Adds a value by a string path, with '.' as a the default delimiter Automatically generates intermediate nodes.

const root = addValueByPath({}, 'c');
addValueByPath({x:'blah'}, 'c.users.admin', root);

Creates the structure:

c          value: { }            label: c
+ users value: undefined label: users
+ admin value: { x: 'blah' } label: admin

By default, multiple values under same key are overwritten, with the most recent winning.

  • Type Parameters

    • T

    Parameters

    • value: T
    • path: string
    • Optionalnode: LabelledNode<T>
    • pathOpts: Partial<Readonly<{
          duplicates: "ignore" | "allow" | "overwrite";
          separator: string;
      }>> = {}

    Returns LabelledNode<T>