Function safeSet

    • Provides a way to safely set an object's data / entries using either a dotted accessor string or an array of exact property keys. Array indexes may only be accessed by number through the array accessor form.

      Parameters

      • data: object

        An object to access entry data.

      • accessor: SafeAccessor

        A dotted string accessor or an array of exact string, number, or symbol property keys.

        The string keys __proto__, prototype, and constructor are rejected to prevent prototype-pollution access paths. ECMAScript well-known symbols, such as Symbol.toStringTag, Symbol.iterator, and Symbol.toPrimitive, are also rejected because they modify built-in language protocols and object behavior. User-created symbols and symbols from Symbol.for remain valid.

      • value: any

        A new value to set if an entry for accessor is found.

      • Optionaloptions: {
            createMissing?: boolean;
            operation?: "add" | "div" | "mult" | "set" | "set-undefined" | "sub";
        }

        Options.

        • OptionalcreateMissing?: boolean

          If true missing accessor entries will be created as objects automatically; default: false.

        • Optionaloperation?: "add" | "div" | "mult" | "set" | "set-undefined" | "sub"

          Operation to perform including: add, div, mult, set, set-undefined, sub; default: set.

      Returns boolean

      True if successful.