From a3accd5ebdaf830ca3ea3acca2245ec3084989c6 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 18 Feb 2022 16:59:47 +0000 Subject: [PATCH] chore(release): 3.0.0-beta.7 [skip ci] # [3.0.0-beta.7](https://github.com/RebeccaStevens/deepmerge-ts/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2022-02-18) ### Features * lone values will now be passed to mergeOthers rather than just returned ([#57](https://github.com/RebeccaStevens/deepmerge-ts/issues/57)) ([14a09ca](https://github.com/RebeccaStevens/deepmerge-ts/commit/14a09ca2d67ffbb5341719c633873e91a5565d89)) --- CHANGELOG.md | 7 +++++++ dist/deno/README.md | 28 +++++++++++++++------------- dist/deno/deepmerge.ts | 31 ++++++++++++++++--------------- dist/node/index.cjs | 17 +++++++---------- dist/node/index.mjs | 17 +++++++---------- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c96298..4d7e7f38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. Dates are displayed in UTC. +# [3.0.0-beta.7](https://github.com/RebeccaStevens/deepmerge-ts/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2022-02-18) + + +### Features + +* lone values will now be passed to mergeOthers rather than just returned ([#57](https://github.com/RebeccaStevens/deepmerge-ts/issues/57)) ([14a09ca](https://github.com/RebeccaStevens/deepmerge-ts/commit/14a09ca2d67ffbb5341719c633873e91a5565d89)) + # [3.0.0-beta.6](https://github.com/RebeccaStevens/deepmerge-ts/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2022-02-17) diff --git a/dist/deno/README.md b/dist/deno/README.md index 4533c58d..3c26c38b 100644 --- a/dist/deno/README.md +++ b/dist/deno/README.md @@ -93,22 +93,24 @@ console.log(merged); // Prettierfied output: // -// { -// record: { -// prop1: "changed", -// prop2: "value2", -// prop3: "value3" -// } -// array: (6) [1, 2, 3, 2, 3, 4] -// set: Set(4) {1, 2, 3, 4} -// map: Map(3) { -// "key1" => "value1", -// "key2" => "changed", -// "key3" => "value3" -// } +// Object { +// "record": Object { +// "prop1": "changed", +// "prop2": "value2", +// "prop3": "value3", +// }, +// "array": Array [1, 2, 3, 2, 3, 4], +// "set": Set { 1, 2, 3, 4 }, +// "map": Map { +// "key1" => "value1", +// "key2" => "changed", +// "key3" => "value3", +// }, // } ``` +You can try out this example at [codesandbox.io](https://codesandbox.io/s/deepmerge-ts-example-iltxby?file=/src/example.ts). + ### Using customized config [See deepmerge custom docs](./docs/deepmergeCustom.md). diff --git a/dist/deno/deepmerge.ts b/dist/deno/deepmerge.ts index ee11fac6..0a43b5c1 100644 --- a/dist/deno/deepmerge.ts +++ b/dist/deno/deepmerge.ts @@ -123,13 +123,6 @@ export function deepmergeCustom< * The customized deepmerge function. */ function customizedDeepmerge(...objects: ReadonlyArray) { - if (objects.length === 0) { - return undefined; - } - if (objects.length === 1) { - return objects[0]; - } - return mergeUnknowns< ReadonlyArray, typeof utils, @@ -186,6 +179,17 @@ function mergeUnknowns< M, MM extends Readonly> >(values: Ts, utils: U, meta: M | undefined): DeepMergeHKT { + if (values.length === 0) { + return undefined as DeepMergeHKT; + } + if (values.length === 1) { + return utils.mergeFunctions.mergeOthers( + values, + utils, + meta + ) as DeepMergeHKT; + } + const type = getObjectType(values[0]); // eslint-disable-next-line functional/no-conditional-statement -- add an early escape for better performance. @@ -274,14 +278,11 @@ function mergeRecords< parents: values, } as unknown as MM); - result[key] = - propValues.length === 1 - ? propValues[0] - : mergeUnknowns, U, MF, M, MM>( - propValues, - utils, - updatedMeta - ); + result[key] = mergeUnknowns, U, MF, M, MM>( + propValues, + utils, + updatedMeta + ); } /* eslint-enable functional/no-loop-statement, functional/no-conditional-statement */ diff --git a/dist/node/index.cjs b/dist/node/index.cjs index c433ff3c..4990ef8c 100644 --- a/dist/node/index.cjs +++ b/dist/node/index.cjs @@ -105,12 +105,6 @@ function deepmergeCustom(options, rootMetaData) { * The customized deepmerge function. */ function customizedDeepmerge(...objects) { - if (objects.length === 0) { - return undefined; - } - if (objects.length === 1) { - return objects[0]; - } return mergeUnknowns(objects, utils, rootMetaData); } return customizedDeepmerge; @@ -140,6 +134,12 @@ function getUtils(options, customizedDeepmerge) { * @param values - The values. */ function mergeUnknowns(values, utils, meta) { + if (values.length === 0) { + return undefined; + } + if (values.length === 1) { + return utils.mergeFunctions.mergeOthers(values, utils, meta); + } const type = getObjectType(values[0]); // eslint-disable-next-line functional/no-conditional-statement -- add an early escape for better performance. if (type !== 0 /* NOT */ && type !== 5 /* OTHER */) { @@ -184,10 +184,7 @@ function mergeRecords(values, utils, meta) { key, parents: values, }); - result[key] = - propValues.length === 1 - ? propValues[0] - : mergeUnknowns(propValues, utils, updatedMeta); + result[key] = mergeUnknowns(propValues, utils, updatedMeta); } /* eslint-enable functional/no-loop-statement, functional/no-conditional-statement */ return result; diff --git a/dist/node/index.mjs b/dist/node/index.mjs index d6636270..57a8ccc0 100644 --- a/dist/node/index.mjs +++ b/dist/node/index.mjs @@ -101,12 +101,6 @@ function deepmergeCustom(options, rootMetaData) { * The customized deepmerge function. */ function customizedDeepmerge(...objects) { - if (objects.length === 0) { - return undefined; - } - if (objects.length === 1) { - return objects[0]; - } return mergeUnknowns(objects, utils, rootMetaData); } return customizedDeepmerge; @@ -136,6 +130,12 @@ function getUtils(options, customizedDeepmerge) { * @param values - The values. */ function mergeUnknowns(values, utils, meta) { + if (values.length === 0) { + return undefined; + } + if (values.length === 1) { + return utils.mergeFunctions.mergeOthers(values, utils, meta); + } const type = getObjectType(values[0]); // eslint-disable-next-line functional/no-conditional-statement -- add an early escape for better performance. if (type !== 0 /* NOT */ && type !== 5 /* OTHER */) { @@ -180,10 +180,7 @@ function mergeRecords(values, utils, meta) { key, parents: values, }); - result[key] = - propValues.length === 1 - ? propValues[0] - : mergeUnknowns(propValues, utils, updatedMeta); + result[key] = mergeUnknowns(propValues, utils, updatedMeta); } /* eslint-enable functional/no-loop-statement, functional/no-conditional-statement */ return result;