Optional
walker: (el: any, keyPath: string[], stage?: "before" | "after") => anyOptional
after?: booleanIf true, run walker on the value after attempting to loop through it's keys. If save is true, this can be used to modify the final value.
Optional
before?: booleanIf true, run walker on the value before attempting to loop through it's keys. If save is true, this can be used to modify the object that will be looped over.
Optional
save?: TSaveIf true, will "save" the result of the walker, allowing it to be used for deep map/cloning of objects. By "save" we mean, the return value of the walker will be assigned to the property (if it does not return undefined) and walk will return the modified clone. Using save will change the return type to any since otherwise it is impossible to type. You can use the second type parameter to set it manually.
Recursively walks through an object or array (and also technically
null
too if you force it).Save can used to save the return of the callback (if no callback is given it just returns the value), and deep clone objects.
As well as more complicated operations that can preserve certain keys (such as in the case of Error instances or other such objects.)
In the above scenerio, if not using save and we just want to modify the object directly, we could do
{before:true}
and use aMap<keypathAsString, val>
to keep a list of keys to modify. Then after (to avoid interfering with the walk) we loop through those keys in reverse (to get deepest keys first, to avoid conflicts) then mutate those keypaths using {@link set}.