define-properties
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
define-data-property | 1.1.4 | 30.13 kB | MIT | prod | |
has-property-descriptors | 1.0.2 | 10.66 kB | MIT | prod | |
object-keys | 1.1.1 | 7.5 kB | MIT | prod |
The Define Properties npm package allows users to define multiple non-enumerable properties simultaneously. It utilizes the Object.defineProperty
where it is available and falls back to standard assignment in engines that are older and do not have the Object.defineProperty
feature. Moreover, existing properties are not overridden unless a map of property names is provided to a predicate that, when true, force-overrides.
You can use the Define Properties package by first importing it to your project using the require function, like this: var define = require('define-properties');
. After importing it, you use it to define properties of an object. Here's an example:
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2 }, {
a: 10,
b: 20,
c: 30
});
In the above example, the properties a
and b
won't be overridden, and a new property c
is added with the value 30
.
You can also use predicates to define when to override existing properties. The example below demonstrates this:
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2, c: 3 }, {
a: 10,
b: 20,
c: 30
}, {
a: function () { return false; },
b: function () { return true; }
});
In the above code, a predicate is used to determine whether to override the properties a
and b
. The property a
is set not to override (a: function () { return false; }
), with property b
is set to override (b: function () { return true; }
).
The documentation for the Define Properties package is provided in the README file in the package's repository on GitHub. The link to the repository is git://github.com/ljharb/define-properties.git. The README file contains everything you need to know to use this package.