import {transform} from "apprt-core/clone";
const input = { x: 1, c: {a: 1} };
const copyOfInput = transform(input);
import {transform} from "apprt-core/clone";
const input = { x: 1, c: {a: 1} };
const transformedCopy = transform(input, (value, ctx)=> {
if (ctx.path[ctx.path.length-1]==="c")){
// value is { a: 1 }
// change c to be a number
return value.a;
}
return value;
});
// -> transformedCopy === { x: 1, c: 1 }
Generated using TypeDoc
This method creates a clone of the given value. and allows customization of the value by a valueTransformer function.
By default this works only for flat objects and not for objects which are instances of classes. But a
valueTransformer
is able to transform input classes to target classes or keep them as is.