#define-prop
###Easy and type safe custom object property define
- object descriptors in a space seperated string for fast inline value creation
- deep freezes non-writable object values
- doesn't throw, but logs on invalid input
- supports custom log so you can throw yourself if needed
- dynamically type checked
###Usage:
<object> defineProperty( <object> obj, <string>/<number> key, <any type> value, <string> descriptorNames )
Default, the enumerable, configurable and writable descriptor values are set to false, which is the default behaviour of Object.defineProperty. You can set them individually to true by passing their names as last arguments or in a space seperated string.
var defineProp= require( 'define-prop' );
var obj= {};
defineProp( obj, 'hello', 'world!', 'enumerable' );
obj.hello= 'cannot be set..';
console.log( obj );
defineProp( obj, 'count', ( () => {
var count= 0;
return {
get: () => count
,set: ( value ) => count= value
};
})(), 'enumerable' );
obj.count++;
console.log( obj.count );
defineProp( obj, 'protected', {
notWritable : 'this is a frozen object'
,test : true
}, 'enumerable' );
obj.protected.cannotAssign = 'when "writable" is not set';
obj.protected.test = 'futile';
console.log( obj );
defineProp.log= ( err ) => {
};
change log
--
0.0.5
- adds support for making object values deeply immutable if descriptor is not set to 'writable'
- adds optional input error logging (default on)
--
0.0.4
- adds support for defining a non-getter/setter object
--
0.0.3
--
###license
MIT