* Shallow clone an object * * @param object - The object to be cloned. * @returns A new object that copies the original.
(object: T)
| 180 | * @returns A new object that copies the original. |
| 181 | */ |
| 182 | function 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 |
no test coverage detected