@win2win/shared 1.0.157 → 1.0.159
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonObject } from "../interfaces";
|
|
1
2
|
export interface DeserializeOptions {
|
|
2
3
|
context?: Record<string, any>;
|
|
3
4
|
run?: boolean;
|
|
@@ -5,8 +6,10 @@ export interface DeserializeOptions {
|
|
|
5
6
|
}
|
|
6
7
|
export declare function deserialize(stringFn?: string, options?: DeserializeOptions): any;
|
|
7
8
|
export declare function deserializeAndRun(stringFn?: string): any;
|
|
8
|
-
export declare function deserializeWithContext(stringFn?: string, context?:
|
|
9
|
-
export declare function deserializeWithContextAndRun(stringFn?: string, context?:
|
|
9
|
+
export declare function deserializeWithContext(stringFn?: string, context?: JsonObject): any;
|
|
10
|
+
export declare function deserializeWithContextAndRun(stringFn?: string, context?: JsonObject): any;
|
|
11
|
+
export declare function tryToDeserialize(stringFn: string | undefined, context?: JsonObject, defaultValue?: any): any;
|
|
12
|
+
export declare function tryToDeserializeAndRun(stringFn: string | undefined, context?: JsonObject, defaultValue?: any): any;
|
|
10
13
|
export declare function toCurrency(value: number, symbol?: string, options?: {
|
|
11
14
|
decimals: number;
|
|
12
15
|
}): string;
|
|
@@ -17,4 +20,4 @@ export declare function toCurrency(value: number, symbol?: string, options?: {
|
|
|
17
20
|
* @param options.emptyValues - Array of values that should be ignored when merging objects (default: `undefined`)
|
|
18
21
|
* @returns
|
|
19
22
|
*/
|
|
20
|
-
export declare function mergeObjects<T = Record<string, any>>(...args: (Record<string, any> | undefined | null |
|
|
23
|
+
export declare function mergeObjects<T = Record<string, any>>(...args: (Record<string, any> | undefined | null | "")[]): T;
|
|
@@ -4,9 +4,12 @@ exports.deserialize = deserialize;
|
|
|
4
4
|
exports.deserializeAndRun = deserializeAndRun;
|
|
5
5
|
exports.deserializeWithContext = deserializeWithContext;
|
|
6
6
|
exports.deserializeWithContextAndRun = deserializeWithContextAndRun;
|
|
7
|
+
exports.tryToDeserialize = tryToDeserialize;
|
|
8
|
+
exports.tryToDeserializeAndRun = tryToDeserializeAndRun;
|
|
7
9
|
exports.toCurrency = toCurrency;
|
|
8
10
|
exports.mergeObjects = mergeObjects;
|
|
9
11
|
const lodash_1 = require("lodash");
|
|
12
|
+
const validators_1 = require("./validators");
|
|
10
13
|
// TODO: refactorizar para usar siempre invisible context, si se pasa
|
|
11
14
|
function deserialize(stringFn, options) {
|
|
12
15
|
const { context = {}, run = false, useInvisibleContext = false, } = options || {};
|
|
@@ -42,6 +45,18 @@ function deserializeWithContextAndRun(stringFn, context = {}) {
|
|
|
42
45
|
run: true,
|
|
43
46
|
});
|
|
44
47
|
}
|
|
48
|
+
function tryToDeserialize(stringFn, context = {}, defaultValue = null) {
|
|
49
|
+
if ((0, validators_1.isSerializedFunction)(stringFn)) {
|
|
50
|
+
return deserializeWithContext(stringFn, context);
|
|
51
|
+
}
|
|
52
|
+
return defaultValue;
|
|
53
|
+
}
|
|
54
|
+
function tryToDeserializeAndRun(stringFn, context = {}, defaultValue = null) {
|
|
55
|
+
if ((0, validators_1.isSerializedFunction)(stringFn)) {
|
|
56
|
+
return deserializeWithContextAndRun(stringFn, context);
|
|
57
|
+
}
|
|
58
|
+
return defaultValue;
|
|
59
|
+
}
|
|
45
60
|
function toCurrency(value, symbol = "EUR", options) {
|
|
46
61
|
const { decimals = 2 } = options || {};
|
|
47
62
|
const locale = {
|
|
@@ -77,6 +92,10 @@ function mergeObjects(...args) {
|
|
|
77
92
|
return (0, lodash_1.mergeWith)(acc, obj, (objValue, srcValue) => {
|
|
78
93
|
if (emptyValues.some((v) => srcValue === v))
|
|
79
94
|
return objValue;
|
|
95
|
+
if ((0, lodash_1.isArray)(srcValue))
|
|
96
|
+
return srcValue;
|
|
97
|
+
if ((0, lodash_1.isObject)(srcValue) && (0, lodash_1.isObject)(objValue))
|
|
98
|
+
return mergeObjects(objValue, srcValue, { emptyValues });
|
|
80
99
|
return srcValue;
|
|
81
100
|
});
|
|
82
101
|
}, {});
|
package/package.json
CHANGED