
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
describe-property
Advanced tools
describe-property is a property descriptor library that runs in both node.js and the browser. You use it to quickly generate property descriptors to use with Object.create
, Object.defineProperty
, and/or Object.defineProperties
.
var d = require('describe-property');
function Person(firstName, surname) {
this.firstName = firstName;
this.surname = surname;
}
Object.defineProperties(Person.prototype, {
// Methods can be passed directly.
sayHi: d(function () {
console.log('Hello, my name is', this.fullName);
}),
// Getters are defined using d.gs.
fullName: d.gs(function () {
return this.firstName + ' ' + this.surname;
}),
// Setters are defined as the second argument to d.gs.
firstName: d.gs(function () {
return this._firstName;
}, function (value) {
this._firstName = value.trim();
})
});
By default property descriptors use ES5 attributes.
{
configurable: true,
enumerable: false,
writable: true
}
But any of these can be overridden using an object literal.
d({
enumerable: true,
value: function () {
// ...
}
}); // => { configurable: true, enumerable: true, writable: true, value: function () {} }
Using npm:
$ npm install describe-property
Please file issues on the issue tracker on GitHub.
To run the tests in node:
$ npm install
$ npm test
This library was inspired by @medikoo's excellent d library. It is intended to be a lighter-weight alternative with fewer features, but also only a single dependency.
FAQs
Define JavaScript object properties quickly with ES5 defaults
The npm package describe-property receives a total of 3,651 weekly downloads. As such, describe-property popularity was classified as popular.
We found that describe-property demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.