'use strict'; var whichBoxedPrimitive = require('which-boxed-primitive'); var callBound = require('call-bind/callBound'); var hasSymbols = require('has-symbols')(); var hasBigInts = require('has-bigints')(); var stringToString = callBound('String.prototype.toString'); var numberValueOf = callBound('Number.prototype.valueOf'); var booleanValueOf = callBound('Boolean.prototype.valueOf'); var symbolValueOf = hasSymbols && callBound('Symbol.prototype.valueOf'); var bigIntValueOf = hasBigInts && callBound('BigInt.prototype.valueOf'); module.exports = function unboxPrimitive(value) { var which = whichBoxedPrimitive(value); if (typeof which !== 'string') { throw new TypeError(which === null ? 'value is an unboxed primitive' : 'value is a non-boxed-primitive object'); } if (which === 'String') { return stringToString(value); } if (which === 'Number') { return numberValueOf(value); } if (which === 'Boolean') { return booleanValueOf(value); } if (which === 'Symbol') { if (!hasSymbols) { throw new EvalError('somehow this environment does not have Symbols, but you have a boxed Symbol value. Please report this!'); } return symbolValueOf(value); } if (which === 'BigInt') { return bigIntValueOf(value); } throw new RangeError('unknown boxed primitive found: ' + which); };
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
.github | Folder | 0755 |
|
|
test | Folder | 0755 |
|
|
.editorconfig | File | 286 B | 0644 |
|
.eslintrc | File | 43 B | 0644 |
|
.nycrc | File | 216 B | 0644 |
|
CHANGELOG.md | File | 6.22 KB | 0644 |
|
LICENSE | File | 1.05 KB | 0644 |
|
README.md | File | 2.09 KB | 0644 |
|
index.js | File | 1.28 KB | 0644 |
|
package.json | File | 1.71 KB | 0644 |
|