@augment-vir/common 19.3.1 → 19.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeDeep = void 0;
4
+ const runtime_type_of_1 = require("../runtime-type-of");
5
+ const tuple_1 = require("../tuple");
6
+ /**
7
+ * Accepts multiple objects and merges their key-value pairs recursively.
8
+ *
9
+ * Note that order matters! Each input object will overwrite the properties of the previous objects.
10
+ */
11
+ function mergeDeep(...inputs) {
12
+ if (!(0, tuple_1.isLengthAtLeast)(inputs, 1)) {
13
+ return {};
14
+ }
15
+ if (inputs.length === 1) {
16
+ return inputs[0];
17
+ }
18
+ let result = {};
19
+ const mergeProps = {};
20
+ inputs.forEach((individualInput) => {
21
+ result = {
22
+ ...result,
23
+ ...individualInput,
24
+ };
25
+ Object.entries(individualInput).forEach(([key, value,]) => {
26
+ if ((0, runtime_type_of_1.isRuntimeTypeOf)(value, 'object')) {
27
+ const mergePropsArray = mergeProps[key] || [];
28
+ if (!mergeProps[key]) {
29
+ mergeProps[key] = mergePropsArray;
30
+ }
31
+ mergePropsArray.push(value);
32
+ }
33
+ });
34
+ });
35
+ Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
36
+ result[key] = mergeDeep(...mergeValues);
37
+ });
38
+ return result;
39
+ }
40
+ exports.mergeDeep = mergeDeep;
package/dist/cjs/index.js CHANGED
@@ -33,6 +33,7 @@ __exportStar(require("./augments/object/has-key"), exports);
33
33
  __exportStar(require("./augments/object/jsonify"), exports);
34
34
  __exportStar(require("./augments/object/map-object"), exports);
35
35
  __exportStar(require("./augments/object/matches-object-shape"), exports);
36
+ __exportStar(require("./augments/object/merge-deep"), exports);
36
37
  __exportStar(require("./augments/object/nested-keys"), exports);
37
38
  __exportStar(require("./augments/object/object"), exports);
38
39
  __exportStar(require("./augments/object/object-entries"), exports);
@@ -0,0 +1,36 @@
1
+ import { isRuntimeTypeOf } from '../runtime-type-of';
2
+ import { isLengthAtLeast } from '../tuple';
3
+ /**
4
+ * Accepts multiple objects and merges their key-value pairs recursively.
5
+ *
6
+ * Note that order matters! Each input object will overwrite the properties of the previous objects.
7
+ */
8
+ export function mergeDeep(...inputs) {
9
+ if (!isLengthAtLeast(inputs, 1)) {
10
+ return {};
11
+ }
12
+ if (inputs.length === 1) {
13
+ return inputs[0];
14
+ }
15
+ let result = {};
16
+ const mergeProps = {};
17
+ inputs.forEach((individualInput) => {
18
+ result = {
19
+ ...result,
20
+ ...individualInput,
21
+ };
22
+ Object.entries(individualInput).forEach(([key, value,]) => {
23
+ if (isRuntimeTypeOf(value, 'object')) {
24
+ const mergePropsArray = mergeProps[key] || [];
25
+ if (!mergeProps[key]) {
26
+ mergeProps[key] = mergePropsArray;
27
+ }
28
+ mergePropsArray.push(value);
29
+ }
30
+ });
31
+ });
32
+ Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
33
+ result[key] = mergeDeep(...mergeValues);
34
+ });
35
+ return result;
36
+ }
package/dist/esm/index.js CHANGED
@@ -17,6 +17,7 @@ export * from './augments/object/has-key';
17
17
  export * from './augments/object/jsonify';
18
18
  export * from './augments/object/map-object';
19
19
  export * from './augments/object/matches-object-shape';
20
+ export * from './augments/object/merge-deep';
20
21
  export * from './augments/object/nested-keys';
21
22
  export * from './augments/object/object';
22
23
  export * from './augments/object/object-entries';
@@ -0,0 +1,7 @@
1
+ export type BaseObject = Record<PropertyKey, unknown>;
2
+ /**
3
+ * Accepts multiple objects and merges their key-value pairs recursively.
4
+ *
5
+ * Note that order matters! Each input object will overwrite the properties of the previous objects.
6
+ */
7
+ export declare function mergeDeep<T extends BaseObject>(...inputs: (T | Partial<T>)[]): T;
@@ -17,6 +17,7 @@ export * from './augments/object/has-key';
17
17
  export * from './augments/object/jsonify';
18
18
  export * from './augments/object/map-object';
19
19
  export * from './augments/object/matches-object-shape';
20
+ export * from './augments/object/merge-deep';
20
21
  export * from './augments/object/nested-keys';
21
22
  export * from './augments/object/object';
22
23
  export * from './augments/object/object-entries';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "19.3.1",
3
+ "version": "19.4.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -24,7 +24,7 @@
24
24
  "test:types": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "type-fest": "^4.3.2"
27
+ "type-fest": "^4.3.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^5.2.2"