Gets a value deep inside of an object given a path. If the path does not
exist in the object, undefined
will be returned
Given an input object and a record of path expressions to numeric values, this function will increment each match with the given value.
const output = inc({
input: { foo: { first: 3, second: 4.5 } },
pathExpressionValues: {
'foo.*': 3,
},
});
// { foo: { first: 6, second: 7.5 } }
console.log(output);
Given an input object, a path expression, and an array of items, this function will either insert or replace the matched items.
// insert before
const output = insert({
input: { some: { array: ['a', 'b', 'c'] } },
before: 'some.array[2]',
items: ['!'],
});
// { some: { array: ['a', 'b', 'c', '!'] } }
console.log(output);
// append
const output = insert({
input: { some: { array: ['a', 'b', 'c'] } },
before: 'some.array[-1]', // negative index for add to the end
items: ['!'],
});
// { some: { array: ['a', 'b', 'c', '!'] } }
console.log(output);
// { some: { array: ['!', 'a', 'b', 'c'] } } console.log(output);
* * ```js
// replace
const output = insert({
input: { some: { array: ['a', 'b', 'c'] } },
replace: 'some.array[1]',
items: ['!'],
});
// { some: { array: ['a', '!', 'c'] } }
console.log(output);
Given an object as input and an path expression, this returns a list of
JSONMatchEntry
ies.
See here for a full list of supported syntax.
Given an input object and a record of path expressions to values, this function will set each match with the given value.
const output = set({
input: { name: { first: '', last: '' } },
pathExpressionValues: {
'name.*': 'changed',
},
});
// { name: { first: 'changed', second: 'changed' } }
console.log(output);
Sets a value deep inside of an object given a path. If the path does not exist in the object, it will be created if the path does not contain an array index
Given an input object and a record of path expressions to values, this
function will set each match with the given value if the value at the current
path is missing. A missing value is either null
or undefined
.
const output = setIfMissing({
input: { name: { first: 'same', last: null } },
pathExpressionValues: {
'name.*': 'changed',
},
});
// { name: { first: 'same', second: 'changed' } }
console.log(output);
Given an input object and an array of path expressions, this function will remove each match from the input object.
const output = unset({
input: { name: { first: 'one', last: 'two' } },
pathExpressions: ['name.*'],
});
// { name: { } }
console.log(output);
Given an object and an exact path as an array, this unsets the value at the given path.
Generated using TypeDoc
Given an input object and a record of path expressions to numeric values, this function will decrement each match with the given value.