* Shallow clone an object * * @param object - The object to be cloned. * @returns A new object that copies the original.
(object: T)
| 169 | * @returns A new object that copies the original. |
| 170 | */ |
| 171 | function 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. |
no test coverage detected
searching dependent graphs…