mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-07 08:39:56 +00:00
Switch cloneObject to objectClone
Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
e639b7e931
commit
bfdb6d598d
@ -76,12 +76,21 @@ export function objectSort<T = Record<string, any>>(
|
|||||||
/**
|
/**
|
||||||
* Deeply clone an object
|
* Deeply clone an object
|
||||||
* @param obj the object to clone
|
* @param obj the object to clone
|
||||||
|
* @deprecated Replace with objectClone
|
||||||
*/
|
*/
|
||||||
export function cloneObject<T = Record<string, any>>(obj: T): T {
|
export function cloneObject<T = Record<string, any>>(obj: T): T {
|
||||||
|
return objectClone(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deeply clone an object
|
||||||
|
* @param obj the object to clone
|
||||||
|
*/
|
||||||
|
export function objectClone<T = Record<string, any>>(obj: T): T {
|
||||||
const clone: Partial<T> = {}
|
const clone: Partial<T> = {}
|
||||||
objectLoop(obj, (value, key) => {
|
objectLoop(obj, (value, key) => {
|
||||||
if (typeof value === 'object' && value != null) {
|
if (typeof value === 'object' && value != null) {
|
||||||
clone[key as Extract<keyof T, string>] = cloneObject(value)
|
clone[key as Extract<keyof T, string>] = objectClone(value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
clone[key as Extract<keyof T, string>] = value
|
clone[key as Extract<keyof T, string>] = value
|
||||||
@ -158,6 +167,7 @@ export default {
|
|||||||
objectSize,
|
objectSize,
|
||||||
objectSort,
|
objectSort,
|
||||||
cloneObject,
|
cloneObject,
|
||||||
|
objectClone,
|
||||||
objectSet,
|
objectSet,
|
||||||
objectEqual
|
objectEqual
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user