own-keys 1.0.0

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 ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "root": true,
3
+
4
+ "extends": "@ljharb",
5
+
6
+ "rules": {
7
+ "id-length": "off",
8
+ "max-lines-per-function": "off",
9
+ "new-cap": ["error", {
10
+ "capIsNewExceptions": [
11
+ "GetIntrinsic",
12
+ ],
13
+ }],
14
+ },
15
+ }
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [ljharb]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: npm/own-keys
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
package/.nycrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "all": true,
3
+ "check-coverage": false,
4
+ "reporter": ["text-summary", "text", "html", "json"],
5
+ "exclude": [
6
+ "coverage",
7
+ "test"
8
+ ]
9
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## v1.0.0 - 2024-12-28
9
+
10
+ ### Commits
11
+
12
+ - Initial implementation, tests, readme, types [`870a06f`](https://github.com/ljharb/own-keys/commit/870a06f9d7a2a6ecee283319d9a7388f8fc1c811)
13
+ - Initial commit [`70323dc`](https://github.com/ljharb/own-keys/commit/70323dc09541b4ee80426acfc89762605d7fc7bf)
14
+ - npm init [`4a3ad06`](https://github.com/ljharb/own-keys/commit/4a3ad0659defe9a67541c198743bd7733d437725)
15
+ - [Tests] node 0.8 sorts object keys differently [`b449364`](https://github.com/ljharb/own-keys/commit/b4493649ead7441fd8e65ab4718acbd088ceac70)
16
+ - Only apps should have lockfiles [`a54acbf`](https://github.com/ljharb/own-keys/commit/a54acbf2c6b8ef320abf7493b7c88002c690f9c0)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jordan Harband
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # own-keys <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
+
3
+ [![github actions][actions-image]][actions-url]
4
+ [![coverage][codecov-image]][codecov-url]
5
+ [![License][license-image]][license-url]
6
+ [![Downloads][downloads-image]][downloads-url]
7
+
8
+ [![npm badge][npm-badge-png]][package-url]
9
+
10
+ Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible.
11
+
12
+ ## Getting started
13
+
14
+ ```sh
15
+ npm install --save own-keys
16
+ ```
17
+
18
+ ## Usage/Examples
19
+
20
+ ```js
21
+ var ownKeys = require('own-keys');
22
+ var assert = require('assert');
23
+
24
+ assert.deepEqual(ownKeys({ a: 1, b: 2 }), ['a', 'b']);
25
+ assert.deepEqual(ownKeys([1, 2, 3]), [0, 1, 2, 'length']);
26
+ ```
27
+
28
+ ## Tests
29
+ Simply clone the repo, `npm install`, and run `npm test`
30
+
31
+ [package-url]: https://npmjs.org/package/own-keys
32
+ [npm-version-svg]: https://versionbadg.es/ljharb/own-keys.svg
33
+ [deps-svg]: https://david-dm.org/ljharb/own-keys.svg
34
+ [deps-url]: https://david-dm.org/ljharb/own-keys
35
+ [dev-deps-svg]: https://david-dm.org/ljharb/own-keys/dev-status.svg
36
+ [dev-deps-url]: https://david-dm.org/ljharb/own-keys#info=devDependencies
37
+ [npm-badge-png]: https://nodei.co/npm/own-keys.png?downloads=true&stars=true
38
+ [license-image]: https://img.shields.io/npm/l/own-keys.svg
39
+ [license-url]: LICENSE
40
+ [downloads-image]: https://img.shields.io/npm/dm/own-keys.svg
41
+ [downloads-url]: https://npm-stat.com/charts.html?package=own-keys
42
+ [codecov-image]: https://codecov.io/gh/ljharb/own-keys/branch/main/graphs/badge.svg
43
+ [codecov-url]: https://app.codecov.io/gh/ljharb/own-keys/
44
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/own-keys
45
+ [actions-url]: https://github.com/ljharb/own-keys/actions
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare function ownKeys<T extends Record<PropertyKey, V>, V>(object: T): (keyof T)[];
2
+
3
+ export = ownKeys;
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var GetIntrinsic = require('get-intrinsic');
4
+
5
+ var safePushApply = require('safe-push-apply');
6
+
7
+ var $ownKeys = GetIntrinsic('%Reflect.ownKeys%', true);
8
+ var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
9
+ var $gOPS = GetIntrinsic('%Object.getOwnPropertySymbols%', true);
10
+
11
+ var keys = require('object-keys');
12
+
13
+ /** @type {import('.')} */
14
+ module.exports = $ownKeys || function OwnPropertyKeys(source) {
15
+ /** @type {(keyof typeof source)[]} */
16
+ var ownKeys = ($gOPN || keys)(source);
17
+ if ($gOPS) {
18
+ safePushApply(ownKeys, $gOPS(source));
19
+ }
20
+ return ownKeys;
21
+ };
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "own-keys",
3
+ "version": "1.0.0",
4
+ "description": "Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible",
5
+ "main": "index.js",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./package.json": "./package.json"
9
+ },
10
+ "sideEffects": false,
11
+ "scripts": {
12
+ "prepack": "npmignore --auto --commentLines=autogenerated",
13
+ "version": "auto-changelog && git add CHANGELOG.md",
14
+ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"",
15
+ "prelint": "evalmd README.md",
16
+ "lint": "eslint --ext=js,mjs .",
17
+ "postlint": "tsc && attw -P",
18
+ "prepublish": "not-in-publish || npm run prepublishOnly",
19
+ "prepublishOnly": "safe-publish-latest",
20
+ "pretest": "npm run lint",
21
+ "tests-only": "nyc tape test",
22
+ "test": "npm run tests-only",
23
+ "posttest": "npx npm@'>= 10.2' audit --production"
24
+ },
25
+ "keywords": [
26
+ "own",
27
+ "key",
28
+ "keys",
29
+ "propertykey",
30
+ "string",
31
+ "symbol",
32
+ "enumerable",
33
+ "non-enumerable",
34
+ "robust"
35
+ ],
36
+ "author": "Jordan Harband <ljharb@gmail.com>",
37
+ "funding": {
38
+ "url": "https://github.com/sponsors/ljharb"
39
+ },
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/ljharb/own-keys.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/ljharb/own-keys/issues"
47
+ },
48
+ "homepage": "https://github.com/ljharb/own-keys#readme",
49
+ "dependencies": {
50
+ "get-intrinsic": "^1.2.6",
51
+ "object-keys": "^1.1.1",
52
+ "safe-push-apply": "^1.0.0"
53
+ },
54
+ "devDependencies": {
55
+ "@arethetypeswrong/cli": "^0.17.2",
56
+ "@ljharb/eslint-config": "^21.1.1",
57
+ "@ljharb/tsconfig": "^0.2.3",
58
+ "@types/get-intrinsic": "^1.2.3",
59
+ "@types/isarray": "^2.0.3",
60
+ "@types/object-keys": "^1.0.3",
61
+ "@types/tape": "^5.8.0",
62
+ "auto-changelog": "^2.5.0",
63
+ "encoding": "^0.1.13",
64
+ "eslint": "=8.8.0",
65
+ "evalmd": "^0.0.19",
66
+ "has-property-descriptors": "^1.0.2",
67
+ "has-symbols": "^1.1.0",
68
+ "in-publish": "^2.0.1",
69
+ "npmignore": "^0.3.1",
70
+ "nyc": "^10.3.2",
71
+ "safe-publish-latest": "^2.0.0",
72
+ "tape": "^5.9.0",
73
+ "typescript": "next"
74
+ },
75
+ "engines": {
76
+ "node": ">= 0.4"
77
+ },
78
+ "auto-changelog": {
79
+ "output": "CHANGELOG.md",
80
+ "template": "keepachangelog",
81
+ "unreleased": false,
82
+ "commitLimit": false,
83
+ "backfillLimit": false,
84
+ "hideCredit": true
85
+ },
86
+ "publishConfig": {
87
+ "ignore": [
88
+ ".github/workflows"
89
+ ]
90
+ }
91
+ }
package/test/index.js ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ var test = require('tape');
4
+ var hasSymbols = require('has-symbols/shams')();
5
+ var hasPropertyDescriptors = require('has-property-descriptors')();
6
+
7
+ var ownKeys = require('../');
8
+
9
+ test('ownKeys', function (t) {
10
+ t.equal(typeof ownKeys, 'function', 'is a function');
11
+ t.equal(
12
+ ownKeys.length,
13
+ 1,
14
+ 'has a length of 1'
15
+ );
16
+
17
+ t.test('basics', function (st) {
18
+ var obj = { a: 1, b: 2 };
19
+ if (hasPropertyDescriptors) {
20
+ Object.defineProperty(obj, 'c', {
21
+ configurable: true,
22
+ enumerable: false,
23
+ writable: true,
24
+ value: 3
25
+ });
26
+ }
27
+
28
+ st.deepEqual(
29
+ ownKeys(obj).sort(),
30
+ (hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(),
31
+ 'includes non-enumerable properties'
32
+ );
33
+
34
+ st.end();
35
+ });
36
+
37
+ t.test('symbols', { skip: !hasSymbols }, function (st) {
38
+ /** @type {Record<PropertyKey, unknown>} */
39
+ var obj = { a: 1 };
40
+ var sym = Symbol('b');
41
+ obj[sym] = 2;
42
+
43
+ var nonEnumSym = Symbol('c');
44
+ Object.defineProperty(obj, nonEnumSym, {
45
+ configurable: true,
46
+ enumerable: false,
47
+ writable: true,
48
+ value: 3
49
+ });
50
+
51
+ st.deepEqual(
52
+ ownKeys(obj).sort(),
53
+ ['a', sym, nonEnumSym].sort(),
54
+ 'works with symbols, both enum and non-enum'
55
+ );
56
+
57
+ st.end();
58
+ });
59
+
60
+ t.end();
61
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@ljharb/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "es2021",
5
+ },
6
+ "exclude": [
7
+ "coverage",
8
+ ],
9
+ }