Repository URL to install this package:
|
Version:
2.0.5 ▾
|
import { isNative } from '../NATIVE/isNative'
import {
getPrototypeOf,
getConstructor,
getPrototypeConstructor,
} from '../NATIVE/prototype/getPrototype'
import isIterator from '../iterator/check/isIterator'
import { hasOwnProp } from './properties/hasOwnProperty'
const SYMBOL_SPECIES = Symbol.for('@@species')
// @NOTE always remember, you can go species to proto, but not proto to species
// @TODO
// const SYMBOL_CONSTRUCTOR = Symbol.for('%%constructor%%')
// const SYMBOL_PROTOTYPE = Symbol.for('%%proto%%')
export interface Code {
code: any
}
const isTyped = (x: any): x is Code => hasOwnProp(x, 'code')
const getSpecies = (x: any) => {
if (isTyped(x)) {
return x[SYMBOL_SPECIES]
} else if (isNative(x)) {
return x
} else {
return isIterator(x) ? getPrototypeConstructor(x) : getConstructor(x)
}
}
const getSpeciesProto = getSpecies
export {
getSpeciesProto,
isTyped,
getSpecies,
getSpecies as toSpecies,
SYMBOL_SPECIES,
// ---
getPrototypeOf,
getConstructor,
getPrototypeConstructor,
}