MCPcopy
hub / github.com/cure53/DOMPurify / clone

Function clone

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

169 * @returns A new object that copies the original.
170 */
171function clone<T extends Record<string, any>>(object: T): T {
172 const newObject = create(null);
173
174 for (const [property, value] of entries(object)) {
175 const isPropertyExist = objectHasOwnProperty(object, property);
176
177 if (isPropertyExist) {
178 if (arrayIsArray(value)) {
179 newObject[property] = cleanArray(value);
180 } else if (
181 value &&
182 typeof value === 'object' &&
183 value.constructor === Object
184 ) {
185 newObject[property] = clone(value);
186 } else {
187 newObject[property] = value;
188 }
189 }
190 }
191
192 return newObject;
193}
194
195/**
196 * Convert non-node values into strings without depending on direct property access.

Callers 3

_resolveSetOptionFunction · 0.85
_parseConfigFunction · 0.85
createDOMPurifyFunction · 0.85

Calls 1

cleanArrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…