own-keys 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +1 -0
- package/CHANGELOG.md +7 -0
- package/index.js +4 -4
- package/package.json +1 -1
- package/test/index.js +15 -4
package/.eslintrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [v1.0.1](https://github.com/ljharb/own-keys/compare/v1.0.0...v1.0.1) - 2024-12-29
|
|
9
|
+
|
|
10
|
+
### Commits
|
|
11
|
+
|
|
12
|
+
- [Tests] sort with a proper comparator [`4a65b56`](https://github.com/ljharb/own-keys/commit/4a65b569d10985032a0773806dcdec8866132baa)
|
|
13
|
+
- [Fix] fix function name when `Reflect.ownKeys` is absent [`5cf17cb`](https://github.com/ljharb/own-keys/commit/5cf17cb1c9adfa836a1ddc467da4da20973db2ae)
|
|
14
|
+
|
|
8
15
|
## v1.0.0 - 2024-12-28
|
|
9
16
|
|
|
10
17
|
### Commits
|
package/index.js
CHANGED
|
@@ -11,11 +11,11 @@ var $gOPS = GetIntrinsic('%Object.getOwnPropertySymbols%', true);
|
|
|
11
11
|
var keys = require('object-keys');
|
|
12
12
|
|
|
13
13
|
/** @type {import('.')} */
|
|
14
|
-
module.exports = $ownKeys || function
|
|
14
|
+
module.exports = $ownKeys || function ownKeys(source) {
|
|
15
15
|
/** @type {(keyof typeof source)[]} */
|
|
16
|
-
var
|
|
16
|
+
var sourceKeys = ($gOPN || keys)(source);
|
|
17
17
|
if ($gOPS) {
|
|
18
|
-
safePushApply(
|
|
18
|
+
safePushApply(sourceKeys, $gOPS(source));
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return sourceKeys;
|
|
21
21
|
};
|
package/package.json
CHANGED
package/test/index.js
CHANGED
|
@@ -6,6 +6,17 @@ var hasPropertyDescriptors = require('has-property-descriptors')();
|
|
|
6
6
|
|
|
7
7
|
var ownKeys = require('../');
|
|
8
8
|
|
|
9
|
+
/** @type {(a: PropertyKey, b: PropertyKey) => number} */
|
|
10
|
+
function comparator(a, b) {
|
|
11
|
+
if (typeof a === 'string' && typeof b === 'string') {
|
|
12
|
+
return a.localeCompare(b);
|
|
13
|
+
}
|
|
14
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
15
|
+
return a - b;
|
|
16
|
+
}
|
|
17
|
+
return typeof a === 'symbol' ? 1 : -1;
|
|
18
|
+
}
|
|
19
|
+
|
|
9
20
|
test('ownKeys', function (t) {
|
|
10
21
|
t.equal(typeof ownKeys, 'function', 'is a function');
|
|
11
22
|
t.equal(
|
|
@@ -26,8 +37,8 @@ test('ownKeys', function (t) {
|
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
st.deepEqual(
|
|
29
|
-
ownKeys(obj).sort(),
|
|
30
|
-
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(),
|
|
40
|
+
ownKeys(obj).sort(comparator),
|
|
41
|
+
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(comparator),
|
|
31
42
|
'includes non-enumerable properties'
|
|
32
43
|
);
|
|
33
44
|
|
|
@@ -49,8 +60,8 @@ test('ownKeys', function (t) {
|
|
|
49
60
|
});
|
|
50
61
|
|
|
51
62
|
st.deepEqual(
|
|
52
|
-
ownKeys(obj).sort(),
|
|
53
|
-
['a', sym, nonEnumSym].sort(),
|
|
63
|
+
ownKeys(obj).sort(comparator),
|
|
64
|
+
['a', sym, nonEnumSym].sort(comparator),
|
|
54
65
|
'works with symbols, both enum and non-enum'
|
|
55
66
|
);
|
|
56
67
|
|