mirror of
https://github.com/zhaolihang/fast-deep-copy.git
synced 2025-04-29 06:20:10 +08:00
add types
This commit is contained in:
parent
1666647ae7
commit
7b8a85e788
10
dist/deep-copy.d.ts
vendored
Normal file
10
dist/deep-copy.d.ts
vendored
Normal file
@ -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<Object>} cache
|
||||
* @return {*}
|
||||
*/
|
||||
export declare function deepCopy<T>(obj: T, cache?: any[]): T;
|
2
dist/deep-copy.js
vendored
2
dist/deep-copy.js
vendored
@ -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
|
1
dist/deep-copy.js.map
vendored
1
dist/deep-copy.js.map
vendored
@ -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"}
|
1
dist/test.d.ts
vendored
Normal file
1
dist/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {};
|
3
dist/test.js
vendored
3
dist/test.js
vendored
@ -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
|
1
dist/test.js.map
vendored
1
dist/test.js.map
vendored
@ -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"}
|
@ -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",
|
||||
|
@ -1,5 +1,6 @@
|
||||
# fast-deep-copy
|
||||
Only 20 lines code! no deps!
|
||||
It can correctly handle circular references!
|
||||
|
||||
## Useage:
|
||||
```
|
||||
|
15
tsconfig.desc.json
Normal file
15
tsconfig.desc.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"compileOnSave": true,
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"sourceMap": false,
|
||||
"declaration": true,
|
||||
"allowJs": true,
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
{
|
||||
"compileOnSave": true,
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"sourceMap": true,
|
||||
"allowJs":true,
|
||||
"sourceMap": false,
|
||||
"allowJs": true,
|
||||
"moduleResolution": "node",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user