source: imaps-frontend/node_modules/unbox-primitive/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var whichBoxedPrimitive = require('which-boxed-primitive');
4var callBound = require('call-bound');
5var hasSymbols = require('has-symbols')();
6var hasBigInts = require('has-bigints')();
7
8var stringToString = callBound('String.prototype.toString');
9var numberValueOf = callBound('Number.prototype.valueOf');
10var booleanValueOf = callBound('Boolean.prototype.valueOf');
11var symbolValueOf = hasSymbols && callBound('Symbol.prototype.valueOf');
12var bigIntValueOf = hasBigInts && callBound('BigInt.prototype.valueOf');
13
14/** @type {import('.')} */
15module.exports = function unboxPrimitive(value) {
16 var which = whichBoxedPrimitive(value);
17 if (typeof which !== 'string') {
18 throw new TypeError(which === null ? 'value is an unboxed primitive' : 'value is a non-boxed-primitive object');
19 }
20
21 if (which === 'String') {
22 return stringToString(value);
23 }
24 if (which === 'Number') {
25 return numberValueOf(value);
26 }
27 if (which === 'Boolean') {
28 return booleanValueOf(value);
29 }
30 if (which === 'Symbol') {
31 if (!hasSymbols) {
32 throw new EvalError('somehow this environment does not have Symbols, but you have a boxed Symbol value. Please report this!');
33 }
34 // eslint-disable-next-line no-extra-parens
35 return /** @type {Exclude<typeof symbolValueOf, false>} */ (symbolValueOf)(value);
36 }
37 if (which === 'BigInt') {
38 // eslint-disable-next-line no-extra-parens
39 return /** @type {Exclude<typeof bigIntValueOf, false>} */ (bigIntValueOf)(value);
40 }
41 throw new RangeError('unknown boxed primitive found: ' + which);
42};
Note: See TracBrowser for help on using the repository browser.