pax_global_header00006660000000000000000000000064152277076360014531gustar00rootroot0000000000000052 comment=20620ebfd195d384d85fc134e29cc4916297a92f ljharb-own-keys-320a20e/000077500000000000000000000000001522770763600150635ustar00rootroot00000000000000ljharb-own-keys-320a20e/.eslintrc000066400000000000000000000003401522770763600167040ustar00rootroot00000000000000{ "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/000077500000000000000000000000001522770763600164235ustar00rootroot00000000000000ljharb-own-keys-320a20e/.github/FUNDING.yml000066400000000000000000000011031522770763600202330ustar00rootroot00000000000000# 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/000077500000000000000000000000001522770763600204605ustar00rootroot00000000000000ljharb-own-keys-320a20e/.github/workflows/node-aught.yml000066400000000000000000000003541522770763600232400ustar00rootroot00000000000000name: '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.yml000066400000000000000000000002061522770763600236120ustar00rootroot00000000000000name: '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.yml000066400000000000000000000003721522770763600231010ustar00rootroot00000000000000name: '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.yml000066400000000000000000000003631522770763600237720ustar00rootroot00000000000000name: '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.yml000066400000000000000000000002571522770763600224500ustar00rootroot00000000000000name: 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.yml000066400000000000000000000003031522770763600250750ustar00rootroot00000000000000name: 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/.gitignore000066400000000000000000000041361522770763600170570ustar00rootroot00000000000000# 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/.npmrc000066400000000000000000000000671522770763600162060ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s ljharb-own-keys-320a20e/.nycrc000066400000000000000000000002131522770763600161760ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } ljharb-own-keys-320a20e/CHANGELOG.md000066400000000000000000000044411522770763600166770ustar00rootroot00000000000000# 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/LICENSE000066400000000000000000000020571522770763600160740ustar00rootroot00000000000000MIT 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.md000066400000000000000000000032001522770763600163350ustar00rootroot00000000000000# 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.ts000066400000000000000000000001521522770763600167620ustar00rootroot00000000000000declare function ownKeys, V>(object: T): (keyof T)[]; export = ownKeys; ljharb-own-keys-320a20e/index.js000066400000000000000000000046601522770763600165360ustar00rootroot00000000000000'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.json000066400000000000000000000046731522770763600173630ustar00rootroot00000000000000{ "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/000077500000000000000000000000001522770763600160425ustar00rootroot00000000000000ljharb-own-keys-320a20e/test/index.js000066400000000000000000000034001522770763600175040ustar00rootroot00000000000000'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.json000066400000000000000000000002101522770763600175630ustar00rootroot00000000000000{ "extends": "@ljharb/tsconfig", "compilerOptions": { "target": "es2021", }, "types": ["node"], "exclude": [ "coverage", ], }