@darkwolf/primordials
v1.2.1
Published
Primordials
Downloads
24
Readme
Primordials
Install
npm i --save @darkwolf/primordials
Usage
// ECMAScript
import * as primordials from '@darkwolf/primordials'
// CommonJS
const primordials = require('@darkwolf/primordials')
const {
ObjectPrototypeToString,
ObjectPrototypeToStringTag,
SymbolIterator,
ArrayPrototypeSymbolIterator,
MapPrototypeSymbolIterator,
SetPrototypeSymbolIterator,
ArrayIteratorPrototype,
MapIteratorPrototype,
SetIteratorPrototype,
SafeArrayIterator,
SafeMap,
SafeSet
} = primordials
ObjectPrototypeToString({}) // => '[object Object]'
ObjectPrototypeToStringTag({}) // => 'Object'
ArrayIteratorPrototype.next = null
const iterator = ArrayPrototypeSymbolIterator([])
iterator.next() // TypeError exception will be thrown
const safeIterator = new SafeArrayIterator([])
safeIterator.next() // => IteratorResult
MapIteratorPrototype.next = null
const mapIterator = MapPrototypeSymbolIterator(new Map())
mapIterator.next() // TypeError exception will be thrown
const safeMapIterator = new SafeMap()[SymbolIterator]()
safeMapIterator.next() // => IteratorResult
SetIteratorPrototype.next = null
const setIterator = SetPrototypeSymbolIterator(new Set())
setIterator.next() // TypeError exception will be thrown
const safeSetIterator = new SafeSet()[SymbolIterator]()
safeSetIterator.next() // => IteratorResult