1.2.1 • Published 8 months ago

define-properties v1.2.1

Weekly downloads
20,107,457
License
MIT
Repository
github
Last release
8 months ago

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

object.assignstring.prototype.trimendstring.prototype.trimstartutil.promisifyobject.getownpropertydescriptorsobject.valuesobject-isarray-includesregexp.prototype.flagsobject.entriesarray.prototype.flatobject.fromentriesarray.prototype.flatmapstring.prototype.matchallstring.prototype.trimleftstring.prototype.trimrightstring.prototype.padendfunction.prototype.nameis-nanarray.prototype.findarray.prototype.mappromise.allsettledpromise.prototype.finallyreflect.ownkeysstring.prototype.padstartstring.prototype.trimglobalthis@huyhpham/rn-linearchetype-librarycomponennentt@dinert/utilseasy-select-rnvuedragdropuploadimagesreact-native-bluetooth2killi8n-react-native-fast-imagepipihomern-send-smsspecify-importsbabel-specify-imports@icanpm/api-master@arisageha/react-lazyload@arisageha/react-lazyload-fix@cashremit/cr-streamline-icons@almeidaa/msreact-native-template-rfbasecloud-archive-s3airscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-module@frxf/frxf@phil8795/pecuniarius-apideneme323112@texttree/demo-bsa-reference-rcl@fundefund/funde_ck@ntt_app/react-native-custom-notificationreact-native-custom-text-hwjamesreact-native-covid-sdkgql_din_modafryxiconsreact-native-thanh-toast-librarymutasi-bca@jttechnic/interpreter@thanhnguyen14797/react-native-thanh-toast-library@l1nyanm1ng/react-picture-viewer@saeon/ol-react@saeon/quick-formcthpb-plugin-social@olivervorasai/sliderreact-native-printer-brothersrn-pdf-reader-offlinecbmis-ai-toolboxreact-native-shekhar-bridge-testasterjscogoportutilsuncoded-connectlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29wilscanner@khalitovadel/abstract-repository@oiti/documentoscopy-react-native@respondea/cordova-plugin-v-inappbrowser@mink-opn/build-tokensquoc-testreact-native-slider-kfone-index@prodam/prodam-typescclibyarntest@saaspe/componentsexpand-react-bridgeopea-bootstraapluminos-ui-core
1.2.1

8 months ago

1.2.0

1 year ago

1.1.4

2 years ago

1.1.3

6 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago