mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +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'
|
||||
}
|
||||
|
||||
/**
|
||||
* 深拷贝对象
|
||||
* 根据源对象类型深度复制,支持object和array
|
||||
* @param {*} obj
|
||||
* @returns
|
||||
*/
|
||||
export function deepClone(obj) {
|
||||
const newObj = Array.isArray(obj) ? [] : {}
|
||||
if (obj && typeof obj === 'object') {
|
||||
if (Array.isArray(obj)) {
|
||||
// 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) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
if (obj[key] instanceof Date) { // 判断属性值是否为 Date 对象
|
||||
newObj[key] = new Date(obj[key].getTime()).toISOString() // 直接拷贝引用
|
||||
} else if (obj[key] && typeof obj[key] === 'object') {
|
||||
newObj[key] = deepClone(obj[key])
|
||||
if (obj[key] instanceof Date) {
|
||||
newObj[key] = new Date(obj[key].getTime()).toISOString()
|
||||
} else {
|
||||
newObj[key] = obj[key]
|
||||
newObj[key] = deepClone(obj[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
return newObj
|
||||
} else {
|
||||
return obj
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
/**
|
||||
* 延时
|
||||
* @param {*} ms
|
||||
|
||||
Reference in New Issue
Block a user