forked from github/fast-deep-copy
完成ts类型描述
This commit is contained in:
parent
7dddf109f9
commit
d8b31b430b
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;
|
1
dist/deep-copy.js
vendored
1
dist/deep-copy.js
vendored
@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.deepCopy = void 0;
|
||||||
/** from https://github.com/vuejs/vuex/blob/dev/src/util.js
|
/** from https://github.com/vuejs/vuex/blob/dev/src/util.js
|
||||||
* Get the first item that pass the test
|
* Get the first item that pass the test
|
||||||
* by second argument function
|
* by second argument function
|
||||||
|
2
dist/deep-copy.js.map
vendored
2
dist/deep-copy.js.map
vendored
@ -1 +1 @@
|
|||||||
{"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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AAK,GAAG,EAAlB,CAAkB,CAAC,CAAC;IACjD,IAAI,GAAG,EAAE;QACL,OAAO,GAAG,CAAC,IAAI,CAAC;KACnB;IAED,IAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,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,OAAU,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 {};
|
2
dist/test.js
vendored
2
dist/test.js
vendored
@ -5,7 +5,7 @@ var a = { dataA: 10, b: null };
|
|||||||
var b = { dataB: 20, a: null };
|
var b = { dataB: 20, a: null };
|
||||||
a.b = b;
|
a.b = b;
|
||||||
b.a = a;
|
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.dataA === 10); //true
|
||||||
console.log(newA.b.dataB === 20); //true
|
console.log(newA.b.dataB === 20); //true
|
||||||
console.log(newA.b.a === newA); //true
|
console.log(newA.b.a === newA); //true
|
||||||
|
2
dist/test.js.map
vendored
2
dist/test.js.map
vendored
@ -1 +1 @@
|
|||||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,yCAAuC;AAEvC,IAAI,CAAC,GAAG,E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AM"}
|
4
index.d.ts
vendored
4
index.d.ts
vendored
@ -1,4 +0,0 @@
|
|||||||
declare module 'fast-deep-copy-ts' {
|
|
||||||
const deepCopy: <T>(obj: T, cache: any[]) => T;
|
|
||||||
export = deepCopy;
|
|
||||||
}
|
|
37
package-lock.json
generated
Normal file
37
package-lock.json
generated
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"name": "fast-deep-copy-ts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "fast-deep-copy-ts",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^4.9.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "4.9.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
||||||
|
"integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.2.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"typescript": {
|
||||||
|
"version": "4.9.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
||||||
|
"integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
package.json
10
package.json
@ -3,14 +3,15 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "20 lines code! Deep copy the given object considering circular structure",
|
"description": "20 lines code! Deep copy the given object considering circular structure",
|
||||||
"main": "dist/deep-copy.js",
|
"main": "dist/deep-copy.js",
|
||||||
"types": "index.d.ts",
|
"types": "dist/deep-copy.d.ts",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"fast-deep-copy",
|
"fast-deep-copy",
|
||||||
"deep-copy",
|
"deep-copy",
|
||||||
"deepcopy"
|
"deepcopy"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node dist/test.js"
|
"prepublish": "npm run build",
|
||||||
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"author": "625335512@qq.com",
|
"author": "625335512@qq.com",
|
||||||
"homepage": "https://github.com/zhaolihang/fast-deep-copy",
|
"homepage": "https://github.com/zhaolihang/fast-deep-copy",
|
||||||
@ -18,5 +19,8 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/zhaolihang/fast-deep-copy.git"
|
"url": "git+https://github.com/zhaolihang/fast-deep-copy.git"
|
||||||
},
|
},
|
||||||
"license": "ISC"
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^4.9.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"allowJs":true,
|
"allowJs":true, // 指定模块化类型
|
||||||
|
"declaration": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user