@asins/deep-clone
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -1,58 +0,54 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.deepClone = factory()); | ||
})(this, (function () { 'use strict'; | ||
'use strict'; | ||
/** | ||
* 对象的深度拷贝 | ||
* 克隆所有JSON类型:Object Array Number String null | ||
* 附加支持:Date (复制) undefined (复制) | ||
* @param {Object|Array} o 待深度复制的对象 | ||
*/ | ||
function clone(o) { | ||
if (typeof o !== 'object' || o === null) | ||
return o; | ||
if (o instanceof Date) | ||
return new Date(o); | ||
if (Array.isArray(o)) | ||
return cloneArray(o, clone); | ||
const o2 = {}; | ||
for (const k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
const cur = o[k]; | ||
if (typeof cur !== 'object' || cur === null) { | ||
o2[k] = cur; | ||
} | ||
else if (cur instanceof Date) { | ||
o2[k] = new Date(cur); | ||
} | ||
else { | ||
o2[k] = clone(cur); | ||
} | ||
} | ||
return o2; | ||
} | ||
function cloneArray(a, fn) { | ||
const keys = Object.keys(a); | ||
const a2 = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const k = keys[i]; | ||
const cur = a[k]; | ||
if (typeof cur !== 'object' || cur === null) { | ||
a2[k] = cur; | ||
} | ||
else if (cur instanceof Date) { | ||
a2[k] = new Date(cur); | ||
} | ||
else { | ||
a2[k] = fn(cur); | ||
} | ||
} | ||
return a2; | ||
} | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return clone; | ||
/** | ||
* 对象的深度拷贝 | ||
* 克隆所有JSON类型:Object Array Number String null | ||
* 附加支持:Date (复制) undefined (复制) | ||
* @param {Object|Array} o 待深度复制的对象 | ||
*/ | ||
function clone(o) { | ||
if (typeof o !== 'object' || o === null) | ||
return o; | ||
if (o instanceof Date) | ||
return new Date(o); | ||
if (Array.isArray(o)) | ||
return cloneArray(o, clone); | ||
const o2 = {}; | ||
for (const k in o) { | ||
if (Object.hasOwnProperty.call(o, k) === false) | ||
continue; | ||
const cur = o[k]; | ||
if (typeof cur !== 'object' || cur === null) { | ||
o2[k] = cur; | ||
} | ||
else if (cur instanceof Date) { | ||
o2[k] = new Date(cur); | ||
} | ||
else { | ||
o2[k] = clone(cur); | ||
} | ||
} | ||
return o2; | ||
} | ||
function cloneArray(a, fn) { | ||
const keys = Object.keys(a); | ||
const a2 = new Array(keys.length); | ||
for (let i = 0; i < keys.length; i++) { | ||
const k = keys[i]; | ||
const cur = a[k]; | ||
if (typeof cur !== 'object' || cur === null) { | ||
a2[k] = cur; | ||
} | ||
else if (cur instanceof Date) { | ||
a2[k] = new Date(cur); | ||
} | ||
else { | ||
a2[k] = fn(cur); | ||
} | ||
} | ||
return a2; | ||
} | ||
})); | ||
exports["default"] = clone; |
{ | ||
"name": "@asins/deep-clone", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "对象深度拷贝", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"typings": "src/index.d.ts", | ||
"typings": "dist/index.d.ts", | ||
"dependencies": {}, | ||
@@ -9,0 +9,0 @@ "devDependencies": { |
@@ -37,4 +37,3 @@ import typescript from 'rollup-plugin-typescript2'; | ||
output: [ | ||
{ file: './dist/index.js', format: 'umd', name: 'deepClone' }, | ||
{ file: './dist/index.cjs.js', format: 'cjs', exports: 'auto' }, | ||
{ file: './dist/index.js', format: 'cjs', exports: 'named' }, | ||
{ file: './dist/index.esm.js', format: 'es' }, | ||
@@ -41,0 +40,0 @@ ], |
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
8
207
7071