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-core / src / Symbols.ts
Size: Mime:
// import { isString } from 'exotic/types/primitive/string'
// import { isNumber } from 'exotic/types/primitive/number'
// import { isSymbol } from 'exotic/types/primitive/symbol'
// import { isStringOrNumber } from 'exotic/types/@omni'
// import WellKnown from 'exoticdeps'
import { zip, freeze } from 'exotic/dist/deps'
import { isSymbol } from 'exotic/dist/types/primitive/symbol'
import { isStringOrNumber } from 'exotic/dist/types/@omni'

// const isStringOrNumber = x => isString(x) || isNumber(x)
const WellKnown = Symbol

// @NOTE all start with @@
const $ = x => Symbol.for(`@@${x}`)

const SYMBOL_STRINGS = freeze([
  'PARENT',
  'INFERRED',
  'INFERRED_DEFAULT',
  'DEFAULT',
  'SUPPORTS',
  'FROM',
  'TO',
  'TYPE',
  'COERCERS',
  'UNKNOWN',
  'EMPTY',
  'IGNORE',
  'SPECIES',
  'NATIVE',
])

// array + array => {[values]: values}
const SYMBOLS = freeze(zip(SYMBOL_STRINGS, SYMBOL_STRINGS))

// @TODO function toSymbol() {}
function toSymbolFor(sig: any): symbol {
  if (isSymbol(sig)) {
    return sig
  } else if (!isStringOrNumber(sig)) {
    return $(sig)
  } else if (WellKnown[sig]) {
    return WellKnown[sig]
  } else {
    const caps = sig.startsWith('@@')
      ? sig.toUpperCase().replace('@@', '')
      : sig.toUpperCase()

    // SYMBOLS[caps]
    return SYMBOL_STRINGS.includes(caps) ? $(caps) : $(sig)
  }
}

// Object.assign(toSymbolFor, WellKnown)

export { toSymbolFor, SYMBOLS, WellKnown }