wishthis/node_modules/define-properties
2023-03-12 10:52:00 +01:00
..
.github Update dependencies 2022-05-29 11:24:36 +02:00
.editorconfig Add production dependencies 2022-01-21 09:28:41 +01:00
.eslintrc Update dependencies 2022-05-29 11:24:36 +02:00
.nycrc Update dependencies 2022-05-29 11:24:36 +02:00
CHANGELOG.md chore(dependency): update dependencies 2023-03-12 10:52:00 +01:00
index.js chore(dependency): update dependencies 2023-03-12 10:52:00 +01:00
LICENSE Add production dependencies 2022-01-21 09:28:41 +01:00
package.json chore(dependency): update dependencies 2023-03-12 10:52:00 +01:00
README.md Update dependencies 2022-05-29 11:24:36 +02:00

define-properties Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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.

Example

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
	});
}

Tests

Simply clone the repo, npm install, and run npm test