@win2win/shared 1.0.142 → 1.0.145
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.
|
@@ -10,3 +10,11 @@ export declare function deserializeWithContextAndRun(stringFn?: string, context?
|
|
|
10
10
|
export declare function toCurrency(value: number, symbol?: string, options?: {
|
|
11
11
|
decimals: number;
|
|
12
12
|
}): string;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* Merges multiple objects into one, ignoring properties with values that match the specified empty values.
|
|
16
|
+
* @param args - Objects to merge. The last argument can be an options object.
|
|
17
|
+
* @param options.emptyValues - Array of values that should be ignored when merging objects (default: `undefined`)
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function mergeObjects(...args: Record<string, any>[]): Record<string, any>;
|
|
@@ -5,6 +5,7 @@ exports.deserializeAndRun = deserializeAndRun;
|
|
|
5
5
|
exports.deserializeWithContext = deserializeWithContext;
|
|
6
6
|
exports.deserializeWithContextAndRun = deserializeWithContextAndRun;
|
|
7
7
|
exports.toCurrency = toCurrency;
|
|
8
|
+
exports.mergeObjects = mergeObjects;
|
|
8
9
|
const lodash_1 = require("lodash");
|
|
9
10
|
// TODO: refactorizar para usar siempre invisible context, si se pasa
|
|
10
11
|
function deserialize(stringFn, options) {
|
|
@@ -56,11 +57,27 @@ function toCurrency(value, symbol = "EUR", options) {
|
|
|
56
57
|
}).format(value);
|
|
57
58
|
return formatted;
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* Merges multiple objects into one, ignoring properties with values that match the specified empty values.
|
|
63
|
+
* @param args - Objects to merge. The last argument can be an options object.
|
|
64
|
+
* @param options.emptyValues - Array of values that should be ignored when merging objects (default: `undefined`)
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
function mergeObjects(...args) {
|
|
68
|
+
const lastArg = args[args.length - 1];
|
|
69
|
+
const options = lastArg &&
|
|
70
|
+
!Array.isArray(lastArg) &&
|
|
71
|
+
typeof lastArg === "object" &&
|
|
72
|
+
"emptyValues" in lastArg
|
|
73
|
+
? args.pop()
|
|
74
|
+
: undefined;
|
|
75
|
+
const emptyValues = [undefined, ...(options?.emptyValues || [])];
|
|
76
|
+
return args.reduce((acc, obj) => {
|
|
77
|
+
return (0, lodash_1.mergeWith)(acc, obj, (objValue, srcValue) => {
|
|
78
|
+
if (emptyValues.some((v) => srcValue === v))
|
|
79
|
+
return objValue;
|
|
80
|
+
return srcValue;
|
|
81
|
+
});
|
|
82
|
+
}, {});
|
|
66
83
|
}
|
package/package.json
CHANGED