MCPcopy Create free account
hub / github.com/cure53/DOMPurify / clone

Function clone

src/utils.ts:177–199  ·  view source on GitHub ↗

* Shallow clone an object * * @param object - The object to be cloned. * @returns A new object that copies the original.

(object: T)

Source from the content-addressed store, hash-verified

175 * @returns A new object that copies the original.
176 */
177function clone<T extends Record<string, any>>(object: T): T {
178 const newObject = create(null);
179
180 for (const [property, value] of entries(object)) {
181 const isPropertyExist = objectHasOwnProperty(object, property);
182
183 if (isPropertyExist) {
184 if (arrayIsArray(value)) {
185 newObject[property] = cleanArray(value);
186 } else if (
187 value &&
188 typeof value === 'object' &&
189 value.constructor === Object
190 ) {
191 newObject[property] = clone(value);
192 } else {
193 newObject[property] = value;
194 }
195 }
196 }
197
198 return newObject;
199}
200
201/**
202 * Copy a flat lookup table

Callers 2

_resolveObjectOptionFunction · 0.85
_parseConfigFunction · 0.85

Calls 1

cleanArrayFunction · 0.85

Tested by

no test coverage detected