xjs-common 13.3.1 → 13.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.
package/build/cjs/func/u-obj.js
CHANGED
|
@@ -75,13 +75,10 @@ var UObj;
|
|
|
75
75
|
return o;
|
|
76
76
|
}
|
|
77
77
|
UObj.manipulateProperties = manipulateProperties;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*/
|
|
83
|
-
function generateRecord(keys, vgen) {
|
|
84
|
-
return keys.reduce((o, k) => { o[k] = vgen(k); return o; }, {});
|
|
78
|
+
function array2record(keyOrValues, op) {
|
|
79
|
+
return keyOrValues.reduce(!!op.kgen
|
|
80
|
+
? (o, korv) => { o[op.kgen(korv)] = korv; return o; }
|
|
81
|
+
: (o, korv) => { o[korv] = op.vgen(korv); return o; }, {});
|
|
85
82
|
}
|
|
86
|
-
UObj.
|
|
83
|
+
UObj.array2record = array2record;
|
|
87
84
|
})(UObj || (exports.UObj = UObj = {}));
|
|
@@ -45,9 +45,15 @@ export declare namespace UObj {
|
|
|
45
45
|
targetType?: MaybeArray<Exclude<Type, "object" | "null" | "undefined">>;
|
|
46
46
|
}): T;
|
|
47
47
|
/**
|
|
48
|
-
* generate a record object which
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
48
|
+
* generate a record object which is mapped by specified keys or values with pair of the entry generated from generator.
|
|
49
|
+
* @param keyOrValues keys or values to be contained in the object.
|
|
50
|
+
* @param op.kgen key generator. if pass this, `keyOrValues` is treated as values.
|
|
51
|
+
* @param op.vgen value generator. if pass this, `keyOrValues` is treated as keys.
|
|
51
52
|
*/
|
|
52
|
-
function
|
|
53
|
+
function array2record<K extends IndexSignature, V>(keyOrValues: K[], op: {
|
|
54
|
+
vgen: (k: K) => V;
|
|
55
|
+
}): Record<K, V>;
|
|
56
|
+
function array2record<K extends IndexSignature, V>(keyOrValues: V[], op: {
|
|
57
|
+
kgen: (v: V) => K;
|
|
58
|
+
}): Record<K, V>;
|
|
53
59
|
}
|
package/build/esm/func/u-obj.js
CHANGED
|
@@ -72,13 +72,10 @@ export var UObj;
|
|
|
72
72
|
return o;
|
|
73
73
|
}
|
|
74
74
|
UObj.manipulateProperties = manipulateProperties;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*/
|
|
80
|
-
function generateRecord(keys, vgen) {
|
|
81
|
-
return keys.reduce((o, k) => { o[k] = vgen(k); return o; }, {});
|
|
75
|
+
function array2record(keyOrValues, op) {
|
|
76
|
+
return keyOrValues.reduce(!!op.kgen
|
|
77
|
+
? (o, korv) => { o[op.kgen(korv)] = korv; return o; }
|
|
78
|
+
: (o, korv) => { o[korv] = op.vgen(korv); return o; }, {});
|
|
82
79
|
}
|
|
83
|
-
UObj.
|
|
80
|
+
UObj.array2record = array2record;
|
|
84
81
|
})(UObj || (UObj = {}));
|