Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
Installations
npm install is-descriptor
Developer Guide
Typescript
No
Module System
CommonJS, ESM
Min. Node Version
>= 0.4
Node Version
21.0.0
NPM Version
10.2.0
Score
99.2
Supply Chain
100
Quality
78.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
inspect-js
Download Statistics
Total Downloads
11,927,211,590
Last Day
6,890,970
Last Week
36,868,609
Last Month
136,718,411
Last Year
2,221,947,444
GitHub Statistics
12 Stars
67 Commits
4 Forks
4 Watching
3 Branches
5 Contributors
Bundle Size
12.25 kB
Minified
3.62 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.1.1
Package Id
is-descriptor@3.1.1
Unpacked Size
27.21 kB
Size
7.42 kB
File Count
11
NPM Version
10.2.0
Node Version
21.0.0
Publised On
28 Oct 2023
Total Downloads
Cumulative downloads
Total Downloads
11,927,211,590
Last day
-7.2%
6,890,970
Compared to previous day
Last week
0.5%
36,868,609
Compared to previous week
Last month
-28%
136,718,411
Compared to previous month
Last year
-9.8%
2,221,947,444
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
is-descriptor
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for fully completed data descriptors and accessor descriptors.
Usage
1const isDescriptor = require('is-descriptor'); 2const assert = require('assert'); 3 4const defaults = { configurable: false, enumerable: false }; 5const dataDefaults = { ...defaults, writable: false}; 6 7assert.ok(isDescriptor({ ...dataDefaults, value: 'foo' })); 8assert.ok(isDescriptor({ ...defaults, get() {}, set() {} })); 9assert.ok(!isDescriptor({ ...defaults, get: 'foo', set() {} }));
You may also check for a descriptor by passing an object as the first argument and property name (string
) as the second argument.
1const obj = { foo: 'abc' };
2
3Object.defineProperty(obj, 'bar', { value: 'xyz' });
4Reflect.defineProperty(obj, 'baz', { value: 'xyz' });
5
6assert.equal(isDescriptor(obj, 'foo'), true);
7assert.equal(isDescriptor(obj, 'bar'), true);
8assert.equal(isDescriptor(obj, 'baz'), true);
Examples
value type
Returns false
when not an object
1assert.equal(isDescriptor('a'), false);
2assert.equal(isDescriptor(null), false);
3assert.equal(isDescriptor([]), false);
data descriptor
Returns true
when the object has valid properties with valid values.
1assert.equal(isDescriptor({ ...dataDefaults, value: 'foo' }), true);
2assert.equal(isDescriptor({ ...dataDefaults, value() {} }), true);
Returns false
when the object has invalid properties
1assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false);
2assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', bar: 'baz' }), false);
3assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'baz' }), false);
4assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'baz' }), false);
5assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', get() {} }), false);
6assert.equal(isDescriptor({ ...dataDefaults, get() {}, value() {} }), false);
false
when a value is not the correct type
1assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', enumerable: 'foo' }), false);
2assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', configurable: 'foo' }), false);
3assert.equal(isDescriptor({ ...dataDefaults, value: 'foo', writable: 'foo' }), false);
accessor descriptor
true
when the object has valid properties with valid values.
1assert.equal(isDescriptor({ ...defaults, get() {}, set() {} }), true); 2assert.equal(isDescriptor({ ...defaults, get() {} }), true); 3assert.equal(isDescriptor({ ...defaults, set() {} }), true);
false
when the object has invalid properties
1assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, bar: 'baz' }), false); 2assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'baz' }), false); 3assert.equal(isDescriptor({ ...defaults, get() {}, writable: true }), false); 4assert.equal(isDescriptor({ ...defaults, get() {}, value: true }), false);
Returns false
when an accessor is not a function
1assert.equal(isDescriptor({ ...defaults, get() {}, set: 'baz' }), false);
2assert.equal(isDescriptor({ ...defaults, get: 'foo', set() {} }), false);
3assert.equal(isDescriptor({ ...defaults, get: 'foo', bar: 'baz' }), false);
4assert.equal(isDescriptor({ ...defaults, get: 'foo', set: 'baz' }), false);
Returns false
when a value is not the correct type
1assert.equal(isDescriptor({ ...defaults, get() {}, set() {}, enumerable: 'foo' }), false); 2assert.equal(isDescriptor({ ...defaults, set() {}, configurable: 'foo' }), false); 3assert.equal(isDescriptor({ ...defaults, get() {}, configurable: 'foo' }), false);
Related projects
You might also be interested in these projects:
- is-accessor-descriptor: Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
- is-data-descriptor: Returns true if a value has the characteristics of a valid JavaScript data descriptor.
- is-object: Returns true if the value is an object and not an array or null.
Tests
Simply clone the repo, npm install
, and run npm test
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/inspect-js/.github/SECURITY.md:1
- Info: Found linked content: github.com/inspect-js/.github/SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: github.com/inspect-js/.github/SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/require-allow-edits.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/inspect-js/is-descriptor/require-allow-edits.yml/main?enable=pin
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node-aught.yml:1
- Warn: no topLevel permission defined: .github/workflows/node-pretest.yml:1
- Warn: no topLevel permission defined: .github/workflows/node-tens.yml:1
- Warn: no topLevel permission defined: .github/workflows/rebase.yml:1
- Warn: no topLevel permission defined: .github/workflows/require-allow-edits.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to is-descriptor
is-accessor-descriptor
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
is-data-descriptor
Returns true if a value has the characteristics of a valid JavaScript data descriptor.
@types/is-data-descriptor
TypeScript definitions for is-data-descriptor
is-media-descriptor
Is given string a valid media descriptor (including media query)?