is-descriptor
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -8,2 +8,23 @@ # Changelog | ||
## [v3.1.1](https://github.com/inspect-js/is-descriptor/compare/v3.1.0...v3.1.1) - 2023-10-27 | ||
### Commits | ||
- [Fix] require fully completed property descriptor; use `gopd` and `hasown` [`d32fc37`](https://github.com/inspect-js/is-descriptor/commit/d32fc3743504a3d72815d820d45a60a6f70eb8bd) | ||
- Merge tag `v0.1.7`, `v1.0.3`` [`596c888`](https://github.com/inspect-js/is-descriptor/commit/596c888a558420697a396947cd24d0edd42e19ef) | ||
- [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) | ||
- [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) | ||
- [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) | ||
- [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) | ||
- [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) | ||
- [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) | ||
- [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) | ||
- [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) | ||
- [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) | ||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`52668c9`](https://github.com/inspect-js/is-descriptor/commit/52668c9c4b3e2aa18f32b368523e65fdb933ca9c) | ||
- [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) | ||
- [Tests] fix incorrect test [`5f4b0e1`](https://github.com/inspect-js/is-descriptor/commit/5f4b0e14412e36d1ddba37ce099c097bfade1dc0) | ||
- 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) | ||
- [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) | ||
## [v3.1.0](https://github.com/inspect-js/is-descriptor/compare/v3.0.0...v3.1.0) - 2023-05-01 | ||
@@ -29,3 +50,3 @@ | ||
## [v2.0.0](https://github.com/inspect-js/is-descriptor/compare/v1.0.2...v2.0.0) - 2017-12-28 | ||
## [v2.0.0](https://github.com/inspect-js/is-descriptor/compare/v1.0.3...v2.0.0) - 2017-12-28 | ||
@@ -38,2 +59,18 @@ ### Commits | ||
## [v1.0.3](https://github.com/inspect-js/is-descriptor/compare/v1.0.2...v1.0.3) - 2023-10-26 | ||
### Commits | ||
- [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) | ||
- [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) | ||
- [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) | ||
- [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) | ||
- [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) | ||
- [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) | ||
- [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) | ||
- [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) | ||
- [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) | ||
- [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) | ||
- [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) | ||
## [v1.0.2](https://github.com/inspect-js/is-descriptor/compare/v1.0.1...v1.0.2) - 2017-12-28 | ||
@@ -52,4 +89,27 @@ | ||
## [v1.0.0](https://github.com/inspect-js/is-descriptor/compare/v0.1.6...v1.0.0) - 2017-02-25 | ||
## [v1.0.0](https://github.com/inspect-js/is-descriptor/compare/v0.1.7...v1.0.0) - 2017-02-25 | ||
## [v0.1.7](https://github.com/inspect-js/is-descriptor/compare/v0.1.6...v0.1.7) - 2023-10-26 | ||
### Merged | ||
- Update dependencies [`#5`](https://github.com/inspect-js/is-descriptor/pull/5) | ||
### Commits | ||
- [eslint] actually use eslint [`8bcf028`](https://github.com/inspect-js/is-descriptor/commit/8bcf0288c53c80297e6109f7632dab9b7b7fb5c5) | ||
- [meta] update package.json, gitignore from main [`544cdfe`](https://github.com/inspect-js/is-descriptor/commit/544cdfe60f5a4db8aa1b02de93b326271fa82ec1) | ||
- [readme] update readme from main [`1130f79`](https://github.com/inspect-js/is-descriptor/commit/1130f79112bd1d36ca5b0806a4ad14ae9427e0e9) | ||
- [Tests] switch to tape [`3f8f094`](https://github.com/inspect-js/is-descriptor/commit/3f8f0947049e4f2d631f88f0374e2b4a4e058577) | ||
- [Docs] remove verb [`92ee1bf`](https://github.com/inspect-js/is-descriptor/commit/92ee1bfcc56ba2cd30503c87af8e8cd795fdca51) | ||
- [Tests] migrate from travis to github actions [`8da3a3c`](https://github.com/inspect-js/is-descriptor/commit/8da3a3c38d50b4e9e18865efd25c6d35f98852b6) | ||
- run update, lint [`754cc73`](https://github.com/inspect-js/is-descriptor/commit/754cc7382bd439f8e8b91775479c59c7c996cd47) | ||
- [Fix] a descriptor with `set` and not `get` is still an accessor descriptor [`269fb53`](https://github.com/inspect-js/is-descriptor/commit/269fb5374659a8c07aac88993b13d94197e9cbed) | ||
- [patch] switch from `files` to `exports` [`41b2d61`](https://github.com/inspect-js/is-descriptor/commit/41b2d6152438119120b8d24ff98ebfb79cb19007) | ||
- [Fix] allow any non-primitive; arrays and functions are objects too [`9fd1ac8`](https://github.com/inspect-js/is-descriptor/commit/9fd1ac80cd42600510dc76de74da9a3834c4358d) | ||
- update deps [`2b58af6`](https://github.com/inspect-js/is-descriptor/commit/2b58af6426d0700607419b096766829aff27f642) | ||
- [Deps] update `is-accessor-descriptor`, `is-data-descriptor` [`f4dbc73`](https://github.com/inspect-js/is-descriptor/commit/f4dbc7327e9df005d3d6130af2ea612426a45081) | ||
- 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) | ||
- [Tests] make a test dir [`9eaa17c`](https://github.com/inspect-js/is-descriptor/commit/9eaa17c3cbcd545d9409ab8d83dcd8bd0c42e739) | ||
## [v0.1.6](https://github.com/inspect-js/is-descriptor/compare/v0.1.5...v0.1.6) - 2017-07-22 | ||
@@ -56,0 +116,0 @@ |
58
index.js
'use strict'; | ||
var gOPD = require('gopd'); | ||
var hasOwn = require('hasown'); | ||
var isDataDescriptor = require('is-data-descriptor'); | ||
var isAccessorDescriptor = require('is-accessor-descriptor'); | ||
var isObject = function (val) { | ||
@@ -7,14 +12,2 @@ return val !== null && typeof val === 'object'; | ||
function isDataDesc(keys) { | ||
return keys.every(function (k) { | ||
return k === 'configurable' || k === 'enumerable' || k === 'get' || k === 'set'; | ||
}); | ||
} | ||
function isAccessorDesc(keys) { | ||
return keys.every(function (k) { | ||
return k === 'configurable' || k === 'enumerable' || k === 'writable' || k === 'value'; | ||
}); | ||
} | ||
module.exports = function isDescriptor(obj, key, checkProto) { | ||
@@ -24,11 +17,24 @@ if (!isObject(obj)) { | ||
} | ||
var desc = arguments.length > 1 ? Object.getOwnPropertyDescriptor(obj, key) : obj; | ||
if (!desc && arguments.length > 1 && checkProto !== false && obj.constructor) { | ||
desc = Object.getOwnPropertyDescriptor(obj.constructor.prototype, key); | ||
var desc; | ||
if (arguments.length > 1) { | ||
if (gOPD) { | ||
desc = gOPD(obj, key); | ||
if (desc) { | ||
return isDescriptor(desc); | ||
} | ||
return checkProto !== false | ||
&& obj.contructor | ||
&& isDescriptor(gOPD(obj.constructor.prototype, key)); | ||
} | ||
if (hasOwn(obj, key)) { | ||
return true; | ||
} | ||
if (checkProto !== false && obj.constructor) { | ||
return hasOwn(obj.constructor.prototype, key); | ||
} | ||
return false; | ||
} | ||
desc = obj; | ||
if (!isObject(desc)) { | ||
return false; | ||
} | ||
if (typeof desc.configurable !== 'boolean' || typeof desc.enumerable !== 'boolean') { | ||
@@ -38,17 +44,3 @@ return false; | ||
var keys = Object.keys(desc); | ||
if (isDataDesc(keys)) { | ||
if (typeof desc.get !== 'function' && desc.get !== void 0) { | ||
return false; | ||
} | ||
if (typeof desc.set !== 'function' && desc.set !== void 0) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
if (isAccessorDesc(keys)) { | ||
return typeof desc.writable === 'boolean'; | ||
} | ||
return false; | ||
return isDataDescriptor(desc) || isAccessorDescriptor(desc); | ||
}; |
{ | ||
"name": "is-descriptor", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.", | ||
@@ -14,2 +14,3 @@ "main": "index.js", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"prelint-disabled": "evalmd README.md # https://github.com/reggi/evalmd/issues/27", | ||
"lint": "eslint --ext=js,mjs .", | ||
@@ -20,3 +21,2 @@ "pretest": "npm run lint", | ||
"posttest": "aud --production", | ||
"prelint-disabled": "evalmd README.md", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
@@ -54,9 +54,15 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
"contributors": [ | ||
"(https://github.com/wtgtybhertgeghgtwtg)", | ||
"Brian Woodward (https://twitter.com/doowb)", | ||
"Jon Schlinkert (https://twitter.com/jonschlinkert)" | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)", | ||
"(https://github.com/wtgtybhertgeghgtwtg)" | ||
], | ||
"dependencies": { | ||
"gopd": "^1.0.1", | ||
"hasown": "^2.0.0", | ||
"is-accessor-descriptor": "^3.0.5", | ||
"is-data-descriptor": "^2.1.3" | ||
}, | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.1", | ||
"aud": "^2.0.2", | ||
"@ljharb/eslint-config": "^21.1.0", | ||
"aud": "^2.0.3", | ||
"auto-changelog": "^2.4.0", | ||
@@ -69,6 +75,6 @@ "eslint": "=8.8.0", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.6.3" | ||
"tape": "^5.7.2" | ||
}, | ||
"engines": { | ||
"node": ">=0.4" | ||
"node": ">= 0.4" | ||
}, | ||
@@ -75,0 +81,0 @@ "auto-changelog": { |
@@ -29,4 +29,3 @@ # is-descriptor <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
```js | ||
const obj = {}; | ||
obj.foo = null; | ||
const obj = { foo: 'abc' }; | ||
@@ -36,5 +35,5 @@ Object.defineProperty(obj, 'bar', { value: 'xyz' }); | ||
assert.ok(isDescriptor(obj, 'foo')); | ||
assert.ok(isDescriptor(obj, 'bar')); | ||
assert.ok(isDescriptor(obj, 'baz')); | ||
assert.equal(isDescriptor(obj, 'foo'), true); | ||
assert.equal(isDescriptor(obj, 'bar'), true); | ||
assert.equal(isDescriptor(obj, 'baz'), true); | ||
``` | ||
@@ -49,5 +48,5 @@ | ||
```js | ||
assert.ok(!isDescriptor('a')); | ||
assert.ok(!isDescriptor(null)); | ||
assert.ok(!isDescriptor([])); | ||
assert.equal(isDescriptor('a'), false); | ||
assert.equal(isDescriptor(null), false); | ||
assert.equal(isDescriptor([]), false); | ||
``` | ||
@@ -60,4 +59,4 @@ | ||
```js | ||
assert.ok(isDescriptor({ ...dataDefaults, value: 'foo' })); | ||
assert.ok(isDescriptor({ ...dataDefaults, value() {} })); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo' }), true); | ||
assert.equal(isDescriptor({ ...dataDefaults, value() {} }), true); | ||
``` | ||
@@ -68,6 +67,8 @@ | ||
```js | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' })); | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' })); | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', get() {} })); | ||
assert.ok(!isDescriptor({ ...dataDefaults, get() {}, value() {} })); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', get() {} }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, get() {}, value() {} }), false); | ||
``` | ||
@@ -78,5 +79,5 @@ | ||
```js | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'foo'})); | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'foo'})); | ||
assert.ok(!isDescriptor({ ...dataDefaults, value: 'foo', writable: 'foo'})); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'foo' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'foo' }), false); | ||
assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', writable: 'foo' }), false); | ||
``` | ||
@@ -89,5 +90,5 @@ | ||
```js | ||
assert.ok(isDescriptor({ ...defaults, get() {}, set() {} })); | ||
assert.ok(isDescriptor({ ...defaults, get() {} })); | ||
assert.ok(isDescriptor({ ...defaults, set() {} })); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, set() {} }), true); | ||
assert.equal(isDescriptor({ ...defaults, get() {} }), true); | ||
assert.equal(isDescriptor({ ...defaults, set() {} }), true); | ||
``` | ||
@@ -98,5 +99,6 @@ | ||
```js | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, set() {}, bar: 'baz' })); | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, writable: true })); | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, value: true })); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, bar: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, writable: true }), false); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, value: true }), false); | ||
``` | ||
@@ -107,6 +109,6 @@ | ||
```js | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, set: 'baz' })); | ||
assert.ok(!isDescriptor({ ...defaults, get: 'foo', set() {} })); | ||
assert.ok(!isDescriptor({ ...defaults, get: 'foo', bar: 'baz' })); | ||
assert.ok(!isDescriptor({ ...defaults, get: 'foo', set: 'baz' })); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, set: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...defaults, get: 'foo', set() {} }), false); | ||
assert.equal(isDescriptor({ ...defaults, get: 'foo', bar: 'baz' }), false); | ||
assert.equal(isDescriptor({ ...defaults, get: 'foo', set: 'baz' }), false); | ||
``` | ||
@@ -117,5 +119,5 @@ | ||
```js | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'foo' })); | ||
assert.ok(!isDescriptor({ ...defaults, set() {}, configurable: 'foo' })); | ||
assert.ok(!isDescriptor({ ...defaults, get() {}, configurable: 'foo' })); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'foo' }), false); | ||
assert.equal(isDescriptor({ ...defaults, set() {}, configurable: 'foo' }), false); | ||
assert.equal(isDescriptor({ ...defaults, get() {}, configurable: 'foo' }), false); | ||
``` | ||
@@ -122,0 +124,0 @@ |
@@ -5,6 +5,6 @@ 'use strict'; | ||
var isDescriptor = require('../'); | ||
function noop() {} | ||
var noop = function () {}; | ||
test('isDescriptor', function (t) { | ||
t.test('value type: is false when not an object', function (st) { | ||
t.test('is false when not an object:', function (st) { | ||
st.notOk(isDescriptor('a')); | ||
@@ -109,5 +109,6 @@ st.notOk(isDescriptor(null)); | ||
st.test('is false when "get" is not a function', function (s2t) { | ||
s2t.notOk(isDescriptor({ set: noop })); | ||
s2t.notOk(isDescriptor({ get: 'foo' })); | ||
st.test('is false when "get" or "set" is not a function', function (s2t) { | ||
s2t.notOk(isDescriptor({ enumerable: true, configurable: true, set: noop })); | ||
s2t.notOk(isDescriptor({ enumerable: true, configurable: true, get: 'foo' })); | ||
s2t.notOk(isDescriptor({ enumerable: true, configurable: true, set: 'foo' })); | ||
@@ -137,3 +138,5 @@ s2t.end(); | ||
}); | ||
st.end(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27862
141
0
4
141
+ Addedgopd@^1.0.1
+ Addedhasown@^2.0.0
+ Addedis-data-descriptor@^2.1.3
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-accessor-descriptor@3.0.5(transitive)
+ Addedis-data-descriptor@2.1.3(transitive)