save code
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 150
|
||||
|
||||
[CHANGELOG.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.json]
|
||||
max_line_length = off
|
||||
|
||||
[Makefile]
|
||||
max_line_length = off
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Jordan Harband
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
'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);
|
||||
};
|
||||
Reference in New Issue
Block a user