unbox-primitive
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -8,2 +8,21 @@ # Changelog | ||
## [v1.1.0](https://github.com/ljharb/unbox-primitive/compare/v1.0.2...v1.1.0) - 2024-12-15 | ||
### Commits | ||
- [meta] use `npmignore` to autogenerate an npmignore file [`348a5ad`](https://github.com/ljharb/unbox-primitive/commit/348a5ad5d353e7fcd6353934073ca3a982f40a4e) | ||
- [New] add types [`a324230`](https://github.com/ljharb/unbox-primitive/commit/a32423092f81bfbf3c4dff77a5fa549ffae87daa) | ||
- [Tests] use `es-value-fixtures` [`a321ae5`](https://github.com/ljharb/unbox-primitive/commit/a321ae56aaf30ea843c708bf6c6c13ee52eee205) | ||
- [actions] split out node 10-20, and 20+ [`04a0e0d`](https://github.com/ljharb/unbox-primitive/commit/04a0e0d09907c2643e25ad69b49864c1c34e59d0) | ||
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `npmignore`, `object-inspect`, `object-is`, `tape` [`7fff971`](https://github.com/ljharb/unbox-primitive/commit/7fff97161bf83ebe348290ef27992af630ca92e9) | ||
- [actions] update rebase action [`91d6807`](https://github.com/ljharb/unbox-primitive/commit/91d6807c562a39ce876feda777b641eb0ee64ce9) | ||
- [Deps] update `call-bind`, `has-symbols`, `which-boxed-primitive` [`f8b6597`](https://github.com/ljharb/unbox-primitive/commit/f8b6597e071d05f0792f6eef0e2fbc30ddfe43d4) | ||
- [Dev Deps] update `aud`, `object-inspect`, `tape` [`b3362a1`](https://github.com/ljharb/unbox-primitive/commit/b3362a164fdbee9006be765d99d5d835d6493326) | ||
- [Refactor] use `call-bound` directly [`e29ff5f`](https://github.com/ljharb/unbox-primitive/commit/e29ff5f4cbcc58d32e670bce11d5c3137eae0c44) | ||
- [meta] add missing `engines.node` [`d3420bc`](https://github.com/ljharb/unbox-primitive/commit/d3420bc8cda471cf62119e08d9581b72962f74f6) | ||
- [Tests] replace `aud` with `npm audit` [`5e6a6d0`](https://github.com/ljharb/unbox-primitive/commit/5e6a6d0459b6fa8a812d00362fe60854333f1b64) | ||
- [Deps] update `which-boxed-primitive` [`0ff873d`](https://github.com/ljharb/unbox-primitive/commit/0ff873dadf31962c2f00e24d8d7d30cfa8c60ac6) | ||
- [Dev Deps] update `aud` [`dd0e373`](https://github.com/ljharb/unbox-primitive/commit/dd0e3733bb9db65d254492d6c1d1b710005b932f) | ||
- [Dev Deps] add missing peer dep [`4f79b24`](https://github.com/ljharb/unbox-primitive/commit/4f79b240212d847276dba9a0044f356506eaeaa6) | ||
## [v1.0.2](https://github.com/ljharb/unbox-primitive/compare/v1.0.1...v1.0.2) - 2022-04-24 | ||
@@ -10,0 +29,0 @@ |
'use strict'; | ||
var whichBoxedPrimitive = require('which-boxed-primitive'); | ||
var callBound = require('call-bind/callBound'); | ||
var callBound = require('call-bound'); | ||
var hasSymbols = require('has-symbols')(); | ||
@@ -14,2 +14,3 @@ var hasBigInts = require('has-bigints')(); | ||
/** @type {import('.')} */ | ||
module.exports = function unboxPrimitive(value) { | ||
@@ -34,8 +35,10 @@ var which = whichBoxedPrimitive(value); | ||
} | ||
return symbolValueOf(value); | ||
// eslint-disable-next-line no-extra-parens | ||
return /** @type {Exclude<typeof symbolValueOf, false>} */ (symbolValueOf)(value); | ||
} | ||
if (which === 'BigInt') { | ||
return bigIntValueOf(value); | ||
// eslint-disable-next-line no-extra-parens | ||
return /** @type {Exclude<typeof bigIntValueOf, false>} */ (bigIntValueOf)(value); | ||
} | ||
throw new RangeError('unknown boxed primitive found: ' + which); | ||
}; |
{ | ||
"name": "unbox-primitive", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Unbox a boxed JS primitive value.", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"prepublishOnly": "safe-publish-latest", | ||
"lint": "eslint --ext=js,mjs .", | ||
"postlint": "tsc && attw -P", | ||
"pretest": "npm run lint", | ||
"tests-only": "nyc tape 'test/**/*.js'", | ||
"test": "npm run tests-only", | ||
"posttest": "aud --production", | ||
"posttest": "npx npm@'>= 10.2' audit --production", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
@@ -39,19 +41,28 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.0", | ||
"auto-changelog": "^2.4.0", | ||
"@arethetypeswrong/cli": "^0.17.1", | ||
"@ljharb/eslint-config": "^21.1.1", | ||
"@ljharb/tsconfig": "^0.2.2", | ||
"@types/for-each": "^0.3.3", | ||
"@types/object-inspect": "^1.13.0", | ||
"@types/object-is": "^1.1.0", | ||
"@types/tape": "^5.7.0", | ||
"auto-changelog": "^2.5.0", | ||
"encoding": "^0.1.13", | ||
"es-value-fixtures": "^1.5.0", | ||
"eslint": "=8.8.0", | ||
"for-each": "^0.3.3", | ||
"in-publish": "^2.0.1", | ||
"npmignore": "^0.3.1", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.12.0", | ||
"object-is": "^1.1.5", | ||
"object-inspect": "^1.13.3", | ||
"object-is": "^1.1.6", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.5.3" | ||
"tape": "^5.9.0", | ||
"typescript": "next" | ||
}, | ||
"dependencies": { | ||
"call-bind": "^1.0.2", | ||
"call-bound": "^1.0.3", | ||
"has-bigints": "^1.0.2", | ||
"has-symbols": "^1.0.3", | ||
"which-boxed-primitive": "^1.0.2" | ||
"has-symbols": "^1.1.0", | ||
"which-boxed-primitive": "^1.1.1" | ||
}, | ||
@@ -65,3 +76,11 @@ "auto-changelog": { | ||
"hideCredit": true | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
}, | ||
"engines": { | ||
"node": ">= 0.4" | ||
} | ||
} |
@@ -7,31 +7,28 @@ 'use strict'; | ||
var forEach = require('for-each'); | ||
var hasSymbols = require('has-symbols')(); | ||
var hasBigInts = require('has-bigints')(); | ||
var v = require('es-value-fixtures'); | ||
var unboxPrimitive = require('..'); | ||
var debug = function (v, m) { return inspect(v) + ' ' + m; }; | ||
test('primitives', function (t) { | ||
forEach([null, undefined], function (nullValue) { | ||
t['throws']( | ||
// @ts-expect-error | ||
function () { unboxPrimitive(nullValue); }, | ||
TypeError, | ||
inspect(nullValue) + ' is not a primitive' | ||
); | ||
}); | ||
test('primitives', function (t) { | ||
var primitives = [ | ||
true, | ||
false, | ||
'', | ||
'foo', | ||
42, | ||
NaN, | ||
Infinity, | ||
0 | ||
]; | ||
if (hasSymbols) { | ||
primitives.push(Symbol(), Symbol.iterator, Symbol('f')); | ||
} | ||
if (hasBigInts) { | ||
primitives.push(BigInt(42), BigInt(0)); | ||
} | ||
forEach(primitives, function (primitive) { | ||
// eslint-disable-next-line no-extra-parens | ||
forEach(/** @type {typeof v.nonNullPrimitives} */ ([].concat( | ||
// @ts-expect-error TS sucks with concat | ||
v.nonNullPrimitives, | ||
v.zeroes, | ||
v.infinities, | ||
NaN | ||
)), function (primitive) { | ||
var obj = Object(primitive); | ||
t.ok( | ||
is(unboxPrimitive(obj), primitive), | ||
debug(obj, 'unboxes to ' + inspect(primitive)) | ||
inspect(obj) + 'unboxes to ' + inspect(primitive) | ||
); | ||
@@ -44,3 +41,6 @@ }); | ||
test('objects', function (t) { | ||
var objects = [ | ||
// eslint-disable-next-line no-extra-parens | ||
forEach(/** @type {typeof v.objects} */ (/** @type {unknown} */ ([].concat( | ||
// @ts-expect-error TS sucks with concat | ||
v.objects, | ||
{}, | ||
@@ -51,8 +51,8 @@ [], | ||
new Date() | ||
]; | ||
forEach(objects, function (object) { | ||
))), function (object) { | ||
t['throws']( | ||
// @ts-expect-error | ||
function () { unboxPrimitive(object); }, | ||
TypeError, | ||
debug(object, 'is not a primitive') | ||
inspect(object) + ' is not a primitive' | ||
); | ||
@@ -59,0 +59,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18507
12
107
20
+ Addedcall-bound@^1.0.3
- Removedcall-bind@^1.0.2
- Removedcall-bind@1.0.8(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedset-function-length@1.2.2(transitive)
Updatedhas-symbols@^1.1.0
Updatedwhich-boxed-primitive@^1.1.1