PHP 7.4.33
Preview: index.js Size: 1.50 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/unbox-primitive/index.js
'use strict';

var whichBoxedPrimitive = require('which-boxed-primitive');
var callBound = require('call-bound');
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');

/** @type {import('.')} */
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!');
		}
		// eslint-disable-next-line no-extra-parens
		return /** @type {Exclude<typeof symbolValueOf, false>} */ (symbolValueOf)(value);
	}
	if (which === 'BigInt') {
		// eslint-disable-next-line no-extra-parens
		return /** @type {Exclude<typeof bigIntValueOf, false>} */ (bigIntValueOf)(value);
	}
	throw new RangeError('unknown boxed primitive found: ' + which);
};

Directory Contents

Dirs: 2 × Files: 10
Name Size Perms Modified Actions
.github DIR
- drwxr-xr-x 2025-03-28 11:04:34
Edit Download
test DIR
- drwxr-xr-x 2025-03-28 11:04:34
Edit Download
286 B lrw-r--r-- 2025-03-28 11:04:34
Edit Download
43 B lrw-r--r-- 2025-03-28 11:04:34
Edit Download
216 B lrw-r--r-- 2025-03-28 11:04:34
Edit Download
8.36 KB lrw-r--r-- 2025-03-28 11:04:34
Edit Download
449 B lrw-r--r-- 2025-03-28 11:04:34
Edit Download
1.50 KB lrw-r--r-- 2025-03-28 11:04:34
Edit Download
1.05 KB lrw-r--r-- 2025-03-28 11:04:34
Edit Download
2.20 KB lrw-r--r-- 2025-03-28 11:04:34
Edit Download
2.09 KB lrw-r--r-- 2025-03-28 11:04:34
Edit Download
68 B lrw-r--r-- 2025-03-28 11:04:34
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).