Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
is-descriptor
Advanced tools
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
The is-descriptor npm package is used for checking if an object is a valid descriptor. Descriptors are objects that define the behavior of properties on JavaScript objects, such as whether they are writable, enumerable, or configurable, and they can also specify getter and setter functions. This package is useful for validation in libraries that manipulate object properties and descriptors, ensuring that operations like defining new properties or modifying existing ones are performed with valid descriptor objects.
Checking property descriptors
This feature allows you to check if a given object is a valid property descriptor. The code sample demonstrates checking various objects to see if they qualify as descriptors based on their properties.
const isDescriptor = require('is-descriptor');
console.log(isDescriptor({enumerable: false, configurable: true})); // true
console.log(isDescriptor({value: 'hello'})); // true
console.log(isDescriptor({get: function() {}})); // true
console.log(isDescriptor({set: undefined})); // false
This package checks specifically for data descriptors, which are a type of property descriptor focusing on value properties rather than accessor properties (getters and setters). It's more specific compared to is-descriptor, which checks for both data and accessor descriptors.
Similar to is-data-descriptor, this package focuses on checking for accessor descriptors, which define getter and setter functions for a property. It complements is-data-descriptor by covering the other main type of property descriptor, offering a more focused approach compared to the broader checks performed by is-descriptor.
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
Install with npm
$ npm i is-descriptor --save
var isDescriptor = require('is-descriptor');
isDescriptor({value: 'foo'})
//=> true
isDescriptor({get: function(){}, set: function(){}})
//=> true
isDescriptor({get: 'foo', set: function(){}})
//=> false
false
when not an object
isDescriptor('a'))
//=> false
isDescriptor(null))
//=> false
isDescriptor([]))
//=> false
true
when the object has valid properties with valid values.
isDescriptor({value: 'foo'}))
//=> true
isDescriptor({value: noop}))
//=> true
false
when the object has invalid properties
isDescriptor({value: 'foo', bar: 'baz'}))
//=> false
isDescriptor({value: 'foo', bar: 'baz'}))
//=> false
isDescriptor({value: 'foo', get: noop}))
//=> false
isDescriptor({get: noop, value: noop}))
//=> false
false
when a value is not the correct type
isDescriptor({value: 'foo', enumerable: 'foo'}))
//=> false
isDescriptor({value: 'foo', configurable: 'foo'}))
//=> false
isDescriptor({value: 'foo', writable: 'foo'}))
//=> false
true
when the object has valid properties with valid values.
isDescriptor({get: noop, set: noop}))
//=> true
isDescriptor({get: noop}))
//=> true
isDescriptor({set: noop}))
//=> true
false
when the object has invalid properties
isDescriptor({get: noop, set: noop, bar: 'baz'}))
//=> false
isDescriptor({get: noop, writable: true}))
//=> false
isDescriptor({get: noop, value: true}))
//=> false
false
when an accessor is not a function
isDescriptor({get: noop, set: 'baz'}))
//=> false
isDescriptor({get: 'foo', set: noop}))
//=> false
isDescriptor({get: 'foo', bar: 'baz'}))
//=> false
isDescriptor({get: 'foo', set: 'baz'}))
//=> false
false
when a value is not the correct type
isDescriptor({get: noop, set: noop, enumerable: 'foo'}))
//=> false
isDescriptor({set: noop, configurable: 'foo'}))
//=> false
isDescriptor({get: noop, configurable: 'foo'}))
//=> false
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on October 04, 2015.
FAQs
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
The npm package is-descriptor receives a total of 17,216,366 weekly downloads. As such, is-descriptor popularity was classified as popular.
We found that is-descriptor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.