Repository URL to install this package:
|
Version:
1.2.8 ▾
|
// import { isNative } from 'exotic/types/NATIVE/isNative'
// import {
// getPrototypeOf,
// getConstructor,
// getPrototypeConstructor,
// } from 'exotic/types/NATIVE/prototype/getPrototype'
// import isIterator from 'exotic/types/iterator/check/isIterator'
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%%')
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,
}