Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
exotic / src / types / attributes / species.ts
Size: Mime:
// 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,
}