random-object-utils
v0.1.1
Published
Node.js library for managing objects.
Downloads
3
Readme
Objects
Collection of random utilities useful to manage Node.js objects.
How to use
getNestedValue
getNestedValue( object: any, ...keys: string[] )
const Objects = require( 'random-object-utils' );
let obj = {
a: {
b: {
c: {
d: 'd',
e: 'e'
}
}
}
};
console.log( Objects.getNestedValue( obj, 'a', 'b', 'c', 'e' ) );
// prints 'e'
setNestedValue
setNestedValue( object: any, value: any, ...keys: string[] )
const Objects = require( 'random-object-utils' );
let obj = {
a: {
b: {
c: {
d: 'd',
e: 'e'
}
}
}
};
Objects.setNestedValue( obj, 'f', 'a', 'b', 'c', 'e' );
console.log( Objects.getNestedValue( obj, 'a', 'b', 'c', 'e' ) );
// prints 'f'
deepExtend
deepExtend( ...sources: any[] )
const Objects = require( 'random-object-utils' );
let obj1 = {
a: {
b: {
c: {
d: 'd',
e: 'e'
}
}
}
};
let obj2 = {
a: {
b: false,
c: {
z: 'yes'
}
}
};
let res = Objects.deepExtend( obj1, obj2 );
console.log( Objects.getNestedValue( obj, 'a', 'c', 'z' ) );
// prints 'yes'