set-recursive
v1.2.1
Published
Set recursive properties on object
Downloads
6
Maintainers
Readme
setRecursive
Set recursive properties on object
Usage: setRecursive<T extends Object>(on: T, to: { [key: string]: any }, whenExist?: boolean): T
import { setRecursive } from 'set-recursive'
const person = {
id: 1,
name: 'john',
metadata: {
personId: 1,
goodParson: true,
family: {
personId: 1,
sister: 'lola'
}
}
}
const propsToSet = { id: 2, personId: 2 }
setRecursive(person, propsToSet)
// Output: {
// id: 2,
// name: 'john',
// metadata: {
// personId: 2,
// goodParson: true,
// family: {
// personId: 2,
// sister: 'lola'
// }
// }
// }
setRecursive(person, propsToSet, false) // This will set the given properties even if they not exist initially
// Output: {
// id: 2,
// personId: 2,
// name: 'john',
// metadata: {
// personId: 2,
// id: 2,
// goodParson: true,
// family: {
// personId: 2,
// id: 2,
// sister: 'lola'
// }
// }
This module exported from utilizes project.