Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
is-accessor-descriptor
Advanced tools
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
The is-accessor-descriptor npm package is used to check if an object property descriptor defines an accessor descriptor. An accessor descriptor is one that includes getter and/or setter functions, as opposed to a data descriptor which contains a value and is writable.
Check if a descriptor is an accessor descriptor
This feature allows you to verify if a given property descriptor from an object is an accessor descriptor. It returns true if the descriptor has a get or set key, and false otherwise.
{"isAccessorDescriptor": require('is-accessor-descriptor');
var descriptor = Object.getOwnPropertyDescriptor({get foo() {}}, 'foo');
console.log(isAccessorDescriptor(descriptor)); //=> true
}
Check if an object is an accessor descriptor
This feature allows you to check if a plain object mimics the structure of an accessor descriptor. It is useful for validation purposes when you have an object that should represent a descriptor and you want to ensure it is an accessor descriptor.
{"isAccessorDescriptor": require('is-accessor-descriptor');
console.log(isAccessorDescriptor({get: function() {}})); //=> true
console.log(isAccessorDescriptor({set: function() {}})); //=> true
console.log(isAccessorDescriptor({value: 123})); //=> false
}
This package is similar to is-accessor-descriptor but checks for data descriptors instead. A data descriptor is an object with a value property and optionally writable, enumerable, and configurable properties. It is the counterpart to is-accessor-descriptor, which checks for accessor descriptors.
is-descriptor is a more general package that checks if an object is a valid property descriptor, which can be either a data descriptor or an accessor descriptor. It is a superset of is-accessor-descriptor and is-data-descriptor functionalities.
While not specifically for checking descriptors, is-plain-object can be used to determine if an object is plain (i.e., created by the Object constructor or one with a null prototype). This can be a preliminary check before further validation as a descriptor.
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
const isAccessorDescriptor = require('is-accessor-descriptor');
const assert = require('assert');
const obj = {
get foo() {},
bar: { get: function() {} }
};
assert.equal(true, isAccessorDescriptor(obj, 'foo'));
assert.equal(false, isAccessorDescriptor(obj, 'bar'));
// or, if you already have the descriptor you can pass it directly
const foo = Object.getOwnPropertyDescriptor(obj, 'foo');
assert.equal(true, isAccessorDescriptor(foo));
const bar = Object.getOwnPropertyDescriptor(obj, 'bar');
assert.equal(false, isAccessorDescriptor(bar));
You might also be interested in these projects:
Simply clone the repo, npm install
, and run npm test
FAQs
Returns true if a value has the characteristics of a valid JavaScript accessor descriptor.
The npm package is-accessor-descriptor receives a total of 42,078,691 weekly downloads. As such, is-accessor-descriptor popularity was classified as popular.
We found that is-accessor-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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.