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 CHANGED
@@ -4,6 +4,7 @@
4
4
  "extends": "@ljharb",
5
5
 
6
6
  "rules": {
7
+ "func-style": "off",
7
8
  "id-length": "off",
8
9
  "max-lines-per-function": "off",
9
10
  "new-cap": ["error", {
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 OwnPropertyKeys(source) {
14
+ module.exports = $ownKeys || function ownKeys(source) {
15
15
  /** @type {(keyof typeof source)[]} */
16
- var ownKeys = ($gOPN || keys)(source);
16
+ var sourceKeys = ($gOPN || keys)(source);
17
17
  if ($gOPS) {
18
- safePushApply(ownKeys, $gOPS(source));
18
+ safePushApply(sourceKeys, $gOPS(source));
19
19
  }
20
- return ownKeys;
20
+ return sourceKeys;
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "own-keys",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible",
5
5
  "main": "index.js",
6
6
  "exports": {
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