保誠-保戶業務員媒合平台
Tomas
2022-05-19 957a1f10a06fdbb76f1a0ba94fe44126c613fee3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
 
var whichBoxedPrimitive = require('which-boxed-primitive');
var bind = require('function-bind');
var hasSymbols = require('has-symbols')();
var hasBigInts = require('has-bigints')();
 
var stringToString = bind.call(Function.call, String.prototype.toString);
var numberValueOf = bind.call(Function.call, Number.prototype.valueOf);
var booleanValueOf = bind.call(Function.call, Boolean.prototype.valueOf);
var symbolValueOf = hasSymbols && bind.call(Function.call, Symbol.prototype.valueOf);
var bigIntValueOf = hasBigInts && bind.call(Function.call, 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);
};