Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
is-descriptor
Advanced tools
Package description
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.
Readme
Returns true if a value has the characteristics of a valid JavaScript descriptor. Works for data descriptors and accessor descriptors.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save is-descriptor
const isDescriptor = require('is-descriptor');
isDescriptor({ value: 'foo' })
//=> true
isDescriptor({ get: function() {}, set: function() {} })
//=> true
isDescriptor({ get: 'foo', set: function() {} })
//=> false
You may also check for a descriptor by passing an object as the first argument and property name (string
) as the second argument.
const obj = {};
obj.foo = null;
Object.defineProperty(obj, 'bar', { value: 'xyz' });
Reflect.defineProperty(obj, 'baz', { value: 'xyz' });
isDescriptor(obj, 'foo'); //=> true
isDescriptor(obj, 'bar'); //=> true
isDescriptor(obj, 'baz'); //=> true
Returns false
when not an object
isDescriptor('a'); //=> false
isDescriptor(null); //=> false
isDescriptor([]); //=> false
Returns true
when the object has valid properties with valid values.
isDescriptor({ value: 'foo' }); //=> true
isDescriptor({ value: function() {} }); //=> true
Returns false
when the object has invalid properties
isDescriptor({ value: 'foo', bar: 'baz' }); //=> false
isDescriptor({ value: 'foo', bar: 'baz' }); //=> false
isDescriptor({ value: 'foo', get: function() {} }); //=> false
isDescriptor({ get: function() {}, value: function() {} }); //=> 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: function() {}, set: function() {} }); //=> true
isDescriptor({ get: function() {} }); //=> true
isDescriptor({ set: function() {} }); //=> true
false
when the object has invalid properties
isDescriptor({ get: function() {}, set: function() {}, bar: 'baz' }); //=> false
isDescriptor({ get: function() {}, writable: true }); //=> false
isDescriptor({ get: function() {}, value: true }); //=> false
Returns false
when an accessor is not a function
isDescriptor({ get: function() {}, set: 'baz' }); //=> false
isDescriptor({ get: 'foo', set: function() {} }); //=> false
isDescriptor({ get: 'foo', bar: 'baz' }); //=> false
isDescriptor({ get: 'foo', set: 'baz' }); //=> false
Returns false
when a value is not the correct type
isDescriptor({ get: function() {}, set: function() {}, enumerable: 'foo' }); //=> false
isDescriptor({ set: function() {}, configurable: 'foo' }); //=> false
isDescriptor({ get: function() {}, configurable: 'foo' }); //=> false
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Commits | Contributor |
---|---|
33 | jonschlinkert |
1 | doowb |
1 | realityking |
1 | wtgtybhertgeghgtwtg |
Jon Schlinkert
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on December 13, 2018.
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 42,065,766 weekly downloads. As such, is-descriptor popularity was classified as popular.
We found that is-descriptor demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.