Comparing version 1.0.0 to 1.0.1
@@ -8,2 +8,9 @@ # Changelog | ||
## [v1.0.1](https://github.com/ljharb/own-keys/compare/v1.0.0...v1.0.1) - 2024-12-29 | ||
### Commits | ||
- [Tests] sort with a proper comparator [`4a65b56`](https://github.com/ljharb/own-keys/commit/4a65b569d10985032a0773806dcdec8866132baa) | ||
- [Fix] fix function name when `Reflect.ownKeys` is absent [`5cf17cb`](https://github.com/ljharb/own-keys/commit/5cf17cb1c9adfa836a1ddc467da4da20973db2ae) | ||
## v1.0.0 - 2024-12-28 | ||
@@ -10,0 +17,0 @@ |
@@ -14,9 +14,9 @@ 'use strict'; | ||
/** @type {import('.')} */ | ||
module.exports = $ownKeys || function OwnPropertyKeys(source) { | ||
module.exports = $ownKeys || function ownKeys(source) { | ||
/** @type {(keyof typeof source)[]} */ | ||
var ownKeys = ($gOPN || keys)(source); | ||
var sourceKeys = ($gOPN || keys)(source); | ||
if ($gOPS) { | ||
safePushApply(ownKeys, $gOPS(source)); | ||
safePushApply(sourceKeys, $gOPS(source)); | ||
} | ||
return ownKeys; | ||
return sourceKeys; | ||
}; |
{ | ||
"name": "own-keys", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,2 +9,13 @@ 'use strict'; | ||
/** @type {(a: PropertyKey, b: PropertyKey) => number} */ | ||
function comparator(a, b) { | ||
if (typeof a === 'string' && typeof b === 'string') { | ||
return a.localeCompare(b); | ||
} | ||
if (typeof a === 'number' && typeof b === 'number') { | ||
return a - b; | ||
} | ||
return typeof a === 'symbol' ? 1 : -1; | ||
} | ||
test('ownKeys', function (t) { | ||
@@ -30,4 +41,4 @@ t.equal(typeof ownKeys, 'function', 'is a function'); | ||
st.deepEqual( | ||
ownKeys(obj).sort(), | ||
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(), | ||
ownKeys(obj).sort(comparator), | ||
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(comparator), | ||
'includes non-enumerable properties' | ||
@@ -54,4 +65,4 @@ ); | ||
st.deepEqual( | ||
ownKeys(obj).sort(), | ||
['a', sym, nonEnumSym].sort(), | ||
ownKeys(obj).sort(comparator), | ||
['a', sym, nonEnumSym].sort(comparator), | ||
'works with symbols, both enum and non-enum' | ||
@@ -58,0 +69,0 @@ ); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9797
87
0