Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ICloneOptions

Cloning Options

Cloning options of the clone function

Hierarchy

  • ICloneOptions

Index

Properties

Optional customCloners

customCloners: Map<Function, TInstanceCloner>

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);

Optional instancesToRefer

instancesToRefer: any[]

Instance constructors which cloning unwanted

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

default

[]

Optional propsToRefer

propsToRefer: Array<any>

Properties which cloning unwanted

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

default

[]

Methods

Optional valueFiltererToRefer

  • valueFiltererToRefer(value: any): boolean
  • Value filterer to pass same references

    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]

    default

    () => false

    Parameters

    • value: any

      incoming value to be cloned

    Returns boolean

    Return true to pass same reference, false to clone

Generated using TypeDoc