From 8912165ee869960cc50d0d07a1173b1a9091e422 Mon Sep 17 00:00:00 2001 From: Sojin Park Date: Sat, 10 Aug 2024 16:32:40 +0900 Subject: [PATCH] docs(mergeWith): Improve docs for mergeWith --- docs/ko/reference/object/mergeWith.md | 10 ++-------- docs/reference/object/mergeWith.md | 13 +++---------- docs/zh_hans/reference/object/mergeWith.md | 10 ++-------- src/object/mergeWith.ts | 10 ++-------- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/docs/ko/reference/object/mergeWith.md b/docs/ko/reference/object/mergeWith.md index edfbd509d..2954e69f7 100644 --- a/docs/ko/reference/object/mergeWith.md +++ b/docs/ko/reference/object/mergeWith.md @@ -2,15 +2,9 @@ `source`가 가지고 있는 값들을 `target` 객체로 병합해요. -어떻게 프로퍼티를 병합하는지 지정하기 위해서 `merge` 함수 인자를 정의하세요. `merge` 함수는 병합되는 모든 프로퍼티에 대해서, 다음과 같은 인자를 가지고 호출돼요. +어떻게 프로퍼티를 병합하는지 지정하기 위해서 `merge` 함수 인자를 정의하세요. `merge` 함수 인자는 `target` 객체에 설정될 값을 반환해야 해요. -- `targetValue`: `target` 객체가 가지고 있는 값. -- `sourceValue`: `source` 객체가 가지고 있는 값. -- `key`: 병합되고 있는 프로퍼티 이름. -- `target`: `target` 객체. -- `source`: `source` 객체. - -`merge` 함수 인자는 `target` 객체에 설정될 값을 반환해야 해요. 만약 `undefined`를 반환한다면, 기본적으로 두 값을 깊이 병합해요. 깊은 병합에서는, 중첩된 객체나 배열을 다음과 같이 재귀적으로 병합해요. +만약 `undefined`를 반환한다면, 기본적으로 두 값을 깊이 병합해요. 깊은 병합에서는, 중첩된 객체나 배열을 다음과 같이 재귀적으로 병합해요. - `source`와 `target`의 프로퍼티가 모두 객체 또는 배열이라면, 두 객체와 배열은 병합돼요. - 만약에 `source`의 프로퍼티가 `undefined` 라면, `target`의 프로퍼티를 덮어씌우지 않아요. diff --git a/docs/reference/object/mergeWith.md b/docs/reference/object/mergeWith.md index cba4b3ff3..465b7f461 100644 --- a/docs/reference/object/mergeWith.md +++ b/docs/reference/object/mergeWith.md @@ -2,15 +2,9 @@ Merges the properties of the source object into the target object. -You can provide a custom `merge` function to control how properties are merged. The `merge` function is called for each property that is being merged and receives the following arguments: +You can provide a custom `merge` function to control how properties are merged. It should return the value to be set in the target object. -- `targetValue`: The current value of the property in the target object. -- `sourceValue`: The value of the property in the source object. -- `key`: The key of the property being merged. -- `target`: The target object. -- `source`: The source object. - -The `merge` function should return the value to be set in the target object. If it returns `undefined`, a default deep merge will be applied for arrays and objects: +If it returns `undefined`, a default deep merge will be applied for arrays and objects: - If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged. - If a property in the source object is undefined, it will not overwrite a defined property in the target object. @@ -60,12 +54,11 @@ mergeWith(target, source, (targetValue, sourceValue) => { const target = { a: [1], b: [2] }; const source = { a: [3], b: [4] }; -const result = mergeWith(target, source, (objValue, srcValue) => { +mergeWith(target, source, (objValue, srcValue) => { if (Array.isArray(objValue)) { return objValue.concat(srcValue); } }); - // Returns { a: [1, 3], b: [2, 4] }) ``` diff --git a/docs/zh_hans/reference/object/mergeWith.md b/docs/zh_hans/reference/object/mergeWith.md index 63698f1a9..41634ae75 100644 --- a/docs/zh_hans/reference/object/mergeWith.md +++ b/docs/zh_hans/reference/object/mergeWith.md @@ -2,15 +2,9 @@ 将源对象的属性合并到目标对象中。 -您可以提供自定义的 `merge` 函数来控制属性的合并方式。`merge` 函数会在每个属性被合并时调用,并接收以下参数: +您可以提供自定义的 `merge` 函数来控制属性的合并方式。`merge` 函数应返回要在目标对象中设置的值。 -- `targetValue`:目标对象中属性的当前值。 -- `sourceValue`:源对象中属性的值。 -- `key`:被合并的属性的键。 -- `target`:目标对象。 -- `source`:源对象。 - -`merge` 函数应返回要在目标对象中设置的值。如果返回 `undefined`,则会对数组和对象应用默认的深度合并: +如果返回 `undefined`,则会对数组和对象应用默认的深度合并: - 如果源对象中的属性是数组或对象,而目标对象中对应的属性也是数组或对象,它们将被合并。 - 如果源对象中的属性是 `undefined`,它不会覆盖目标对象中已定义的属性。 diff --git a/src/object/mergeWith.ts b/src/object/mergeWith.ts index 909ca4ccd..733a9d6dc 100644 --- a/src/object/mergeWith.ts +++ b/src/object/mergeWith.ts @@ -3,15 +3,9 @@ import { isObjectLike } from '../compat/predicate/isObjectLike.ts'; /** * Merges the properties of the source object into the target object. * - * You can provide a custom `merge` function to control how properties are merged. The `merge` function is called for each property that is being merged and receives the following arguments: + * You can provide a custom `merge` function to control how properties are merged. It should return the value to be set in the target object. * - * - `targetValue`: The current value of the property in the target object. - * - `sourceValue`: The value of the property in the source object. - * - `key`: The key of the property being merged. - * - `target`: The target object. - * - `source`: The source object. - * - * The `merge` function should return the value to be set in the target object. If it returns `undefined`, a default deep merge will be applied for arrays and objects: + * If it returns `undefined`, a default deep merge will be applied for arrays and objects: * * - If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged. * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.