├── .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 | "extends": "@ljharb", 3 | 4 | "rules": { 5 | "func-style": "warn", 6 | }, 7 | 8 | "overrides": [ 9 | { 10 | "files": "test/**/*.js", 11 | "rules": { 12 | "max-lines-per-function": "off", 13 | }, 14 | }, 15 | ], 16 | } 17 | -------------------------------------------------------------------------------- /.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-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.1.1](https://github.com/inspect-js/is-descriptor/compare/v3.1.0...v3.1.1) - 2023-10-27 9 | 10 | ### Commits 11 | 12 | - [Fix] require fully completed property descriptor; use `gopd` and `hasown` [`d32fc37`](https://github.com/inspect-js/is-descriptor/commit/d32fc3743504a3d72815d820d45a60a6f70eb8bd) 13 | - Merge tag `v0.1.7`, `v1.0.3`` [`596c888`](https://github.com/inspect-js/is-descriptor/commit/596c888a558420697a396947cd24d0edd42e19ef) 14 | - [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) 15 | - [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) 16 | - [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) 17 | - [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) 18 | - [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) 19 | - [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) 20 | - [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) 21 | - [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) 22 | - [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) 23 | - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`52668c9`](https://github.com/inspect-js/is-descriptor/commit/52668c9c4b3e2aa18f32b368523e65fdb933ca9c) 24 | - [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) 25 | - [Tests] fix incorrect test [`5f4b0e1`](https://github.com/inspect-js/is-descriptor/commit/5f4b0e14412e36d1ddba37ce099c097bfade1dc0) 26 | - v0.x line: v1 and v0 are the same, so, branch v0 from 1.x [`91be723`](https://github.com/inspect-js/is-descriptor/commit/91be72399c3066950d2414a6d2f091e1074625cd) 27 | - [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) 28 | 29 | ## [v3.1.0](https://github.com/inspect-js/is-descriptor/compare/v3.0.0...v3.1.0) - 2023-05-01 30 | 31 | ### Commits 32 | 33 | - [eslint] cleanup [`1f4e8cd`](https://github.com/inspect-js/is-descriptor/commit/1f4e8cdb49b4b15666a782f3f05e6f4f0146b9ab) 34 | - [Tests] travis -> Github Actions; add `safe-publish-latest`, `npmignore`, `auto-changelog`, `evalmd`, `aud` [`5993285`](https://github.com/inspect-js/is-descriptor/commit/5993285a122ef7bf5b91cba3b486f96a1f94f552) 35 | - [readme] clean up docs, URLs, package.json, etc [`8807164`](https://github.com/inspect-js/is-descriptor/commit/88071644c15d543c7830e6ac00a5ed8531c82750) 36 | - [Docs] remove verb [`0bc26a3`](https://github.com/inspect-js/is-descriptor/commit/0bc26a306f02241e6c5c506e95c53ca828031c05) 37 | - [Tests] convert from mocha to tape [`1604d7f`](https://github.com/inspect-js/is-descriptor/commit/1604d7feebd776b0fb67163e3013cc6d5ab9fd6b) 38 | - [New] increase support from node 6 down to node 0.4 [`7893404`](https://github.com/inspect-js/is-descriptor/commit/789340412f4028d46a3121466a25497716b94402) 39 | - [Tests] add coverage [`1dcc45e`](https://github.com/inspect-js/is-descriptor/commit/1dcc45ed57aebc83ba0588c232663f4164a7d0a8) 40 | - [Fix] when an object/key pair is provided, check arguments.length instead of key truthiness [`d1edefe`](https://github.com/inspect-js/is-descriptor/commit/d1edefef56c7eeaab385b1704417b314f197034d) 41 | - [meta] switch from `files` field to npmignore; add `exports` [`c64d3d3`](https://github.com/inspect-js/is-descriptor/commit/c64d3d356d459f2e73198841f93fb902895875b4) 42 | 43 | ## [v3.0.0](https://github.com/inspect-js/is-descriptor/compare/v2.0.0...v3.0.0) - 2018-12-13 44 | 45 | ### Commits 46 | 47 | - refactor [`7f7e2c8`](https://github.com/inspect-js/is-descriptor/commit/7f7e2c865674526424f5cd1fb98f0ed7811a67f9) 48 | 49 | ## [v2.0.0](https://github.com/inspect-js/is-descriptor/compare/v1.0.3...v2.0.0) - 2017-12-28 50 | 51 | ### Commits 52 | 53 | - run verb to generate readme [`7d97594`](https://github.com/inspect-js/is-descriptor/commit/7d97594666afaa825e0421883507cfec04ceef1d) 54 | - upgrade is-accessor-descriptor [`2e2cb1e`](https://github.com/inspect-js/is-descriptor/commit/2e2cb1e723d2ca1d6b8580d384702700e26dda81) 55 | - run update [`c04832a`](https://github.com/inspect-js/is-descriptor/commit/c04832a3a2bf48bef2ea0f5844652da7d6209242) 56 | 57 | ## [v1.0.3](https://github.com/inspect-js/is-descriptor/compare/v1.0.2...v1.0.3) - 2023-10-26 58 | 59 | ### Commits 60 | 61 | - [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) 62 | - [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) 63 | - [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) 64 | - [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) 65 | - [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) 66 | - [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) 67 | - [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) 68 | - [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) 69 | - [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) 70 | - [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) 71 | - [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) 72 | 73 | ## [v1.0.2](https://github.com/inspect-js/is-descriptor/compare/v1.0.1...v1.0.2) - 2017-12-28 74 | 75 | ### Merged 76 | 77 | - Update dependencies [`#5`](https://github.com/inspect-js/is-descriptor/pull/5) 78 | 79 | ## [v1.0.1](https://github.com/inspect-js/is-descriptor/compare/v1.0.0...v1.0.1) - 2017-07-22 80 | 81 | ### Commits 82 | 83 | - run update, lint [`754cc73`](https://github.com/inspect-js/is-descriptor/commit/754cc7382bd439f8e8b91775479c59c7c996cd47) 84 | - update deps [`2b58af6`](https://github.com/inspect-js/is-descriptor/commit/2b58af6426d0700607419b096766829aff27f642) 85 | 86 | ## [v1.0.0](https://github.com/inspect-js/is-descriptor/compare/v0.1.7...v1.0.0) - 2017-02-25 87 | 88 | ## [v0.1.7](https://github.com/inspect-js/is-descriptor/compare/v0.1.6...v0.1.7) - 2023-10-26 89 | 90 | ### Merged 91 | 92 | - Update dependencies [`#5`](https://github.com/inspect-js/is-descriptor/pull/5) 93 | 94 | ### Commits 95 | 96 | - [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) 97 | - [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) 98 | - [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) 99 | - [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) 100 | - [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) 101 | - [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) 102 | - run update, lint [`754cc73`](https://github.com/inspect-js/is-descriptor/commit/754cc7382bd439f8e8b91775479c59c7c996cd47) 103 | - [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) 104 | - [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) 105 | - [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) 106 | - update deps [`2b58af6`](https://github.com/inspect-js/is-descriptor/commit/2b58af6426d0700607419b096766829aff27f642) 107 | - [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) 108 | - v0.x line: v1 and v0 are the same, so, branch v0 from 1.x [`91be723`](https://github.com/inspect-js/is-descriptor/commit/91be72399c3066950d2414a6d2f091e1074625cd) 109 | - [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) 110 | 111 | ## [v0.1.6](https://github.com/inspect-js/is-descriptor/compare/v0.1.5...v0.1.6) - 2017-07-22 112 | 113 | ## [v0.1.5](https://github.com/inspect-js/is-descriptor/compare/v0.1.4...v0.1.5) - 2017-02-25 114 | 115 | ### Merged 116 | 117 | - Bump `lazy-cache`. [`#4`](https://github.com/inspect-js/is-descriptor/pull/4) 118 | 119 | ### Commits 120 | 121 | - update docs, fix typos [`bc3cf69`](https://github.com/inspect-js/is-descriptor/commit/bc3cf6915686d4a964997ae7585bf65005bbf955) 122 | - run update [`1956814`](https://github.com/inspect-js/is-descriptor/commit/1956814c67c2033caeaed469ad09e6392dd0799e) 123 | 124 | ## [v0.1.4](https://github.com/inspect-js/is-descriptor/compare/v0.1.3...v0.1.4) - 2015-12-28 125 | 126 | ### Commits 127 | 128 | - allow a key to be passed [`202062b`](https://github.com/inspect-js/is-descriptor/commit/202062b56735525e7def35c8453505778ce9de03) 129 | - update docs [`890fe80`](https://github.com/inspect-js/is-descriptor/commit/890fe80100aa21cac1bee55d6fb4045ffb661ff7) 130 | 131 | ## [v0.1.3](https://github.com/inspect-js/is-descriptor/compare/v0.1.2...v0.1.3) - 2015-12-20 132 | 133 | ### Commits 134 | 135 | - lint [`fa81701`](https://github.com/inspect-js/is-descriptor/commit/fa817018aabb6f18e7f09e452b80386775773d42) 136 | - add gulp-format-md to verb config, build readme [`8e6c159`](https://github.com/inspect-js/is-descriptor/commit/8e6c159cfa23b357dbac8f977c3a9421172aafeb) 137 | - update deps [`b7b8321`](https://github.com/inspect-js/is-descriptor/commit/b7b8321e194f4f25c5aa4ff382a0a8ffb6482cc1) 138 | 139 | ## [v0.1.2](https://github.com/inspect-js/is-descriptor/compare/v0.1.1...v0.1.2) - 2015-10-04 140 | 141 | ### Commits 142 | 143 | - files prop [`3aaf1ce`](https://github.com/inspect-js/is-descriptor/commit/3aaf1ce8483bdee217e2f18b293937a09634a33b) 144 | 145 | ## [v0.1.1](https://github.com/inspect-js/is-descriptor/compare/v0.1.0...v0.1.1) - 2015-10-04 146 | 147 | ### Merged 148 | 149 | - Update .verb.md [`#1`](https://github.com/inspect-js/is-descriptor/pull/1) 150 | 151 | ### Commits 152 | 153 | - adds lazy-caching [`0219f1a`](https://github.com/inspect-js/is-descriptor/commit/0219f1aa95b9ce7c08e0a1e00fe506a572c6ac46) 154 | - 0.1.1 readme [`924a5a7`](https://github.com/inspect-js/is-descriptor/commit/924a5a7a5d648d901b24b7287d9a5d232865f603) 155 | - fix readme [`dd9c431`](https://github.com/inspect-js/is-descriptor/commit/dd9c4315dd61be73f42d07bc71ddb97414dfdbcf) 156 | 157 | ## v0.1.0 - 2015-08-31 158 | 159 | ### Commits 160 | 161 | - first commit [`b5d8c39`](https://github.com/inspect-js/is-descriptor/commit/b5d8c39843c98588b67069325a4e6455beb8aef3) 162 | - 0.1.0 readme [`aaffb92`](https://github.com/inspect-js/is-descriptor/commit/aaffb924062d7c588417d9a2184ff1129f8d294a) 163 | - 0.1.0 docs [`eb0da6c`](https://github.com/inspect-js/is-descriptor/commit/eb0da6c548e59ff76f6a80a95ea0a750dab40591) 164 | - use libs [`86ad32f`](https://github.com/inspect-js/is-descriptor/commit/86ad32fe5a07d2705b14bb3e237584c05d60d519) 165 | - lint [`94fbcc9`](https://github.com/inspect-js/is-descriptor/commit/94fbcc9c2a3da1e9b888bad86b9576259d1d7940) 166 | -------------------------------------------------------------------------------- /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-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 descriptor. Works for fully completed data descriptors and accessor descriptors. 11 | 12 | ## Usage 13 | 14 | ```js 15 | const isDescriptor = require('is-descriptor'); 16 | const assert = require('assert'); 17 | 18 | const defaults = { configurable: false, enumerable: false }; 19 | const dataDefaults = { ...defaults, writable: false}; 20 | 21 | assert.ok(isDescriptor({ ...dataDefaults, value: 'foo' })); 22 | assert.ok(isDescriptor({ ...defaults, get() {}, set() {} })); 23 | assert.ok(!isDescriptor({ ...defaults, get: 'foo', set() {} })); 24 | ``` 25 | 26 | You may also check for a descriptor by passing an object as the first argument and property name (`string`) as the second argument. 27 | 28 | ```js 29 | const obj = { foo: 'abc' }; 30 | 31 | Object.defineProperty(obj, 'bar', { value: 'xyz' }); 32 | Reflect.defineProperty(obj, 'baz', { value: 'xyz' }); 33 | 34 | assert.equal(isDescriptor(obj, 'foo'), true); 35 | assert.equal(isDescriptor(obj, 'bar'), true); 36 | assert.equal(isDescriptor(obj, 'baz'), true); 37 | ``` 38 | 39 | ## Examples 40 | 41 | ### value type 42 | 43 | Returns `false` when not an object 44 | 45 | ```js 46 | assert.equal(isDescriptor('a'), false); 47 | assert.equal(isDescriptor(null), false); 48 | assert.equal(isDescriptor([]), false); 49 | ``` 50 | 51 | ### data descriptor 52 | 53 | Returns `true` when the object has valid properties with valid values. 54 | 55 | ```js 56 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo' }), true); 57 | assert.equal(isDescriptor({ ...dataDefaults, value() {} }), true); 58 | ``` 59 | 60 | Returns `false` when the object has invalid properties 61 | 62 | ```js 63 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false); 64 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false); 65 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'baz' }), false); 66 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'baz' }), false); 67 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', get() {} }), false); 68 | assert.equal(isDescriptor({ ...dataDefaults, get() {}, value() {} }), false); 69 | ``` 70 | 71 | `false` when a value is not the correct type 72 | 73 | ```js 74 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'foo' }), false); 75 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'foo' }), false); 76 | assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', writable: 'foo' }), false); 77 | ``` 78 | 79 | ### accessor descriptor 80 | 81 | `true` when the object has valid properties with valid values. 82 | 83 | ```js 84 | assert.equal(isDescriptor({ ...defaults, get() {}, set() {} }), true); 85 | assert.equal(isDescriptor({ ...defaults, get() {} }), true); 86 | assert.equal(isDescriptor({ ...defaults, set() {} }), true); 87 | ``` 88 | 89 | `false` when the object has invalid properties 90 | 91 | ```js 92 | assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, bar: 'baz' }), false); 93 | assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'baz' }), false); 94 | assert.equal(isDescriptor({ ...defaults, get() {}, writable: true }), false); 95 | assert.equal(isDescriptor({ ...defaults, get() {}, value: true }), false); 96 | ``` 97 | 98 | Returns `false` when an accessor is not a function 99 | 100 | ```js 101 | assert.equal(isDescriptor({ ...defaults, get() {}, set: 'baz' }), false); 102 | assert.equal(isDescriptor({ ...defaults, get: 'foo', set() {} }), false); 103 | assert.equal(isDescriptor({ ...defaults, get: 'foo', bar: 'baz' }), false); 104 | assert.equal(isDescriptor({ ...defaults, get: 'foo', set: 'baz' }), false); 105 | ``` 106 | 107 | Returns `false` when a value is not the correct type 108 | 109 | ```js 110 | assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'foo' }), false); 111 | assert.equal(isDescriptor({ ...defaults, set() {}, configurable: 'foo' }), false); 112 | assert.equal(isDescriptor({ ...defaults, get() {}, configurable: 'foo' }), false); 113 | ``` 114 | 115 | ### Related projects 116 | 117 | You might also be interested in these projects: 118 | 119 | * [is-accessor-descriptor](https://www.npmjs.com/package/is-accessor-descriptor): Returns true if a value has the characteristics of a valid JavaScript accessor descriptor. 120 | * [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. 121 | * [is-object](https://www.npmjs.com/package/is-object): Returns true if the value is an object and not an array or null. 122 | 123 | ## Tests 124 | Simply clone the repo, `npm install`, and run `npm test` 125 | 126 | [package-url]: https://npmjs.org/package/is-descriptor 127 | [npm-version-svg]: https://versionbadg.es/inspect-js/is-descriptor.svg 128 | [deps-svg]: https://david-dm.org/inspect-js/is-descriptor.svg 129 | [deps-url]: https://david-dm.org/inspect-js/is-descriptor 130 | [dev-deps-svg]: https://david-dm.org/inspect-js/is-descriptor/dev-status.svg 131 | [dev-deps-url]: https://david-dm.org/inspect-js/is-descriptor#info=devDependencies 132 | [npm-badge-png]: https://nodei.co/npm/is-descriptor.png?downloads=true&stars=true 133 | [license-image]: https://img.shields.io/npm/l/is-descriptor.svg 134 | [license-url]: LICENSE 135 | [downloads-image]: https://img.shields.io/npm/dm/is-descriptor.svg 136 | [downloads-url]: https://npm-stat.com/charts.html?package=is-descriptor 137 | [codecov-image]: https://codecov.io/gh/inspect-js/is-descriptor/branch/main/graphs/badge.svg 138 | [codecov-url]: https://app.codecov.io/gh/inspect-js/is-descriptor/ 139 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-descriptor 140 | [actions-url]: https://github.com/inspect-js/is-descriptor/actions 141 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gOPD = require('gopd'); 4 | var hasOwn = require('hasown'); 5 | var isDataDescriptor = require('is-data-descriptor'); 6 | var isAccessorDescriptor = require('is-accessor-descriptor'); 7 | 8 | var isObject = function (val) { 9 | return val !== null && typeof val === 'object'; 10 | }; 11 | 12 | module.exports = function isDescriptor(obj, key, checkProto) { 13 | if (!isObject(obj)) { 14 | return false; 15 | } 16 | 17 | var desc; 18 | if (arguments.length > 1) { 19 | if (gOPD) { 20 | desc = gOPD(obj, key); 21 | if (desc) { 22 | return isDescriptor(desc); 23 | } 24 | return checkProto !== false 25 | && obj.contructor 26 | && isDescriptor(gOPD(obj.constructor.prototype, key)); 27 | } 28 | if (hasOwn(obj, key)) { 29 | return true; 30 | } 31 | if (checkProto !== false && obj.constructor) { 32 | return hasOwn(obj.constructor.prototype, key); 33 | } 34 | return false; 35 | } 36 | desc = obj; 37 | 38 | if (typeof desc.configurable !== 'boolean' || typeof desc.enumerable !== 'boolean') { 39 | return false; 40 | } 41 | 42 | return isDataDescriptor(desc) || isAccessorDescriptor(desc); 43 | }; 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-descriptor", 3 | "version": "3.1.1", 4 | "description": "Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.", 5 | "main": "index.js", 6 | "exports": { 7 | ".": "./index.js", 8 | "./package.json": "./package.json" 9 | }, 10 | "scripts": { 11 | "prepack": "npmignore --auto --commentLines=autogenerated", 12 | "prepublishOnly": "safe-publish-latest", 13 | "prepublish": "not-in-publish || npm run prepublishOnly", 14 | "prelint-disabled": "evalmd README.md # https://github.com/reggi/evalmd/issues/27", 15 | "lint": "eslint --ext=js,mjs .", 16 | "pretest": "npm run lint", 17 | "tests-only": "nyc tape 'test/**/*.js'", 18 | "test": "npm run tests-only", 19 | "posttest": "aud --production", 20 | "version": "auto-changelog && git add CHANGELOG.md", 21 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/inspect-js/is-descriptor.git" 26 | }, 27 | "keywords": [ 28 | "accessor", 29 | "check", 30 | "data", 31 | "descriptor", 32 | "get", 33 | "getter", 34 | "is", 35 | "keys", 36 | "object", 37 | "properties", 38 | "property", 39 | "set", 40 | "setter", 41 | "type", 42 | "valid", 43 | "value" 44 | ], 45 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 46 | "license": "MIT", 47 | "bugs": { 48 | "url": "https://github.com/inspect-js/is-descriptor/issues" 49 | }, 50 | "homepage": "https://github.com/inspect-js/is-descriptor", 51 | "contributors": [ 52 | "Brian Woodward (https://twitter.com/doowb)", 53 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 54 | "(https://github.com/wtgtybhertgeghgtwtg)" 55 | ], 56 | "dependencies": { 57 | "gopd": "^1.0.1", 58 | "hasown": "^2.0.0", 59 | "is-accessor-descriptor": "^3.0.5", 60 | "is-data-descriptor": "^2.1.3" 61 | }, 62 | "devDependencies": { 63 | "@ljharb/eslint-config": "^21.1.0", 64 | "aud": "^2.0.3", 65 | "auto-changelog": "^2.4.0", 66 | "eslint": "=8.8.0", 67 | "evalmd": "^0.0.19", 68 | "in-publish": "^2.0.1", 69 | "npmignore": "^0.3.0", 70 | "nyc": "^10.3.2", 71 | "safe-publish-latest": "^2.0.0", 72 | "tape": "^5.7.2" 73 | }, 74 | "engines": { 75 | "node": ">= 0.4" 76 | }, 77 | "auto-changelog": { 78 | "output": "CHANGELOG.md", 79 | "template": "keepachangelog", 80 | "unreleased": false, 81 | "commitLimit": false, 82 | "backfillLimit": false, 83 | "hideCredit": true 84 | }, 85 | "publishConfig": { 86 | "ignore": [ 87 | ".github/workflows" 88 | ] 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var test = require('tape'); 4 | var isDescriptor = require('../'); 5 | var noop = function () {}; 6 | 7 | test('isDescriptor', function (t) { 8 | t.test('is false when not an object:', function (st) { 9 | st.notOk(isDescriptor('a')); 10 | st.notOk(isDescriptor(null)); 11 | st.notOk(isDescriptor([])); 12 | 13 | st.end(); 14 | }); 15 | 16 | t.test('check for descriptor', function (st) { 17 | st.test('returns true if the property exists', function (s2t) { 18 | var obj = { foo: null }; 19 | 20 | Object.defineProperty(obj, 'bar', { 21 | value: 'xyz' 22 | }); 23 | 24 | Object.defineProperty(obj, 'baz', { 25 | get: function () { 26 | return 'aaa'; 27 | } 28 | }); 29 | 30 | (typeof Reflect === 'function' ? Reflect : Object).defineProperty(obj, 'qux', { 31 | value: 'xyz' 32 | }); 33 | 34 | s2t.ok(isDescriptor(obj, 'foo')); 35 | s2t.ok(isDescriptor(obj, 'bar')); 36 | s2t.ok(isDescriptor(obj, 'baz')); 37 | s2t.ok(isDescriptor(obj, 'qux')); 38 | 39 | s2t.end(); 40 | }); 41 | 42 | st.end(); 43 | }); 44 | 45 | t.test('with a key', function (st) { 46 | st.equal(isDescriptor({ foo: 3 }, 'foo'), true, 'a data property is a data descriptor'); 47 | st.equal(isDescriptor({ '': 3 }, ''), true, 'an empty string data property is a data descriptor'); 48 | st.equal(isDescriptor({ 0: 3 }, 0), true, 'a zero data property is a data descriptor'); 49 | st.end(); 50 | }); 51 | 52 | t.test('data descriptor:', function (st) { 53 | st.test('is false when the object has invalid properties:', function (s2t) { 54 | s2t.notOk(isDescriptor({ value: 'foo', get: noop })); 55 | s2t.notOk(isDescriptor({ get: noop, value: noop })); 56 | 57 | s2t.end(); 58 | }); 59 | 60 | st.test('is false when the object has unrecognized properties:', function (s2t) { 61 | s2t.notOk(isDescriptor({ value: 'foo', bar: 'baz' })); 62 | s2t.notOk(isDescriptor({ value: 'foo', bar: 'baz' })); 63 | 64 | s2t.end(); 65 | }); 66 | 67 | st.test('is false when not descriptors', function (s2t) { 68 | s2t.notOk(isDescriptor({ value: 'foo' })); 69 | s2t.notOk(isDescriptor({ value: noop })); 70 | 71 | s2t.end(); 72 | }); 73 | 74 | st.test('is false when a value is not the correct type:', function (s2t) { 75 | s2t.notOk(isDescriptor({ value: 'foo', enumerable: 'foo' })); 76 | s2t.notOk(isDescriptor({ value: 'foo', configurable: 'foo' })); 77 | s2t.notOk(isDescriptor({ value: 'foo', writable: 'foo' })); 78 | 79 | s2t.end(); 80 | }); 81 | 82 | st.end(); 83 | }); 84 | 85 | t.test('accessor descriptor:', function (st) { 86 | st.test('is false when the object has invalid properties:', function (s2t) { 87 | s2t.notOk(isDescriptor({ get: noop, writable: true })); 88 | s2t.notOk(isDescriptor({ get: noop, value: true })); 89 | 90 | s2t.end(); 91 | }); 92 | 93 | st.test('is false when the object has unrecognize properties:', function (s2t) { 94 | s2t.notOk(isDescriptor({ get: noop, set: noop, bar: 'baz' })); 95 | 96 | s2t.end(); 97 | }); 98 | 99 | st.test('is false when an accessor is not a function:', function (s2t) { 100 | s2t.notOk(isDescriptor({ get: noop, set: 'baz' })); 101 | s2t.notOk(isDescriptor({ get: 'foo', set: noop })); 102 | s2t.notOk(isDescriptor({ get: 'foo', bar: 'baz' })); 103 | s2t.notOk(isDescriptor({ get: 'foo', set: 'baz' })); 104 | 105 | s2t.end(); 106 | }); 107 | 108 | st.test('is false when "get" or "set" is not a function', function (s2t) { 109 | s2t.notOk(isDescriptor({ enumerable: true, configurable: true, set: noop })); 110 | s2t.notOk(isDescriptor({ enumerable: true, configurable: true, get: 'foo' })); 111 | s2t.notOk(isDescriptor({ enumerable: true, configurable: true, set: 'foo' })); 112 | 113 | s2t.end(); 114 | }); 115 | 116 | st.test('is true when the object has all necessary properties', function (s2t) { 117 | s2t.ok(isDescriptor({ get: noop, set: noop, configurable: true, enumerable: true })); 118 | 119 | s2t.end(); 120 | }); 121 | 122 | st.test('is false when the object does not have all necessary properties', function (s2t) { 123 | s2t.notOk(isDescriptor({ get: noop, set: noop })); 124 | s2t.notOk(isDescriptor({ get: noop })); 125 | 126 | s2t.end(); 127 | }); 128 | 129 | st.test('is false when a value is not the correct type:', function (s2t) { 130 | s2t.notOk(isDescriptor({ get: noop, set: noop, enumerable: 'foo' })); 131 | s2t.notOk(isDescriptor({ set: noop, configurable: 'foo' })); 132 | s2t.notOk(isDescriptor({ get: noop, configurable: 'foo' })); 133 | 134 | s2t.end(); 135 | }); 136 | 137 | st.end(); 138 | }); 139 | }); 140 | --------------------------------------------------------------------------------