pax_global_header 0000666 0000000 0000000 00000000064 15227707636 0014531 g ustar 00root root 0000000 0000000 52 comment=20620ebfd195d384d85fc134e29cc4916297a92f
ljharb-own-keys-320a20e/ 0000775 0000000 0000000 00000000000 15227707636 0015063 5 ustar 00root root 0000000 0000000 ljharb-own-keys-320a20e/.eslintrc 0000664 0000000 0000000 00000000340 15227707636 0016704 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"func-style": "off",
"id-length": "off",
"max-lines-per-function": "off",
"new-cap": ["error", {
"capIsNewExceptions": [
"GetIntrinsic",
],
}],
},
}
ljharb-own-keys-320a20e/.github/ 0000775 0000000 0000000 00000000000 15227707636 0016423 5 ustar 00root root 0000000 0000000 ljharb-own-keys-320a20e/.github/FUNDING.yml 0000664 0000000 0000000 00000001103 15227707636 0020233 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/own-keys
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
ljharb-own-keys-320a20e/.github/workflows/ 0000775 0000000 0000000 00000000000 15227707636 0020460 5 ustar 00root root 0000000 0000000 ljharb-own-keys-320a20e/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000354 15227707636 0023240 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
skip-ls-check: true
ljharb-own-keys-320a20e/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 15227707636 0023612 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
ljharb-own-keys-320a20e/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000372 15227707636 0023101 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js 10 - 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10 < 20'
type: minors
command: npm run tests-only
ljharb-own-keys-320a20e/.github/workflows/node-twenties.yml 0000664 0000000 0000000 00000000363 15227707636 0023772 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 20'
type: minors
command: npm run tests-only
ljharb-own-keys-320a20e/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 15227707636 0022450 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
ljharb-own-keys-320a20e/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 15227707636 0025075 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
ljharb-own-keys-320a20e/.gitignore 0000664 0000000 0000000 00000004136 15227707636 0017057 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
ljharb-own-keys-320a20e/.npmrc 0000664 0000000 0000000 00000000067 15227707636 0016206 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
ljharb-own-keys-320a20e/.nycrc 0000664 0000000 0000000 00000000213 15227707636 0016176 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
ljharb-own-keys-320a20e/CHANGELOG.md 0000664 0000000 0000000 00000004441 15227707636 0016677 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.0.2](https://github.com/ljharb/own-keys/compare/v1.0.1...v1.0.2) - 2026-07-21
### Commits
- [Fix] preserve own-key insertion order when the platform's key enumeration does not [`29950ec`](https://github.com/ljharb/own-keys/commit/29950ecffbfe74a94ccfdcfe5066e19206078d52)
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/eslint`, `@types/has-property-descriptors`, `auto-changelog`, `eslint`, `evalmd`, `npmignore`, `tape` [`431250c`](https://github.com/ljharb/own-keys/commit/431250cb85e78ca8deba28875edd59e0c11149ef)
- [Deps] update `get-intrinsic` [`d1c3396`](https://github.com/ljharb/own-keys/commit/d1c3396801f0d976f13b2c4fb323c95ca5c214e3)
- [types] fix an error TS v6 ignores but v7 fails on [`ae0c7fe`](https://github.com/ljharb/own-keys/commit/ae0c7fe3f8a871f50f9b7daf46298f0ef33cc75c)
- [readme] replace runkit CI badge with shields.io check-runs badge [`5caf6ed`](https://github.com/ljharb/own-keys/commit/5caf6edb73d4ff65ecd491521ef7094c08805061)
## [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
### Commits
- Initial implementation, tests, readme, types [`870a06f`](https://github.com/ljharb/own-keys/commit/870a06f9d7a2a6ecee283319d9a7388f8fc1c811)
- Initial commit [`70323dc`](https://github.com/ljharb/own-keys/commit/70323dc09541b4ee80426acfc89762605d7fc7bf)
- npm init [`4a3ad06`](https://github.com/ljharb/own-keys/commit/4a3ad0659defe9a67541c198743bd7733d437725)
- [Tests] node 0.8 sorts object keys differently [`b449364`](https://github.com/ljharb/own-keys/commit/b4493649ead7441fd8e65ab4718acbd088ceac70)
- Only apps should have lockfiles [`a54acbf`](https://github.com/ljharb/own-keys/commit/a54acbf2c6b8ef320abf7493b7c88002c690f9c0)
ljharb-own-keys-320a20e/LICENSE 0000664 0000000 0000000 00000002057 15227707636 0016074 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2024 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ljharb-own-keys-320a20e/README.md 0000664 0000000 0000000 00000003200 15227707636 0016335 0 ustar 00root root 0000000 0000000 # own-keys [![Version Badge][npm-version-svg]][package-url]
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible.
## Getting started
```sh
npm install --save own-keys
```
## Usage/Examples
```js
var ownKeys = require('own-keys');
var assert = require('assert');
assert.deepEqual(ownKeys({ a: 1, b: 2 }), ['a', 'b']);
assert.deepEqual(ownKeys([1, 2, 3]), [0, 1, 2, 'length']);
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/own-keys
[npm-version-svg]: https://versionbadg.es/ljharb/own-keys.svg
[deps-svg]: https://david-dm.org/ljharb/own-keys.svg
[deps-url]: https://david-dm.org/ljharb/own-keys
[dev-deps-svg]: https://david-dm.org/ljharb/own-keys/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/own-keys#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/own-keys.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/own-keys.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/own-keys.svg
[downloads-url]: https://npm-stat.com/charts.html?package=own-keys
[codecov-image]: https://codecov.io/gh/ljharb/own-keys/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/own-keys/
[actions-image]: https://img.shields.io/github/check-runs/ljharb/own-keys/main
[actions-url]: https://github.com/ljharb/own-keys/actions
ljharb-own-keys-320a20e/index.d.ts 0000664 0000000 0000000 00000000152 15227707636 0016762 0 ustar 00root root 0000000 0000000 declare function ownKeys, V>(object: T): (keyof T)[];
export = ownKeys;
ljharb-own-keys-320a20e/index.js 0000664 0000000 0000000 00000004660 15227707636 0016536 0 ustar 00root root 0000000 0000000 'use strict';
var GetIntrinsic = require('get-intrinsic');
var callBound = require('call-bound');
var safePushApply = require('safe-push-apply');
var $ownKeys = GetIntrinsic('%Reflect.ownKeys%', true);
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
var $gOPS = GetIntrinsic('%Object.getOwnPropertySymbols%', true);
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var keys = require('object-keys');
// eslint-disable-next-line array-bracket-newline
var order = ['b', 'd', 'a', 'c', 'g', 'e', 'h', 'f', 'j', 'i', 'l', 'k'];
/*
* Some pre-ES2015 engines (notably V8 in node 0.8) enumerate own property names
* in a per-realm randomized order rather than property-creation order, and a
* `Reflect.ownKeys`/`getOwnPropertyNames` shim layered on top (e.g. es6-shim)
* inherits that. `Object.keys` is ordered even there, so probe whichever key
* source we're about to use and reconstruct from `object-keys` when it can't be
* trusted to preserve insertion order.
*/
/** @param {(o: object) => (string | symbol)[]} getNames */
function preservesInsertionOrder(getNames) {
/** @type {Record} */
var probe = {};
var got;
var i;
for (i = 0; i < order.length; i += 1) {
probe[order[i]] = true;
}
got = getNames(probe);
if (got.length !== order.length) {
return false;
}
for (i = 0; i < order.length; i += 1) {
if (got[i] !== order[i]) {
return false;
}
}
return true;
}
var nativeOwnKeys = $ownKeys && preservesInsertionOrder($ownKeys) ? $ownKeys : null;
var trustGOPNOrder = !nativeOwnKeys && $gOPN && preservesInsertionOrder($gOPN);
/** @type {typeof import('.')} */
module.exports = nativeOwnKeys || function ownKeys(source) {
/** @type {(keyof typeof source)[]} */
var sourceKeys;
var allNames;
var name;
var i;
if ($gOPN && trustGOPNOrder) {
sourceKeys = $gOPN(source);
} else {
/*
* The available key source can't be trusted to preserve order, so take the
* enumerable keys from `object-keys` (ordered) and borrow only the
* non-enumerable names from `getOwnPropertyNames` (their relative order is
* unrecoverable on such engines).
*/
sourceKeys = keys(source);
if ($gOPN) {
allNames = $gOPN(source);
for (i = 0; i < allNames.length; i += 1) {
name = allNames[i];
if (!$isEnumerable(source, name)) {
sourceKeys[sourceKeys.length] = name;
}
}
}
}
if ($gOPS) {
safePushApply(sourceKeys, $gOPS(source));
}
return sourceKeys;
};
ljharb-own-keys-320a20e/package.json 0000664 0000000 0000000 00000004673 15227707636 0017363 0 ustar 00root root 0000000 0000000 {
"name": "own-keys",
"version": "1.0.2",
"description": "Robustly get an object's own property keys (strings and symbols), including non-enumerables when possible",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"",
"prelint": "evalmd --eslint README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run lint",
"tests-only": "nyc tape test",
"test": "npm run tests-only",
"posttest": "npx npm@'>= 10.2' audit --production"
},
"keywords": [
"own",
"key",
"keys",
"propertykey",
"string",
"symbol",
"enumerable",
"non-enumerable",
"robust"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/own-keys.git"
},
"bugs": {
"url": "https://github.com/ljharb/own-keys/issues"
},
"homepage": "https://github.com/ljharb/own-keys#readme",
"dependencies": {
"call-bound": "^1.0.4",
"get-intrinsic": "^1.3.0",
"object-keys": "^1.1.1",
"safe-push-apply": "^1.0.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.18.5",
"@ljharb/eslint-config": "^22.2.3",
"@ljharb/tsconfig": "^0.3.2",
"@types/eslint": "^8.56.12",
"@types/get-intrinsic": "^1.2.3",
"@types/has-property-descriptors": "^1.0.3",
"@types/isarray": "^2.0.3",
"@types/node": "^12.20.55",
"@types/object-keys": "^1.0.3",
"auto-changelog": "^2.6.0",
"eslint": "^8.57.1",
"evalmd": "^0.0.22",
"has-property-descriptors": "^1.0.2",
"has-symbols": "^1.1.0",
"in-publish": "^2.0.1",
"npmignore": "^0.3.5",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.10.2",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
ljharb-own-keys-320a20e/test/ 0000775 0000000 0000000 00000000000 15227707636 0016042 5 ustar 00root root 0000000 0000000 ljharb-own-keys-320a20e/test/index.js 0000664 0000000 0000000 00000003400 15227707636 0017504 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var hasSymbols = require('has-symbols/shams')();
var hasPropertyDescriptors = require('has-property-descriptors')();
var ownKeys = require('../');
/** @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) {
t.equal(typeof ownKeys, 'function', 'is a function');
t.equal(
ownKeys.length,
1,
'has a length of 1'
);
t.test('basics', function (st) {
var obj = { a: 1, b: 2 };
if (hasPropertyDescriptors) {
Object.defineProperty(obj, 'c', {
configurable: true,
enumerable: false,
writable: true,
value: 3
});
}
st.deepEqual(
ownKeys(obj).sort(comparator),
(hasPropertyDescriptors ? ['a', 'b', 'c'] : ['a', 'b']).sort(comparator),
'includes non-enumerable properties'
);
st.end();
});
t.test('symbols', { skip: !hasSymbols }, function (st) {
/** @type {Record} */
var obj = { a: 1 };
var sym = Symbol('b');
obj[sym] = 2;
var nonEnumSym = Symbol('c');
Object.defineProperty(obj, nonEnumSym, {
configurable: true,
enumerable: false,
writable: true,
value: 3
});
st.deepEqual(
ownKeys(obj).sort(comparator),
['a', sym, nonEnumSym].sort(comparator),
'works with symbols, both enum and non-enum'
);
st.end();
});
t.test('preserves insertion order of enumerable string keys', function (st) {
st.deepEqual(
ownKeys({ d: 1, a: 2, c: 3, b: 4 }),
['d', 'a', 'c', 'b'],
'enumerable string keys are returned in insertion order'
);
st.end();
});
t.end();
});
ljharb-own-keys-320a20e/tsconfig.json 0000664 0000000 0000000 00000000210 15227707636 0017563 0 ustar 00root root 0000000 0000000 {
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "es2021",
},
"types": ["node"],
"exclude": [
"coverage",
],
}