mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 15:10:23 +00:00
fix/build-nobelium
This commit is contained in:
26
lib/utils.js
26
lib/utils.js
@@ -112,24 +112,32 @@ export function isIterable(obj) {
|
|||||||
return obj != null && typeof obj[Symbol.iterator] === 'function'
|
return obj != null && typeof obj[Symbol.iterator] === 'function'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 深拷贝对象
|
||||||
|
* 根据源对象类型深度复制,支持object和array
|
||||||
|
* @param {*} obj
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export function deepClone(obj) {
|
export function deepClone(obj) {
|
||||||
const newObj = Array.isArray(obj) ? [] : {}
|
if (Array.isArray(obj)) {
|
||||||
if (obj && typeof obj === 'object') {
|
// If obj is an array, create a new array and deep clone each element
|
||||||
|
return obj.map(item => deepClone(item))
|
||||||
|
} else if (obj && typeof obj === 'object') {
|
||||||
|
const newObj = {}
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
if (obj[key] instanceof Date) { // 判断属性值是否为 Date 对象
|
if (obj[key] instanceof Date) {
|
||||||
newObj[key] = new Date(obj[key].getTime()).toISOString() // 直接拷贝引用
|
newObj[key] = new Date(obj[key].getTime()).toISOString()
|
||||||
} else if (obj[key] && typeof obj[key] === 'object') {
|
|
||||||
newObj[key] = deepClone(obj[key])
|
|
||||||
} else {
|
} else {
|
||||||
newObj[key] = obj[key]
|
newObj[key] = deepClone(obj[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return newObj
|
||||||
|
} else {
|
||||||
|
return obj
|
||||||
}
|
}
|
||||||
return newObj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延时
|
* 延时
|
||||||
* @param {*} ms
|
* @param {*} ms
|
||||||
|
|||||||
Reference in New Issue
Block a user