diff --git a/dist/deep-copy.d.ts b/dist/deep-copy.d.ts new file mode 100644 index 0000000..45c26a1 --- /dev/null +++ b/dist/deep-copy.d.ts @@ -0,0 +1,10 @@ +/** + * Deep copy the given object considering circular structure. + * This function caches all nested objects and its copies. + * If it detects circular structure, use cached copy to avoid infinite loop. + * + * @param {*} obj + * @param {Array} cache + * @return {*} + */ +export declare function deepCopy(obj: T, cache?: any[]): T; diff --git a/dist/deep-copy.js b/dist/deep-copy.js index d770708..4d0abb6 100644 --- a/dist/deep-copy.js +++ b/dist/deep-copy.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.deepCopy = void 0; /** from https://github.com/vuejs/vuex/blob/dev/src/util.js * Get the first item that pass the test * by second argument function @@ -41,4 +42,3 @@ function deepCopy(obj, cache) { return copy; } exports.deepCopy = deepCopy; -//# sourceMappingURL=deep-copy.js.map \ No newline at end of file diff --git a/dist/deep-copy.js.map b/dist/deep-copy.js.map deleted file mode 100644 index 92e5367..0000000 --- a/dist/deep-copy.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"deep-copy.js","sourceRoot":"","sources":["../src/deep-copy.ts"],"names":[],"mappings":";;AAAA;;;;;;;GAOG;AACH,cAAc,IAAI,EAAE,CAAC;IACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;GAQG;AACH,kBAA4B,GAAM,EAAE,KAAU;IAAV,sBAAA,EAAA,UAAU;IAC1C,wCAAwC;IACxC,EAAE,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC;IACf,CAAC;IAED,6CAA6C;IAC7C,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,QAAQ,KAAK,GAAG,EAAlB,CAAkB,CAAC,CAAC;IACjD,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACN,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;IACpB,CAAC;IAED,IAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;IAC1C,mCAAmC;IACnC,oDAAoD;IACpD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;IAEpC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,MAAM,CAAI,IAAI,CAAC;AACnB,CAAC;AAtBD,4BAsBC"} \ No newline at end of file diff --git a/dist/test.d.ts b/dist/test.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/test.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/test.js b/dist/test.js index 7723e34..ff6c3a1 100644 --- a/dist/test.js +++ b/dist/test.js @@ -5,8 +5,7 @@ var a = { dataA: 10, b: null }; var b = { dataB: 20, a: null }; a.b = b; b.a = a; -var newA = deep_copy_1.deepCopy(a); +var newA = (0, deep_copy_1.deepCopy)(a); console.log(newA.dataA === 10); //true console.log(newA.b.dataB === 20); //true console.log(newA.b.a === newA); //true -//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/dist/test.js.map b/dist/test.js.map deleted file mode 100644 index 2437fbb..0000000 --- a/dist/test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,yCAAuC;AAEvC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;AAC/B,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACR,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAER,IAAI,IAAI,GAAG,oBAAQ,CAAC,CAAC,CAAC,CAAC;AACvB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAK,MAAM;AAC1C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAG,MAAM;AAC1C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAK,MAAM"} \ No newline at end of file diff --git a/package.json b/package.json index fee89d2..bce8645 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,18 @@ { "name": "fast-deep-copy", - "version": "1.0.0", + "version": "1.0.1", "description": "20 lines code! Deep copy the given object considering circular structure", "main": "dist/deep-copy.js", + "types": "dist/deep-copy.d.ts", "keywords": [ "fast-deep-copy", "deep-copy", "deepcopy" ], "scripts": { - "test": "node dist/test.js" + "test": "node dist/test.js", + "build": "tsc", + "desc": "tsc --project ./tsconfig.desc.json" }, "author": "625335512@qq.com", "homepage": "https://github.com/zhaolihang/fast-deep-copy", diff --git a/readme.md b/readme.md index afc6ae1..f023e4b 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ # fast-deep-copy Only 20 lines code! no deps! + It can correctly handle circular references! ## Useage: ``` diff --git a/tsconfig.desc.json b/tsconfig.desc.json new file mode 100644 index 0000000..6a51567 --- /dev/null +++ b/tsconfig.desc.json @@ -0,0 +1,15 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "sourceMap": false, + "declaration": true, + "allowJs": true, + "moduleResolution": "node", + "outDir": "dist" + }, + "include": [ + "src/**/*" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7a83bd5..21e8176 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,14 @@ - { - "compileOnSave": true, - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "sourceMap": true, - "allowJs":true, - "moduleResolution": "node", - "outDir": "dist" - }, - "include": [ - "src/**/*" - ] - } \ No newline at end of file +{ + "compileOnSave": true, + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "sourceMap": false, + "allowJs": true, + "moduleResolution": "node", + "outDir": "dist" + }, + "include": [ + "src/**/*" + ] +} \ No newline at end of file