diff --git a/package.json b/package.json index 0bffc8a9ef..184a5d0721 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "codesandbox": "^2.2.3", "ajv": "^8.11.0", "ajv-formats": "^2.1.1", - "extend": "^3.0.2", + "rfdc": "^1.3.0", "file-saver": "^2.0.5", "ng-github-button": "^14.0.0", "ng-zorro-antd": "^14.0.0-beta.0", @@ -117,8 +117,6 @@ "karma-viewport": "^1.0.9", "@types/aos": "^3.0.4", "@types/file-saver": "^2.0.5", - "@types/deep-extend": "^0.4.32", - "@types/extend": "^3.0.1", "@types/fs-extra": "^9.0.13", "@types/mockjs": "^1.0.6", "@types/parse5": "^6.0.3", diff --git a/packages/util/other/deep.spec.ts b/packages/util/other/deep.spec.ts index 5aafc3a17f..d2bf0f82ef 100644 --- a/packages/util/other/deep.spec.ts +++ b/packages/util/other/deep.spec.ts @@ -52,9 +52,18 @@ describe('abc: utils', () => { }); }); - it('#deepCopy', () => { - const a = { number: 1 }; - expect(deepCopy(a).number).toBe(a.number); + describe('#deepCopy', () => { + it('should be working', () => { + const a = { number: 1 }; + expect(deepCopy(a).number).toBe(a.number); + }); + it('when is null', () => { + expect(deepCopy(null)).toBe(null); + }); + it('when proto is false', () => { + const res = deepCopy(Object.create({ a: 1 }), { proto: false }); + expect(Object.keys(res).length).toBe(0); + }); }); describe('#deepMerge', () => { diff --git a/packages/util/other/deep.ts b/packages/util/other/deep.ts index 6edd949e5d..2a2a73ebf2 100644 --- a/packages/util/other/deep.ts +++ b/packages/util/other/deep.ts @@ -1,4 +1,4 @@ -import extend from 'extend'; +import rfdc from 'rfdc'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; @@ -21,13 +21,22 @@ export function deepGet(obj: NzSafeAny, path: string | string[] | null | undefin } /** - * Base on [extend](https://github.com/justmoon/node-extend) deep copy. + * Base on [rfdc](https://github.com/davidmarkclements/rfdc) deep copy. * - * 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝 + * 基于 [rfdc](https://github.com/davidmarkclements/rfdc) 的深度拷贝 */ -export function deepCopy(obj: T | null | undefined): T { - const result = extend(true, {}, { _: obj }); - return result._ as T; +export function deepCopy(obj: T | null | undefined): T; +/** + * Base on [rfdc](https://github.com/davidmarkclements/rfdc) deep copy. + * + * 基于 [rfdc](https://github.com/davidmarkclements/rfdc) 的深度拷贝 + * + * - [options](https://github.com/davidmarkclements/rfdc#requirerfdcopts---proto-false-circles-false---cloneobj--obj2) 参数文档 + */ +export function deepCopy(obj: T | null | undefined, options?: rfdc.Options): T; +export function deepCopy(obj: T | null | undefined, options?: rfdc.Options): T { + if (obj == null) return obj as T; + return rfdc(options)(obj); } /** diff --git a/packages/util/other/index.en-US.md b/packages/util/other/index.en-US.md index 64b2fd5eb6..a5b9a58932 100644 --- a/packages/util/other/index.en-US.md +++ b/packages/util/other/index.en-US.md @@ -23,7 +23,7 @@ deepGet(obj, 'user.age'); // 18 ## deepCopy -Base on [extend](https://github.com/justmoon/node-extend) deep copy. +Base on [rfdc](https://github.com/davidmarkclements/rfdc) deep copy. ```ts const source = { a: 1, user: { name: 'cipchk' } }; diff --git a/packages/util/other/index.zh-CN.md b/packages/util/other/index.zh-CN.md index 02e50bd179..897175576b 100644 --- a/packages/util/other/index.zh-CN.md +++ b/packages/util/other/index.zh-CN.md @@ -23,7 +23,7 @@ deepGet(obj, 'user.age'); // 18 ## deepCopy -基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝。 +基于 [rfdc](https://github.com/davidmarkclements/rfdc) 的深度拷贝。 ```ts const source = { a: 1, user: { name: 'cipchk' } }; diff --git a/scripts/site/route-paths.txt b/scripts/site/route-paths.txt index f4390cc87d..358d0cb3e3 100644 --- a/scripts/site/route-paths.txt +++ b/scripts/site/route-paths.txt @@ -95,8 +95,6 @@ /components/global-footer/zh /components/highlight/en /components/highlight/zh -/components/image/en -/components/image/zh /components/let/en /components/let/zh /components/loading/en