Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asins/deep-clone

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asins/deep-clone - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

index.d.ts

106

dist/index.js

@@ -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 @@ ],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc