diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6eb9ad..10a3da93 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. +## [4.0.4](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.3...v4.0.4) (2022-06-13) + + +### Bug Fixes + +* drop keys that have no enumerable properties ([3363570](https://github.com/RebeccaStevens/deepmerge-ts/commit/3363570fcc53488d22a2d4b778b558173c7ee5c9)) + ## [4.0.3](https://github.com/RebeccaStevens/deepmerge-ts/compare/v4.0.2...v4.0.3) (2022-04-06) diff --git a/dist/deno/deepmerge.ts b/dist/deno/deepmerge.ts index 87559716..7ce13713 100644 --- a/dist/deno/deepmerge.ts +++ b/dist/deno/deepmerge.ts @@ -203,8 +203,8 @@ function mergeUnknowns< // eslint-disable-next-line functional/no-conditional-statement -- add an early escape for better performance. if (type !== ObjectType.NOT && type !== ObjectType.OTHER) { // eslint-disable-next-line functional/no-loop-statement -- using a loop here is more performant than mapping every value and then testing every value. - for (let mutableIndex = 1; mutableIndex < values.length; mutableIndex++) { - if (getObjectType(values[mutableIndex]) === type) { + for (let m_index = 1; m_index < values.length; m_index++) { + if (getObjectType(values[m_index]) === type) { continue; } @@ -425,7 +425,9 @@ function defaultMergeRecords< } } - // assert(propValues.length > 0); + if (propValues.length === 0) { + continue; + } const updatedMeta = utils.metaDataUpdater(meta, { key, diff --git a/dist/deno/types/options.ts b/dist/deno/types/options.ts index d05f5457..890d3d63 100644 --- a/dist/deno/types/options.ts +++ b/dist/deno/types/options.ts @@ -1,4 +1,4 @@ -// eslint-disable-next-line import/no-relative-parent-imports -- use "@/deepmerge" once denoify can support it. +// eslint-disable-next-line import/no-relative-parent-imports -- use "deepmerge-ts" once denoify can support it. import type { DeepMergeMergeFunctionsDefaults } from "../index.ts"; import type { DeepMergeBuiltInMetaData } from "./merging.ts"; diff --git a/dist/node/index.cjs b/dist/node/index.cjs index 293768e1..4f2ef872 100644 --- a/dist/node/index.cjs +++ b/dist/node/index.cjs @@ -12,21 +12,21 @@ var isPlainObject = require('is-plain-object'); */ function getObjectType(object) { if (typeof object !== "object" || object === null) { - return 0 /* NOT */; + return 0 /* ObjectType.NOT */; } if (Array.isArray(object)) { - return 2 /* ARRAY */; + return 2 /* ObjectType.ARRAY */; } if (isPlainObject.isPlainObject(object)) { - return 1 /* RECORD */; + return 1 /* ObjectType.RECORD */; } if (object instanceof Set) { - return 3 /* SET */; + return 3 /* ObjectType.SET */; } if (object instanceof Map) { - return 4 /* MAP */; + return 4 /* ObjectType.MAP */; } - return 5 /* OTHER */; + return 5 /* ObjectType.OTHER */; } /** * Get the keys of the given objects including symbol keys. @@ -151,23 +151,23 @@ function mergeUnknowns(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 */) { + if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { // eslint-disable-next-line functional/no-loop-statement -- using a loop here is more performant than mapping every value and then testing every value. - for (let mutableIndex = 1; mutableIndex < values.length; mutableIndex++) { - if (getObjectType(values[mutableIndex]) === type) { + for (let m_index = 1; m_index < values.length; m_index++) { + if (getObjectType(values[m_index]) === type) { continue; } return mergeOthers(values, utils, meta); } } switch (type) { - case 1 /* RECORD */: + case 1 /* ObjectType.RECORD */: return mergeRecords(values, utils, meta); - case 2 /* ARRAY */: + case 2 /* ObjectType.ARRAY */: return mergeArrays(values, utils, meta); - case 3 /* SET */: + case 3 /* ObjectType.SET */: return mergeSets(values, utils, meta); - case 4 /* MAP */: + case 4 /* ObjectType.MAP */: return mergeMaps(values, utils, meta); default: return mergeOthers(values, utils, meta); @@ -266,7 +266,9 @@ function defaultMergeRecords(values, utils, meta) { propValues.push(value[key]); } } - // assert(propValues.length > 0); + if (propValues.length === 0) { + continue; + } const updatedMeta = utils.metaDataUpdater(meta, { key, parents: values, diff --git a/dist/node/index.mjs b/dist/node/index.mjs index 3ed233d6..45e22ff9 100644 --- a/dist/node/index.mjs +++ b/dist/node/index.mjs @@ -8,21 +8,21 @@ import { isPlainObject } from 'is-plain-object'; */ function getObjectType(object) { if (typeof object !== "object" || object === null) { - return 0 /* NOT */; + return 0 /* ObjectType.NOT */; } if (Array.isArray(object)) { - return 2 /* ARRAY */; + return 2 /* ObjectType.ARRAY */; } if (isPlainObject(object)) { - return 1 /* RECORD */; + return 1 /* ObjectType.RECORD */; } if (object instanceof Set) { - return 3 /* SET */; + return 3 /* ObjectType.SET */; } if (object instanceof Map) { - return 4 /* MAP */; + return 4 /* ObjectType.MAP */; } - return 5 /* OTHER */; + return 5 /* ObjectType.OTHER */; } /** * Get the keys of the given objects including symbol keys. @@ -147,23 +147,23 @@ function mergeUnknowns(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 */) { + if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { // eslint-disable-next-line functional/no-loop-statement -- using a loop here is more performant than mapping every value and then testing every value. - for (let mutableIndex = 1; mutableIndex < values.length; mutableIndex++) { - if (getObjectType(values[mutableIndex]) === type) { + for (let m_index = 1; m_index < values.length; m_index++) { + if (getObjectType(values[m_index]) === type) { continue; } return mergeOthers(values, utils, meta); } } switch (type) { - case 1 /* RECORD */: + case 1 /* ObjectType.RECORD */: return mergeRecords(values, utils, meta); - case 2 /* ARRAY */: + case 2 /* ObjectType.ARRAY */: return mergeArrays(values, utils, meta); - case 3 /* SET */: + case 3 /* ObjectType.SET */: return mergeSets(values, utils, meta); - case 4 /* MAP */: + case 4 /* ObjectType.MAP */: return mergeMaps(values, utils, meta); default: return mergeOthers(values, utils, meta); @@ -262,7 +262,9 @@ function defaultMergeRecords(values, utils, meta) { propValues.push(value[key]); } } - // assert(propValues.length > 0); + if (propValues.length === 0) { + continue; + } const updatedMeta = utils.metaDataUpdater(meta, { key, parents: values,