Function safeSet
-
safeSet(
data: object,
path: PropertyPath,
value: any,
options?: {
createMissing?: boolean;
operation?: "add" | "set" | "div" | "sub" | "mult" | "set-undefined";
},
): booleanParameters
- data: object
An object to access entry data.
- path: PropertyPath
A dotted string path or an array of exact string, number, or symbol property keys.
The string keys
__proto__,prototype, andconstructorare rejected to prevent prototype-pollution access paths. ECMAScript well-known symbols, such asSymbol.toStringTag,Symbol.iterator, andSymbol.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 path is found.
Optionaloptions: {
createMissing?: boolean;
operation?: "add" | "set" | "div" | "sub" | "mult" | "set-undefined";
}Options.
-
OptionalcreateMissing?: booleanIf
truemissing path entries will be created as objects automatically; default:false. -
Optionaloperation?: "add" | "set" | "div" | "sub" | "mult" | "set-undefined"Operation to perform including:
add,div,mult,set,set-undefined,sub; default:set.
-
Returns boolean
True if successful.
- data: object
Provides a way to safely set an object's data / entries using either a dotted path string or an array of exact property keys. Array indexes may only be accessed by number through the array property-key form.