Example:
import { clone } from "@thalesrc/js-utils/object";
const object = {
width: 250,
element: document.querySelector("div")
};
function divCloner(objectToClone, options, internalData) {
const newElement = document.createElement("div");
newElement.classList.add("cloned");
return newElement;
}
const customCloners = new Map();
customCloners.set(HTMLDivElement, divCloner);
const clonedObject = clone(object);
Give the instance constructors to prevent them being cloned
Example:
import { clone } from "@thalesrc/js-utils/object";
const object = {
width: 250,
element: document.querySelector("div")
};
const clonedObject = clone(object, {instancesToRefer: [ HTMLElement ]});
// clonedObject.element === object.element
Give the unwanted properties to prevent them being cloned
Example:
import { clone } from "@thalesrc/js-utils/object";
const object = {
width: 250,
element: document.querySelector("div")
};
const clonedObject = clone(object, {propsToRefer: [ "element" ]});
// clonedObject.element === object.element
Being called for each value while cloning. Return true to prevent cloning for the incoming value and pass the same reference instead.
Example:
import { clone } from "@thalesrc/js-utils/object";
const john = { age: 20, willBeReferenced: true };
const jane = { age: 25, willBeReferenced: false };
const array = [john, jane];
const clonedArray = clone(array, {valueFiltererToRefer: person => person.willBeReferenced });
// clonedArray[0] === array[0]
// clonedArray[1] !== array[1]
incoming value to be cloned
Return true to pass same reference, false to clone
Generated using TypeDoc
Cloning Options
Cloning options of the clone function