@asins/deep-clone
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -8,27 +8,39 @@ /** | ||
function clone(o) { | ||
let res; | ||
if (typeof o !== 'object' || o === null) | ||
return o; | ||
// @ts-ignore Date类型转为T类型 | ||
if (o instanceof Date) | ||
return new Date(o); | ||
if (Array.isArray(o)) { | ||
const keys = Object.keys(o); | ||
const a2 = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const k = keys[i]; | ||
a2[k] = clone(o[k]); | ||
res = o; | ||
else if (o instanceof Date) | ||
res = new Date(o); | ||
else if (Array.isArray(o)) | ||
res = cloneArray(o, clone); | ||
else if (o instanceof Map) | ||
res = new Map(cloneArray(Array.from(o), clone)); | ||
else if (o instanceof Set) | ||
res = new Set(cloneArray(Array.from(o), clone)); | ||
else if (ArrayBuffer.isView(o)) | ||
res = o.slice(0); | ||
else if (o instanceof Element) | ||
res = o; | ||
else { | ||
res = {}; | ||
for (var k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
// @ts-ignore Object类型转为T类型 | ||
res[k] = clone(o[k]); | ||
} | ||
// @ts-ignore Array类型转为T类型 | ||
return a2; | ||
} | ||
const o2 = {}; | ||
for (const k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
// @ts-ignore Object类型转为T类型 | ||
o2[k] = clone(o[k]); | ||
return res; | ||
} | ||
function cloneArray(a, fn) { | ||
var keys = Object.keys(a); | ||
var a2 = new Array(keys.length); | ||
for (var i = 0; i < keys.length; i++) { | ||
var k = keys[i]; | ||
a2[k] = fn(a[k]); | ||
} | ||
return o2; | ||
// @ts-ignore Array类型转为T类型 | ||
return a2; | ||
} | ||
export { clone as default }; |
@@ -12,27 +12,39 @@ 'use strict'; | ||
function clone(o) { | ||
let res; | ||
if (typeof o !== 'object' || o === null) | ||
return o; | ||
// @ts-ignore Date类型转为T类型 | ||
if (o instanceof Date) | ||
return new Date(o); | ||
if (Array.isArray(o)) { | ||
const keys = Object.keys(o); | ||
const a2 = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const k = keys[i]; | ||
a2[k] = clone(o[k]); | ||
res = o; | ||
else if (o instanceof Date) | ||
res = new Date(o); | ||
else if (Array.isArray(o)) | ||
res = cloneArray(o, clone); | ||
else if (o instanceof Map) | ||
res = new Map(cloneArray(Array.from(o), clone)); | ||
else if (o instanceof Set) | ||
res = new Set(cloneArray(Array.from(o), clone)); | ||
else if (ArrayBuffer.isView(o)) | ||
res = o.slice(0); | ||
else if (o instanceof Element) | ||
res = o; | ||
else { | ||
res = {}; | ||
for (var k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
// @ts-ignore Object类型转为T类型 | ||
res[k] = clone(o[k]); | ||
} | ||
// @ts-ignore Array类型转为T类型 | ||
return a2; | ||
} | ||
const o2 = {}; | ||
for (const k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
// @ts-ignore Object类型转为T类型 | ||
o2[k] = clone(o[k]); | ||
return res; | ||
} | ||
function cloneArray(a, fn) { | ||
var keys = Object.keys(a); | ||
var a2 = new Array(keys.length); | ||
for (var i = 0; i < keys.length; i++) { | ||
var k = keys[i]; | ||
a2[k] = fn(a[k]); | ||
} | ||
return o2; | ||
// @ts-ignore Array类型转为T类型 | ||
return a2; | ||
} | ||
exports["default"] = clone; |
{ | ||
"name": "@asins/deep-clone", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "对象深度拷贝", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10348
280