├── .editorconfig ├── .eslintrc ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── node-aught.yml │ ├── node-pretest.yml │ ├── node-tens.yml │ ├── rebase.yml │ └── require-allow-edits.yml ├── .gitignore ├── .npmrc ├── .nycrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "@ljharb", 5 | 6 | "overrides": [ 7 | { 8 | "files": "index.js", 9 | "rules": { 10 | "complexity": "off", 11 | "no-param-reassign": "warn", 12 | }, 13 | }, 14 | { 15 | "files": "test/**/*.js", 16 | "rules": { 17 | "id-length": "off", 18 | "getter-return": "off", 19 | "max-lines-per-function": "warn", 20 | }, 21 | }, 22 | ], 23 | } 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 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/is-accessor-descriptor 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'] 13 | -------------------------------------------------------------------------------- /.github/workflows/node-aught.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js < 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '< 10' 10 | type: minors 11 | command: npm run tests-only 12 | 13 | node: 14 | name: 'node < 10' 15 | needs: [tests] 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo tests completed' 19 | -------------------------------------------------------------------------------- /.github/workflows/node-pretest.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: pretest/posttest' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/pretest.yml@main 8 | -------------------------------------------------------------------------------- /.github/workflows/node-tens.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js >= 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '>= 10' 10 | type: minors 11 | command: npm run tests-only 12 | 13 | node: 14 | name: 'node >= 10' 15 | needs: [tests] 16 | runs-on: ubuntu-latest 17 | steps: 18 | - run: 'echo tests completed' 19 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | name: Automatic Rebase 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | uses: ljharb/actions/.github/workflows/rebase.yml@main 8 | secrets: 9 | token: ${{ secrets.GITHUB_TOKEN }} 10 | -------------------------------------------------------------------------------- /.github/workflows/require-allow-edits.yml: -------------------------------------------------------------------------------- 1 | name: Require “Allow Edits” 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Require “Allow Edits”" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: ljharb/require-allow-edits@main 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # Only apps should have lockfiles 107 | npm-shrinkwrap.json 108 | package-lock.json 109 | yarn.lock 110 | 111 | .npmignore 112 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | allow-same-version=true 3 | message=v%s 4 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "check-coverage": false, 4 | "reporter": ["text-summary", "text", "html", "json"], 5 | "exclude": [ 6 | "coverage", 7 | "test" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 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 | ## [v3.0.5](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.4...v3.0.5) - 2023-10-27 9 | 10 | ### Commits 11 | 12 | - [Fix] fix a bad merge and refactor checkProto logic [`1acdf9d`](https://github.com/inspect-js/is-accessor-descriptor/commit/1acdf9deb55f1616da5b8dd3c2991d2de56faec3) 13 | 14 | ## [v3.0.4](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.3...v3.0.4) - 2023-10-26 15 | 16 | ### Commits 17 | 18 | - Merge tag v0.1.7, v1.0.1 [`a5ae905`](https://github.com/inspect-js/is-accessor-descriptor/commit/a5ae9058400afa44a5e8cf9af85c096425a53128) 19 | - [eslint] actually use eslint [`d0b9c94`](https://github.com/inspect-js/is-accessor-descriptor/commit/d0b9c94c669a8c2939566fc805e97e0a517ea1db) 20 | - [eslint] actually use eslint [`a05c057`](https://github.com/inspect-js/is-accessor-descriptor/commit/a05c0576662de977798bcba0ffa037a1ffdb9f68) 21 | - [meta] update package.json, etc from main [`c4fab21`](https://github.com/inspect-js/is-accessor-descriptor/commit/c4fab216ad2f011daf45e35323f1d8a872041e63) 22 | - [readme] clean up docs, URLs, package.json, etc [`6648dcd`](https://github.com/inspect-js/is-accessor-descriptor/commit/6648dcde8c01fcb36f7d6aaa3f70e3563df54b67) 23 | - temp [`a6392d4`](https://github.com/inspect-js/is-accessor-descriptor/commit/a6392d4159aaa89a7ba79057cb401e0e09093c06) 24 | - [meta] update `.gitignore` [`cba0ea0`](https://github.com/inspect-js/is-accessor-descriptor/commit/cba0ea006594dd4583ba671c1643a1e96aaab7ff) 25 | - [Tests] switch to tape [`9a0ab35`](https://github.com/inspect-js/is-accessor-descriptor/commit/9a0ab35563c55cb23e663bd5c842811c59371e31) 26 | - [readme] remove verb [`2f07da4`](https://github.com/inspect-js/is-accessor-descriptor/commit/2f07da493d0c824b5738675999ea4a3db541c84e) 27 | - [Tests] switch to tape [`7e39202`](https://github.com/inspect-js/is-accessor-descriptor/commit/7e392020781a23f4c1276e78da4bf8a798021d85) 28 | - [Tests] migrate from travis to github actions [`aa436b0`](https://github.com/inspect-js/is-accessor-descriptor/commit/aa436b0bbeb03c1281e816445e4d495e582274c7) 29 | - [Tests] migrate from travis to github actions [`6e9c4f1`](https://github.com/inspect-js/is-accessor-descriptor/commit/6e9c4f1a211697db4956743992107e67f751b433) 30 | - [readme] remove verb [`967137d`](https://github.com/inspect-js/is-accessor-descriptor/commit/967137d64da7b14dd861f27c9092a2ac66e09564) 31 | - [readme] use `evalmd` [`471d3b9`](https://github.com/inspect-js/is-accessor-descriptor/commit/471d3b9e33b86a856b68f67dd5e57663af39d746) 32 | - [Fix] only one of `get` and `set` are required to be an accessor [`c8de5e7`](https://github.com/inspect-js/is-accessor-descriptor/commit/c8de5e75a9e817c2726511701c048d0f9360195b) 33 | - [Fix] properly handle an accessor descriptor with only a setter [`04647f4`](https://github.com/inspect-js/is-accessor-descriptor/commit/04647f45870a2d3a78e2ae8adf07b0e9d47e0fc9) 34 | - [Refactor] use `hasown` [`6151f01`](https://github.com/inspect-js/is-accessor-descriptor/commit/6151f01a4244d22545cd9fb4ca9b6b772f62a40f) 35 | - [Refactor] properly guard for-in loop [`a0454cc`](https://github.com/inspect-js/is-accessor-descriptor/commit/a0454cca3ea0610c8cf5e0b70bd581689ded929a) 36 | - [Fix] allow any non-primitive; arrays and functions are objects too [`853db5a`](https://github.com/inspect-js/is-accessor-descriptor/commit/853db5a1af876e7c52bee27f6069779d069b1a5c) 37 | - [Fix] allow any non-primitive; arrays and functions are objects too [`123e3c3`](https://github.com/inspect-js/is-accessor-descriptor/commit/123e3c3da341a1a397e274805df88ed13646442f) 38 | - Only apps should have lockfiles [`87402b1`](https://github.com/inspect-js/is-accessor-descriptor/commit/87402b118e6f391dde566cdcd51f27d0e0aa211f) 39 | - [Refactor] use `hasown` [`7ad36a0`](https://github.com/inspect-js/is-accessor-descriptor/commit/7ad36a05be98c7f0ae3f4dc9b3a3df1fa392c7fd) 40 | - [Fix] use correct logic for two-arg form [`3c1729e`](https://github.com/inspect-js/is-accessor-descriptor/commit/3c1729e0e5658fc8b53dbbd945e1c99b033f562a) 41 | - [Fix] properly guard for-in loop [`442daa8`](https://github.com/inspect-js/is-accessor-descriptor/commit/442daa86d808259f62f2ced02619a2bc84f881be) 42 | - [Tests] move tests to test dir [`18313a7`](https://github.com/inspect-js/is-accessor-descriptor/commit/18313a7d61e9bb0d3ff34b112c2d614a975be0df) 43 | - [readme] fix incorrect example [`3ee754a`](https://github.com/inspect-js/is-accessor-descriptor/commit/3ee754af6cb65c690ccd9ade150b33e8ec2808f8) 44 | - [Tests] move tests to test dir [`5d70880`](https://github.com/inspect-js/is-accessor-descriptor/commit/5d70880ae2256d1f5927dab02c0bf8fe78cafef3) 45 | - [Dev Deps] add missing `npmignore` [`97ce4bc`](https://github.com/inspect-js/is-accessor-descriptor/commit/97ce4bca878e775672e3d7349906bd7fc7db5f24) 46 | - [Robustness] use a null object just in case [`675af5b`](https://github.com/inspect-js/is-accessor-descriptor/commit/675af5b191ebe9e18fb65c0aecb2a5ae65a535e0) 47 | 48 | ## [v3.0.3](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.2...v3.0.3) - 2023-10-25 49 | 50 | ### Commits 51 | 52 | - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `has-property-descriptors`, `tape` [`908044d`](https://github.com/inspect-js/is-accessor-descriptor/commit/908044d05559496cddf61b8f634641e879305f24) 53 | - [Refactor] use `hasown` [`8b94cc1`](https://github.com/inspect-js/is-accessor-descriptor/commit/8b94cc153ba580143fe27bab0437199e873e58e3) 54 | 55 | ## [v3.0.2](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.1...v3.0.2) - 2023-04-27 56 | 57 | ### Commits 58 | 59 | - [eslint] cleanup [`c0a3a34`](https://github.com/inspect-js/is-accessor-descriptor/commit/c0a3a34eabaed6634dd674600df2c647688d3a31) 60 | - [Tests] travis -> Github Actions; add `safe-publish-latest`, `npmignore`, `auto-changelog`, `evalmd`, `aud` [`a45de10`](https://github.com/inspect-js/is-accessor-descriptor/commit/a45de10c8020a350df860c2c4fe7697a74cdb943) 61 | - [readme] clean up docs, URLs, package.json, etc [`d2f3547`](https://github.com/inspect-js/is-accessor-descriptor/commit/d2f354741f4fecc8c0e1ed6a83d351028a2ce2ba) 62 | - [New] increase support from node 6 down to node 0.4 [`825f88e`](https://github.com/inspect-js/is-accessor-descriptor/commit/825f88e69da75476b638e9879296a37d370ce9fd) 63 | - [Tests] convert from mocha to tape [`072d097`](https://github.com/inspect-js/is-accessor-descriptor/commit/072d097f5bbe1d6383ec38c13bbe67b491c0c671) 64 | - [Docs] remove `verb` [`7567b54`](https://github.com/inspect-js/is-accessor-descriptor/commit/7567b54961b87af9ae890584089f5f29f19d8537) 65 | - [Tests] use `has-property-descriptors` to skip true getter tests in older engines [`0e26d80`](https://github.com/inspect-js/is-accessor-descriptor/commit/0e26d806b7f97e23f287eac39bb352e772ac3f3b) 66 | - [Fix] when an object/key pair is provided, check arguments.length instead of key truthiness [`3962d00`](https://github.com/inspect-js/is-accessor-descriptor/commit/3962d006fbe65dce0bc0847e278af142829057cb) 67 | - [Tests] add coverage [`6337da4`](https://github.com/inspect-js/is-accessor-descriptor/commit/6337da417af127694412e5f18ba853f47b9a4270) 68 | - [meta] switch from `files` field to npmignore; add `exports` [`6e870be`](https://github.com/inspect-js/is-accessor-descriptor/commit/6e870be859d17221b11b8c9f2fcb3e8a1e649598) 69 | 70 | ## [v3.0.1](https://github.com/inspect-js/is-accessor-descriptor/compare/v3.0.0...v3.0.1) - 2018-12-13 71 | 72 | ### Commits 73 | 74 | - cleanup readme [`5cce1d2`](https://github.com/inspect-js/is-accessor-descriptor/commit/5cce1d212f887f9b4afe2b29dd95d657e1ea210c) 75 | - remove unnecessary check [`288d4b9`](https://github.com/inspect-js/is-accessor-descriptor/commit/288d4b9f407bd7a01a606456ac40b7c29d7fd407) 76 | 77 | ## [v3.0.0](https://github.com/inspect-js/is-accessor-descriptor/compare/v2.0.0...v3.0.0) - 2018-12-13 78 | 79 | ### Commits 80 | 81 | - refactor [`d01d897`](https://github.com/inspect-js/is-accessor-descriptor/commit/d01d897175f09d3fb285a6bb22e4eb46a46a6045) 82 | 83 | ## [v2.0.0](https://github.com/inspect-js/is-accessor-descriptor/compare/v1.0.1...v2.0.0) - 2017-12-04 84 | 85 | ### Commits 86 | 87 | - refactor to be stricter [`f7370ef`](https://github.com/inspect-js/is-accessor-descriptor/commit/f7370efe312e338c7f3175d76b973bdd838d0d27) 88 | - update docs [`fd1764c`](https://github.com/inspect-js/is-accessor-descriptor/commit/fd1764c14dc6bfba668cb502dad57e5e03855ecf) 89 | 90 | ## [v1.0.1](https://github.com/inspect-js/is-accessor-descriptor/compare/v1.0.0...v1.0.1) - 2023-10-26 91 | 92 | ### Commits 93 | 94 | - [eslint] actually use eslint [`a05c057`](https://github.com/inspect-js/is-accessor-descriptor/commit/a05c0576662de977798bcba0ffa037a1ffdb9f68) 95 | - [readme] clean up docs, URLs, package.json, etc [`6648dcd`](https://github.com/inspect-js/is-accessor-descriptor/commit/6648dcde8c01fcb36f7d6aaa3f70e3563df54b67) 96 | - [meta] update `.gitignore` [`cba0ea0`](https://github.com/inspect-js/is-accessor-descriptor/commit/cba0ea006594dd4583ba671c1643a1e96aaab7ff) 97 | - [readme] remove verb [`2f07da4`](https://github.com/inspect-js/is-accessor-descriptor/commit/2f07da493d0c824b5738675999ea4a3db541c84e) 98 | - [Tests] switch to tape [`7e39202`](https://github.com/inspect-js/is-accessor-descriptor/commit/7e392020781a23f4c1276e78da4bf8a798021d85) 99 | - [Tests] migrate from travis to github actions [`aa436b0`](https://github.com/inspect-js/is-accessor-descriptor/commit/aa436b0bbeb03c1281e816445e4d495e582274c7) 100 | - [Fix] properly handle an accessor descriptor with only a setter [`04647f4`](https://github.com/inspect-js/is-accessor-descriptor/commit/04647f45870a2d3a78e2ae8adf07b0e9d47e0fc9) 101 | - [Refactor] properly guard for-in loop [`a0454cc`](https://github.com/inspect-js/is-accessor-descriptor/commit/a0454cca3ea0610c8cf5e0b70bd581689ded929a) 102 | - [Fix] allow any non-primitive; arrays and functions are objects too [`123e3c3`](https://github.com/inspect-js/is-accessor-descriptor/commit/123e3c3da341a1a397e274805df88ed13646442f) 103 | - [Refactor] use `hasown` [`7ad36a0`](https://github.com/inspect-js/is-accessor-descriptor/commit/7ad36a05be98c7f0ae3f4dc9b3a3df1fa392c7fd) 104 | - [readme] fix incorrect example [`3ee754a`](https://github.com/inspect-js/is-accessor-descriptor/commit/3ee754af6cb65c690ccd9ade150b33e8ec2808f8) 105 | - [Tests] move tests to test dir [`5d70880`](https://github.com/inspect-js/is-accessor-descriptor/commit/5d70880ae2256d1f5927dab02c0bf8fe78cafef3) 106 | - [Dev Deps] add missing `npmignore` [`97ce4bc`](https://github.com/inspect-js/is-accessor-descriptor/commit/97ce4bca878e775672e3d7349906bd7fc7db5f24) 107 | - [Robustness] use a null object just in case [`675af5b`](https://github.com/inspect-js/is-accessor-descriptor/commit/675af5b191ebe9e18fb65c0aecb2a5ae65a535e0) 108 | 109 | ## [v1.0.0](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.7...v1.0.0) - 2017-11-01 110 | 111 | ### Merged 112 | 113 | - Pin mocha to version 3 to support Node 0.12 [`#3`](https://github.com/inspect-js/is-accessor-descriptor/pull/3) 114 | - Update kind-of to version 6.0 [`#2`](https://github.com/inspect-js/is-accessor-descriptor/pull/2) 115 | 116 | ### Commits 117 | 118 | - run update [`2489800`](https://github.com/inspect-js/is-accessor-descriptor/commit/2489800869cbecf53e9bc3596916abf2e6008edb) 119 | - run verb to generate readme documentation [`22b0a26`](https://github.com/inspect-js/is-accessor-descriptor/commit/22b0a2617ccbebd131247c29e3700ca860d37d06) 120 | - remove should [`4b10d2a`](https://github.com/inspect-js/is-accessor-descriptor/commit/4b10d2aa721021d5f7af69c47f49a1691a8c3fcd) 121 | 122 | ## [v0.1.7](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.6...v0.1.7) - 2023-10-26 123 | 124 | ### Commits 125 | 126 | - [eslint] actually use eslint [`d0b9c94`](https://github.com/inspect-js/is-accessor-descriptor/commit/d0b9c94c669a8c2939566fc805e97e0a517ea1db) 127 | - [meta] update package.json, etc from main [`c4fab21`](https://github.com/inspect-js/is-accessor-descriptor/commit/c4fab216ad2f011daf45e35323f1d8a872041e63) 128 | - [Tests] switch to tape [`9a0ab35`](https://github.com/inspect-js/is-accessor-descriptor/commit/9a0ab35563c55cb23e663bd5c842811c59371e31) 129 | - [Tests] migrate from travis to github actions [`6e9c4f1`](https://github.com/inspect-js/is-accessor-descriptor/commit/6e9c4f1a211697db4956743992107e67f751b433) 130 | - [readme] remove verb [`967137d`](https://github.com/inspect-js/is-accessor-descriptor/commit/967137d64da7b14dd861f27c9092a2ac66e09564) 131 | - [readme] use `evalmd` [`471d3b9`](https://github.com/inspect-js/is-accessor-descriptor/commit/471d3b9e33b86a856b68f67dd5e57663af39d746) 132 | - [Fix] only one of `get` and `set` are required to be an accessor [`c8de5e7`](https://github.com/inspect-js/is-accessor-descriptor/commit/c8de5e75a9e817c2726511701c048d0f9360195b) 133 | - [Refactor] use `hasown` [`6151f01`](https://github.com/inspect-js/is-accessor-descriptor/commit/6151f01a4244d22545cd9fb4ca9b6b772f62a40f) 134 | - [Fix] allow any non-primitive; arrays and functions are objects too [`853db5a`](https://github.com/inspect-js/is-accessor-descriptor/commit/853db5a1af876e7c52bee27f6069779d069b1a5c) 135 | - Only apps should have lockfiles [`87402b1`](https://github.com/inspect-js/is-accessor-descriptor/commit/87402b118e6f391dde566cdcd51f27d0e0aa211f) 136 | - [Fix] use correct logic for two-arg form [`3c1729e`](https://github.com/inspect-js/is-accessor-descriptor/commit/3c1729e0e5658fc8b53dbbd945e1c99b033f562a) 137 | - [Fix] properly guard for-in loop [`442daa8`](https://github.com/inspect-js/is-accessor-descriptor/commit/442daa86d808259f62f2ced02619a2bc84f881be) 138 | - [Tests] move tests to test dir [`18313a7`](https://github.com/inspect-js/is-accessor-descriptor/commit/18313a7d61e9bb0d3ff34b112c2d614a975be0df) 139 | 140 | ## [v0.1.6](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.5...v0.1.6) - 2015-12-28 141 | 142 | ### Commits 143 | 144 | - update docs [`914d85d`](https://github.com/inspect-js/is-accessor-descriptor/commit/914d85d44b914b8b693889081942bf95ea172914) 145 | - update related projects [`92679ea`](https://github.com/inspect-js/is-accessor-descriptor/commit/92679eab1c0eb16eef052218e309aa55b10ce606) 146 | 147 | ## [v0.1.5](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.4...v0.1.5) - 2015-12-28 148 | 149 | ### Commits 150 | 151 | - run update [`139251c`](https://github.com/inspect-js/is-accessor-descriptor/commit/139251c5225d7cdc2b6d16e5c6c713b515643ce8) 152 | - improve checks for valid/invalid properties [`de1be1e`](https://github.com/inspect-js/is-accessor-descriptor/commit/de1be1e6250ca2f084f5d0ac43fed8dd4f607376) 153 | - use verb layout, add verb plugin for formatting markdown [`2324242`](https://github.com/inspect-js/is-accessor-descriptor/commit/23242429e18e6f518318cf1568ec53c636bc1085) 154 | - run verb to generate readme [`84587a4`](https://github.com/inspect-js/is-accessor-descriptor/commit/84587a4269640683049cb06aa75ae9e33165b5fe) 155 | 156 | ## [v0.1.4](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.3...v0.1.4) - 2015-12-20 157 | 158 | ### Commits 159 | 160 | - lint [`d076464`](https://github.com/inspect-js/is-accessor-descriptor/commit/d0764648b3428e7f01303ea7835e25be9d1b5c21) 161 | - generate docs [`12e2143`](https://github.com/inspect-js/is-accessor-descriptor/commit/12e2143ca3d93ece7ae73ee3fcbdb8952d7c5091) 162 | 163 | ## [v0.1.3](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.2...v0.1.3) - 2015-10-04 164 | 165 | ### Commits 166 | 167 | - files prop [`0bcef73`](https://github.com/inspect-js/is-accessor-descriptor/commit/0bcef73f2c7c90be7e05f3dd56f02fbe67790897) 168 | 169 | ## [v0.1.2](https://github.com/inspect-js/is-accessor-descriptor/compare/v0.1.1...v0.1.2) - 2015-10-04 170 | 171 | ### Commits 172 | 173 | - lazy-cache [`fc6da15`](https://github.com/inspect-js/is-accessor-descriptor/commit/fc6da15ecef4a18c20f102a412d596407bb86a5c) 174 | - update docs [`943c0cd`](https://github.com/inspect-js/is-accessor-descriptor/commit/943c0cd4d709eff029fa3880560aec27c0d0f458) 175 | 176 | ## v0.1.1 - 2015-08-31 177 | 178 | ### Commits 179 | 180 | - first commit [`dca2279`](https://github.com/inspect-js/is-accessor-descriptor/commit/dca22793793cf208e65d8daee9d949d76252b647) 181 | - 0.1.1 readme [`27c92b6`](https://github.com/inspect-js/is-accessor-descriptor/commit/27c92b65b85b9bfb39945d646f223cbfd262ab41) 182 | - 0.1.1 docs [`09beed6`](https://github.com/inspect-js/is-accessor-descriptor/commit/09beed68a3c5a5ea76128d5faf2933848181750d) 183 | - lint [`aa03d9b`](https://github.com/inspect-js/is-accessor-descriptor/commit/aa03d9ba1e65e2e71be0add9de75d25cc981e9e2) 184 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present, Jon Schlinkert. 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-accessor-descriptor [![Version Badge][npm-version-svg]][package-url] 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 | > Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. 11 | 12 | ## Examples 13 | 14 | ```js 15 | const isAccessorDescriptor = require('is-accessor-descriptor'); 16 | const assert = require('assert'); 17 | 18 | const obj = { 19 | get foo() {}, 20 | bar: { get: function() {} } 21 | }; 22 | 23 | assert.equal(true, isAccessorDescriptor(obj, 'foo')); 24 | assert.equal(false, isAccessorDescriptor(obj, 'bar')); 25 | 26 | // or, if you already have the descriptor you can pass it directly 27 | const foo = Object.getOwnPropertyDescriptor(obj, 'foo'); 28 | assert.equal(true, isAccessorDescriptor(foo)); 29 | 30 | const bar = Object.getOwnPropertyDescriptor(obj, 'bar'); 31 | assert.equal(false, isAccessorDescriptor(bar)); 32 | ``` 33 | 34 | ### Related projects 35 | 36 | You might also be interested in these projects: 37 | 38 | * [is-data-descriptor](https://www.npmjs.com/package/is-data-descriptor): Returns true if a value has the characteristics of a valid JavaScript data descriptor. 39 | * [is-descriptor](https://www.npmjs.com/package/is-descriptor): Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for… [more](https://github.com/inspect-js/is-descriptor) 40 | * [is-object](https://www.npmjs.com/package/is-object): Returns true if the value is an object and not an array or null. 41 | 42 | ## Tests 43 | Simply clone the repo, `npm install`, and run `npm test` 44 | 45 | [package-url]: https://npmjs.org/package/is-accessor-descriptor 46 | [npm-version-svg]: https://versionbadg.es/inspect-js/is-accessor-descriptor.svg 47 | [deps-svg]: https://david-dm.org/inspect-js/is-accessor-descriptor.svg 48 | [deps-url]: https://david-dm.org/inspect-js/is-accessor-descriptor 49 | [dev-deps-svg]: https://david-dm.org/inspect-js/is-accessor-descriptor/dev-status.svg 50 | [dev-deps-url]: https://david-dm.org/inspect-js/is-accessor-descriptor#info=devDependencies 51 | [npm-badge-png]: https://nodei.co/npm/is-accessor-descriptor.png?downloads=true&stars=true 52 | [license-image]: https://img.shields.io/npm/l/is-accessor-descriptor.svg 53 | [license-url]: LICENSE 54 | [downloads-image]: https://img.shields.io/npm/dm/is-accessor-descriptor.svg 55 | [downloads-url]: https://npm-stat.com/charts.html?package=is-accessor-descriptor 56 | [codecov-image]: https://codecov.io/gh/inspect-js/is-accessor-descriptor/branch/main/graphs/badge.svg 57 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-accessor-descriptor/ 58 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-accessor-descriptor 59 | [actions-url]: https://github.com/inspect-js/is-accessor-descriptor/actions 60 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var hasOwn = require('hasown'); 4 | var gOPD = require('gopd'); 5 | 6 | var isObject = function (val) { 7 | return val !== null && typeof val === 'object' && !Array.isArray(val); 8 | }; 9 | 10 | module.exports = function isAccessorDescriptor(obj, key, checkProto) { 11 | if (!isObject(obj)) { 12 | return false; 13 | } 14 | 15 | if (arguments.length > 1) { 16 | var hasKey = hasOwn(obj, key); 17 | if (!hasKey && checkProto !== false) { 18 | return isAccessorDescriptor(obj.constructor.prototype, key, false); 19 | } 20 | return gOPD ? isAccessorDescriptor(gOPD(obj, key)) : hasKey; 21 | } 22 | 23 | var desc = obj; 24 | if ( 25 | !hasOwn(desc, 'get') 26 | || !hasOwn(desc, 'set') 27 | || !hasOwn(desc, 'enumerable') 28 | || !hasOwn(desc, 'configurable') 29 | ) { 30 | return false; 31 | } 32 | 33 | for (var descKey in desc) { // eslint-disable-line no-restricted-syntax 34 | if (hasOwn(desc, descKey)) { 35 | if ( 36 | descKey !== 'get' 37 | && descKey !== 'set' 38 | && descKey !== 'enumerable' 39 | && descKey !== 'configurable' 40 | ) { 41 | return false; 42 | } 43 | 44 | var val = desc[descKey]; 45 | if (descKey === 'get' || descKey === 'set') { 46 | if (typeof val !== 'undefined' && typeof val !== 'function') { 47 | return false; 48 | } 49 | } else if (typeof val !== 'boolean') { 50 | return false; 51 | } 52 | } 53 | } 54 | return true; 55 | }; 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-accessor-descriptor", 3 | "version": "3.0.5", 4 | "description": "Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.", 5 | "main": "index.js", 6 | "exports": { 7 | ".": "./index.js", 8 | "./package.json": "./package.json" 9 | }, 10 | "sideEffects": true, 11 | "scripts": { 12 | "prepack": "npmignore --auto --commentLines=autogenerated", 13 | "prepublishOnly": "safe-publish-latest", 14 | "prepublish": "not-in-publish || npm run prepublishOnly", 15 | "prelint": "evalmd README.md", 16 | "lint": "eslint --ext=js,mjs .", 17 | "pretest": "npm run lint", 18 | "tests-only": "nyc tape 'test/**/*.js'", 19 | "test": "npm run tests-only", 20 | "posttest": "aud --production", 21 | "version": "auto-changelog && git add CHANGELOG.md", 22 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/inspect-js/is-accessor-descriptor.git" 27 | }, 28 | "keywords": [ 29 | "accessor", 30 | "check", 31 | "data", 32 | "descriptor", 33 | "get", 34 | "getter", 35 | "is", 36 | "keys", 37 | "object", 38 | "properties", 39 | "property", 40 | "set", 41 | "setter", 42 | "type", 43 | "valid", 44 | "value" 45 | ], 46 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 47 | "license": "MIT", 48 | "bugs": { 49 | "url": "https://github.com/inspect-js/is-accessor-descriptor/issues" 50 | }, 51 | "homepage": "https://github.com/inspect-js/is-accessor-descriptor", 52 | "contributors": [ 53 | "Jon Schlinkert (https://twitter.com/jonschlinkert)", 54 | "Jordan Harband " 55 | ], 56 | "dependencies": { 57 | "gopd": "^1.0.1", 58 | "hasown": "^2.0.0" 59 | }, 60 | "devDependencies": { 61 | "@ljharb/eslint-config": "^21.1.0", 62 | "aud": "^2.0.3", 63 | "auto-changelog": "^2.4.0", 64 | "eslint": "=8.8.0", 65 | "evalmd": "^0.0.19", 66 | "has-property-descriptors": "^1.0.1", 67 | "in-publish": "^2.0.1", 68 | "npmignore": "^0.3.0", 69 | "nyc": "^10.3.2", 70 | "safe-publish-latest": "^2.0.0", 71 | "tape": "^5.7.2" 72 | }, 73 | "engines": { 74 | "node": ">= 0.4" 75 | }, 76 | "auto-changelog": { 77 | "output": "CHANGELOG.md", 78 | "template": "keepachangelog", 79 | "unreleased": false, 80 | "commitLimit": false, 81 | "backfillLimit": false, 82 | "hideCredit": true 83 | }, 84 | "publishConfig": { 85 | "ignore": [ 86 | ".github/workflows" 87 | ] 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | var hasPropertyDescriptors = require('has-property-descriptors')(); 5 | var gOPD = require('gopd'); 6 | var isAccessorDescriptor = require('../'); 7 | var noop = function () {}; 8 | 9 | test('isAccessorDescriptor', function (t) { 10 | t.test('value type: is false when not an object', function (st) { 11 | st.notOk(isAccessorDescriptor('a')); 12 | st.notOk(isAccessorDescriptor(null)); 13 | st.notOk(isAccessorDescriptor([])); 14 | 15 | st.end(); 16 | }); 17 | 18 | t.notOk( 19 | isAccessorDescriptor({ 20 | foo: { 21 | writable: true, 22 | enumerable: true, 23 | configurable: true, 24 | get: noop, 25 | set: noop 26 | } 27 | }, 'foo'), 28 | 'is false when the property has data descriptor properties' 29 | ); 30 | 31 | t.test('should be true when the property is a valid getter/setter', { skip: !hasPropertyDescriptors }, function (st) { 32 | var obj = { 33 | foo: function () {} 34 | }; 35 | Object.defineProperty(obj, 'bar', { 36 | get: function bar() {}, 37 | set: function bar(value) {} // eslint-disable-line no-unused-vars 38 | }); 39 | 40 | st.ok(isAccessorDescriptor(obj, 'bar')); 41 | st.ok(isAccessorDescriptor(gOPD(obj, 'bar'))); 42 | 43 | st.end(); 44 | }); 45 | 46 | t.test('constructor.prototype:', { skip: !hasPropertyDescriptors }, function (st) { 47 | var Foo = function Foo() {}; // eslint-disable-line func-name-matching 48 | Object.defineProperty(Foo.prototype, 'bar', { 49 | get: function bar() { 50 | return 'baz'; 51 | } 52 | }); 53 | 54 | st.ok(isAccessorDescriptor(new Foo(), 'bar'), 'checks ctor.prototype'); 55 | st.notOk(isAccessorDescriptor(new Foo(), 'bar', false), 'does not check ctor.prototype when disabled'); 56 | 57 | st.end(); 58 | }); 59 | 60 | t.test('is false when get or set are not functions', function (st) { 61 | st.notOk(isAccessorDescriptor({ 62 | configurable: true, 63 | enumerable: true, 64 | set: 'baz', 65 | get: noop 66 | })); 67 | 68 | st.notOk(isAccessorDescriptor({ 69 | configurable: true, 70 | enumerable: true, 71 | set: noop, 72 | get: 'foo' 73 | })); 74 | 75 | st.notOk(isAccessorDescriptor({ 76 | configurable: true, 77 | enumerable: true, 78 | bar: 'baz', 79 | get: 'foo' 80 | })); 81 | 82 | st.notOk(isAccessorDescriptor({ 83 | configurable: true, 84 | enumerable: true, 85 | set: 'baz', 86 | get: 'foo' 87 | })); 88 | 89 | st.notOk(isAccessorDescriptor({ 90 | get: 'foo', 91 | enumerable: true, 92 | configurable: true 93 | })); 94 | 95 | st.end(); 96 | }); 97 | 98 | t.test('is false when the object lacks necessary properties', function (st) { 99 | st.notOk(isAccessorDescriptor({ set: noop })); 100 | st.notOk(isAccessorDescriptor({ get: noop, set: noop })); 101 | st.notOk(isAccessorDescriptor({ get: noop })); 102 | 103 | st.end(); 104 | }); 105 | 106 | t.test('is false when invalid properties are defined', function (st) { 107 | st.notOk(isAccessorDescriptor({ 108 | enumerable: true, 109 | configurable: true, 110 | get: noop, 111 | foo: true 112 | })); 113 | 114 | st.notOk(isAccessorDescriptor({ 115 | enumerable: true, 116 | configurable: true, 117 | get: noop, 118 | bar: true 119 | })); 120 | 121 | st.end(); 122 | }); 123 | 124 | t.test('is false when a value is not the correct type', function (st) { 125 | st.notOk(isAccessorDescriptor({ get: noop, set: noop, enumerable: 'foo' })); 126 | st.notOk(isAccessorDescriptor({ set: noop, configurable: 'foo' })); 127 | st.notOk(isAccessorDescriptor({ get: noop, configurable: 'foo' })); 128 | 129 | st.end(); 130 | }); 131 | 132 | t.test('with a key', { skip: !hasPropertyDescriptors }, function (st) { 133 | var desc = { enumerable: true, get: function () {} }; 134 | 135 | st.equal(isAccessorDescriptor(Object.defineProperty({}, 'foo', desc), 'foo'), true, 'an accessor property is an accessor descriptor'); 136 | st.equal(isAccessorDescriptor(Object.defineProperty({}, '', desc), ''), true, 'an empty string accessor property is an accessor descriptor'); 137 | st.equal(isAccessorDescriptor(Object.defineProperty({}, 0, desc), 0), true, 'a zero accessor property is an accessor descriptor'); 138 | 139 | st.end(); 140 | }); 141 | }); 142 | --------------------------------------------------------------------------------