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

Function clone

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

154 * @returns A new object that copies the original.
155 */
156function clone<T extends Record<string, any>>(object: T): T {
157 const newObject = create(null);
158
159 for (const [property, value] of entries(object)) {
160 const isPropertyExist = objectHasOwnProperty(object, property);
161
162 if (isPropertyExist) {
163 if (Array.isArray(value)) {
164 newObject[property] = cleanArray(value);
165 } else if (
166 value &&
167 typeof value === 'object' &&
168 value.constructor === Object
169 ) {
170 newObject[property] = clone(value);
171 } else {
172 newObject[property] = value;
173 }
174 }
175 }
176
177 return newObject;
178}
179
180/**
181 * This method automatically checks if the prop is function or getter and behaves accordingly.

Callers 1

_parseConfigFunction · 0.85

Calls 1

cleanArrayFunction · 0.85

Tested by

no test coverage detected