Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
define-properties
Advanced tools
Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.
The define-properties npm package is used to define new properties on an object, including any necessary descriptors. It provides a simple API to define multiple properties at once while ensuring compatibility with older JavaScript engines that may not fully support ES5.
Defining multiple properties
This feature allows you to define multiple properties on an object with their descriptors. The 'enumerable' predicate ensures that the property will only be defined if the value is truthy.
{"object": {}, "properties": {"prop1": {"value": 42, "enumerable": true}, "prop2": {"value": 'hello', "enumerable": false}}, "predicates": {"enumerable": function(val) { return !!val; }}}
Defining properties with shared descriptors
This feature allows you to define properties with a shared descriptor. The predicate function can be used to conditionally define properties based on the key or value.
{"object": {}, "propertyNames": ["prop1", "prop2"], "descriptor": {"enumerable": true}, "predicate": function(key, value) { return key === 'prop1' || value > 10; }}
This package provides a similar functionality to define-properties by allowing you to define a new property directly on an object. It is a polyfill for Object.defineProperty and is useful for ensuring compatibility with older JavaScript engines.
es5-ext is a collection of ECMAScript 5 extensions, including various shims and polyfills. It offers a broader set of functionalities compared to define-properties, which includes defining properties but also other utilities for working with objects, arrays, and functions.
Define multiple non-enumerable properties at once. Uses Object.defineProperty
when available; falls back to standard assignment in older engines.
Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides.
var define = require('define-properties');
var assert = require('assert');
var obj = define({ a: 1, b: 2 }, {
a: 10,
b: 20,
c: 30
});
assert(obj.a === 1);
assert(obj.b === 2);
assert(obj.c === 30);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'b']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'c'), {
configurable: true,
enumerable: false,
value: 30,
writable: false
});
}
Then, with predicates:
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; }
});
assert(obj.a === 1);
assert(obj.b === 20);
assert(obj.c === 3);
if (define.supportsDescriptors) {
assert.deepEqual(Object.keys(obj), ['a', 'c']);
assert.deepEqual(Object.getOwnPropertyDescriptor(obj, 'b'), {
configurable: true,
enumerable: false,
value: 20,
writable: false
});
}
Simply clone the repo, npm install
, and run npm test
v1.2.0 - 2023-02-10
true
, it compares the existing value with ===
as the predicate d8dd6fc
auto-changelog
7ebe2b0
npmignore
to autogenerate an npmignore file 647478a
@ljharb/eslint-config
, aud
, tape
e620d70
aud
, tape
f1e5072
628b3af
has-property-descriptors
object-keys
prepublishOnly
script for npm 7+funding
field; create FUNDING.ymlnode/install
instead of node/run
; use codecov
actionnyc
on all tests; use tape
runnernpx aud
instead of nsp
or npm audit
with hoopsjscs
eslint
, @ljharb/eslint-config
, safe-publish-latest
, tape
; add aud
, safe-publish-latest
foreach
to make for smaller bundle sizesArray.prototype.concat
and Object.defineProperty
object-keys
eslint
, @ljharb/eslint-config
, nsp
, tape
, jscs
; remove unused eccheck script + depobject-keys
jscs
, tape
, eslint
, @ljharb/eslint-config
, nsp
io.js
v3.3
, node
v4.2
object-keys
tape
, eslint
io.js
v2.4
nsp
, eslint
io.js
v2.3
io.js
v2.0
tape
, jscs
, nsp
, eslint
, object-keys
, editorconfig-tools
, covert
object-keys
to fix ES3 supportFAQs
Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.
The npm package define-properties receives a total of 31,795,983 weekly downloads. As such, define-properties popularity was classified as popular.
We found that define-properties 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.