Options
All
  • Public
  • Public/Protected
  • All
Menu

@ricokahler/jsonmatch-patch

Index

Type aliases

InsertOptions

InsertOptions: { input: unknown; items: unknown[] } & OperationEntryObject

Functions

dec

  • Given an input object and a record of path expressions to numeric values, this function will decrement each match with the given value.

    const output = dec({
    input: { foo: { first: 3, second: 4.5 } },
    pathExpressionValues: {
    'foo.*': 3,
    },
    });

    // { foo: { first: 0, second: 1.5 } }
    console.log(output);

    Type parameters

    • R

    Parameters

    Returns R

getDeep

  • Gets a value deep inside of an object given a path. If the path does not exist in the object, undefined will be returned

    Type parameters

    • R

    Parameters

    Returns R

inc

  • 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);

    Type parameters

    • R

    Parameters

    Returns R

insert

  • 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);
    • ```js // prepend const output = insert({ input: { some: { array: ['a', 'b', 'c'] } }, before: 'some.array[0]', items: ['!'], });

    // { 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);

    Type parameters

    • R

    Parameters

    Returns R

match

  • Given an object as input and an path expression, this returns a list of JSONMatchEntryies.

    See here for a full list of supported syntax.

    Parameters

    Returns JSONMatchEntry[]

set

  • 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);

    Type parameters

    • R

    Parameters

    Returns R

setDeep

  • 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

    Type parameters

    • R

    Parameters

    Returns R

setIfMissing

  • 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);

    Type parameters

    • R

    Parameters

    Returns R

unset

  • 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);

    Type parameters

    • R

    Parameters

    Returns R

unsetDeep

  • Given an object and an exact path as an array, this unsets the value at the given path.

    Type parameters

    • R

    Parameters

    Returns R

Generated using TypeDoc