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

Function clone

src/utils.ts:182–204  ·  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

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

Callers 2

_resolveObjectOptionFunction · 0.85
_parseConfigFunction · 0.85

Calls 1

cleanArrayFunction · 0.85

Tested by

no test coverage detected