From 3393707a2db1fecbb66eb8c1ffcffba9f55d9146 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sun, 1 Dec 2024 16:06:59 +0900 Subject: [PATCH] docs: Update docs for cloneDeepWith --- docs/ja/reference/object/cloneDeepWith.md | 2 +- docs/ko/reference/object/cloneDeepWith.md | 4 ++-- docs/reference/object/cloneDeepWith.md | 4 ++-- docs/zh_hans/reference/object/cloneDeepWith.md | 4 ++-- src/object/cloneDeepWith.ts | 17 +++++++++-------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/ja/reference/object/cloneDeepWith.md b/docs/ja/reference/object/cloneDeepWith.md index 804fe43ed..42c9cb441 100644 --- a/docs/ja/reference/object/cloneDeepWith.md +++ b/docs/ja/reference/object/cloneDeepWith.md @@ -16,7 +16,7 @@ function cloneDeepWith( ### パラメータ - `obj` (`T`): クローンするオブジェクト。 -- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any`): 値をクローンする方法を示す関数。デフォルトの方法を使用せずに値をクローンして返すことができます。`undefined`を返すと、デフォルトの方法で値がクローンされます。 +- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any`): 値をクローンする方法を示す関数。デフォルトの方法を使用せずに値をクローンして返すことができます。`undefined`を返すと、デフォルトの方法で値がクローンされます。 - `value`: 現在クローンされている値。 - `key`: 現在クローンされている値のプロパティ名。 - `obj`: クローンする全体のオブジェクト `obj`。 diff --git a/docs/ko/reference/object/cloneDeepWith.md b/docs/ko/reference/object/cloneDeepWith.md index 24b29e08c..a777be2f1 100644 --- a/docs/ko/reference/object/cloneDeepWith.md +++ b/docs/ko/reference/object/cloneDeepWith.md @@ -9,14 +9,14 @@ ```typescript function cloneDeepWith( obj: T, - cloneValue: (value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any + cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any ): T; ``` ### 파라미터 - `obj` (`T`): 복사할 객체. -- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any`): 값을 복사하는 방법을 나타내는 함수. 기본 방법을 사용하지 않고 값을 복사해서 반환할 수 있어요. `undefined`를 반환하면 기본 방법으로 값이 복사돼요. +- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any`): 값을 복사하는 방법을 나타내는 함수. 기본 방법을 사용하지 않고 값을 복사해서 반환할 수 있어요. `undefined`를 반환하면 기본 방법으로 값이 복사돼요. - `value`: 현재 복사되고 있는 값. - `key`: 현재 복사되고 있는 값에 대한 프로퍼티 이름. - `obj`: 복사할 전체 객체 `obj`. diff --git a/docs/reference/object/cloneDeepWith.md b/docs/reference/object/cloneDeepWith.md index fe0238683..80c8a1a84 100644 --- a/docs/reference/object/cloneDeepWith.md +++ b/docs/reference/object/cloneDeepWith.md @@ -9,14 +9,14 @@ You can customize the deep cloning process using the `cloneValue` function. The ```typescript function cloneDeepWith( obj: T, - cloneValue: (value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any + cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any ): T; ``` ### Parameters - `obj` (`T`): The object to clone. -- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any`): A function that specifies how to clone the value. It can return a cloned value instead of using the default method. If it returns `undefined`, the default method is used to clone the value. +- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any`): A function that specifies how to clone the value. It can return a cloned value instead of using the default method. If it returns `undefined`, the default method is used to clone the value. - `value`: The current value being cloned. - `key`: The property name of the current value being cloned. - `obj`: The entire object `obj` to clone. diff --git a/docs/zh_hans/reference/object/cloneDeepWith.md b/docs/zh_hans/reference/object/cloneDeepWith.md index 819d079f8..ec55d7704 100644 --- a/docs/zh_hans/reference/object/cloneDeepWith.md +++ b/docs/zh_hans/reference/object/cloneDeepWith.md @@ -9,14 +9,14 @@ ```typescript function cloneDeepWith( obj: T, - cloneValue: (value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any + cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any ): T; ``` ### 参数 - `obj` (`T`): 要克隆的对象。 -- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T | undefined, stack: Map) => any`): 表示如何克隆值的函数。可以返回克隆后的值而不是使用默认方法。如果返回 `undefined`,则使用默认方法克隆值。 +- `cloneValue` (`(value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any`): 表示如何克隆值的函数。可以返回克隆后的值而不是使用默认方法。如果返回 `undefined`,则使用默认方法克隆值。 - `value`: 当前正在克隆的值。 - `key`: 当前正在克隆的值的属性名。 - `obj`: 要克隆的整个对象 `obj`。 diff --git a/src/object/cloneDeepWith.ts b/src/object/cloneDeepWith.ts index 8f473af46..d763d7855 100644 --- a/src/object/cloneDeepWith.ts +++ b/src/object/cloneDeepWith.ts @@ -3,7 +3,12 @@ import { isPrimitive } from '../predicate/isPrimitive.ts'; import { isTypedArray } from '../predicate/isTypedArray.ts'; /** - * Creates a deep clone of the given object using a customizer function. + * Deeply clones the given object. + * + * You can customize the deep cloning process using the `cloneValue` function. + * The function takes the current value `value`, the property name `key`, and the entire object `obj` as arguments. + * If the function returns a value, that value is used; + * if it returns `undefined`, the default cloning method is used. * * @template T - The type of the object. * @param {T} obj - The object to clone. @@ -39,7 +44,7 @@ import { isTypedArray } from '../predicate/isTypedArray.ts'; */ export function cloneDeepWith( obj: T, - cloneValue: (value: any, key: PropertyKey | undefined, object: T | undefined, stack: Map) => any + cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any ): T { return cloneDeepWithImpl(obj, undefined, obj, new Map(), cloneValue); } @@ -49,9 +54,7 @@ export function cloneDeepWithImpl( keyToClone: PropertyKey | undefined, objectToClone: T, stack = new Map(), - cloneValue: - | ((value: any, key: PropertyKey | undefined, object: T | undefined, stack: Map) => any) - | undefined = undefined + cloneValue: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any) | undefined = undefined ): T { const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack); @@ -212,9 +215,7 @@ export function copyProperties( source: any, objectToClone: T = target, stack?: Map | undefined, - cloneValue?: - | ((value: any, key: PropertyKey | undefined, object: T | undefined, stack: Map) => any) - | undefined + cloneValue?: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map) => any) | undefined ): void { const keys = [...Object.keys(source), ...getSymbols(source)];