xjs-common 13.1.0 → 13.2.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.js +4 -7
- package/build/esm/func/u.d.ts +12 -1
- package/build/esm/func/u.js +4 -6
- package/package.json +1 -1
package/build/cjs/func/u.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.getJSTDate = getJSTDate;
|
|
|
4
4
|
exports.delay = delay;
|
|
5
5
|
exports.int2array = int2array;
|
|
6
6
|
exports.array2map = array2map;
|
|
7
|
-
exports.bitor = bitor;
|
|
8
7
|
exports.retry = retry;
|
|
9
8
|
const xjs_err_1 = require("../obj/xjs-err");
|
|
10
9
|
const s_errCode = 10;
|
|
@@ -20,20 +19,18 @@ function int2array(size) {
|
|
|
20
19
|
throw new xjs_err_1.XjsErr(s_errCode, "size of the argument is not number.");
|
|
21
20
|
return Array.from(Array(s).keys());
|
|
22
21
|
}
|
|
23
|
-
function array2map(array, keyGen) {
|
|
22
|
+
function array2map(array, keyGen, op) {
|
|
23
|
+
const _acm = op?.accumulate ?? true;
|
|
24
24
|
const map = new Map();
|
|
25
25
|
for (const e of array) {
|
|
26
26
|
const k = keyGen(e);
|
|
27
27
|
if (map.has(k))
|
|
28
|
-
map.get(k).push(e);
|
|
28
|
+
_acm && map.get(k).push(e);
|
|
29
29
|
else
|
|
30
|
-
map.set(k, [e]);
|
|
30
|
+
map.set(k, _acm ? [e] : e);
|
|
31
31
|
}
|
|
32
32
|
return map;
|
|
33
33
|
}
|
|
34
|
-
function bitor(...bit) {
|
|
35
|
-
return bit.reduce((a, b) => a | b);
|
|
36
|
-
}
|
|
37
34
|
;
|
|
38
35
|
;
|
|
39
36
|
;
|
package/build/esm/func/u.d.ts
CHANGED
|
@@ -2,8 +2,19 @@ import { Loggable, MaybePromise } from "../const/types";
|
|
|
2
2
|
export declare function getJSTDate(d?: Date): Date;
|
|
3
3
|
export declare function delay(sec: number): Promise<void>;
|
|
4
4
|
export declare function int2array(size: number): number[];
|
|
5
|
+
/**
|
|
6
|
+
* generate `Map` object from an array.
|
|
7
|
+
* @param array source array.
|
|
8
|
+
* @param keyGen predicate which generates map keys from a value of the array.
|
|
9
|
+
* @param op.accumulate flag whether values of the map are accumulated or not if key/value from the array conflict. default is true.
|
|
10
|
+
*/
|
|
5
11
|
export declare function array2map<K, T>(array: T[], keyGen: (e: T) => K): Map<K, T[]>;
|
|
6
|
-
export declare function
|
|
12
|
+
export declare function array2map<K, T>(array: T[], keyGen: (e: T) => K, op: {
|
|
13
|
+
accumulate: false;
|
|
14
|
+
}): Map<K, T>;
|
|
15
|
+
export declare function array2map<K, T>(array: T[], keyGen: (e: T) => K, op?: {
|
|
16
|
+
accumulate?: boolean;
|
|
17
|
+
}): Map<K, T[]>;
|
|
7
18
|
export interface RetryOption<T = MaybePromise> {
|
|
8
19
|
/**
|
|
9
20
|
* number of retries. default is 1.
|
package/build/esm/func/u.js
CHANGED
|
@@ -12,20 +12,18 @@ export function int2array(size) {
|
|
|
12
12
|
throw new XjsErr(s_errCode, "size of the argument is not number.");
|
|
13
13
|
return Array.from(Array(s).keys());
|
|
14
14
|
}
|
|
15
|
-
export function array2map(array, keyGen) {
|
|
15
|
+
export function array2map(array, keyGen, op) {
|
|
16
|
+
const _acm = op?.accumulate ?? true;
|
|
16
17
|
const map = new Map();
|
|
17
18
|
for (const e of array) {
|
|
18
19
|
const k = keyGen(e);
|
|
19
20
|
if (map.has(k))
|
|
20
|
-
map.get(k).push(e);
|
|
21
|
+
_acm && map.get(k).push(e);
|
|
21
22
|
else
|
|
22
|
-
map.set(k, [e]);
|
|
23
|
+
map.set(k, _acm ? [e] : e);
|
|
23
24
|
}
|
|
24
25
|
return map;
|
|
25
26
|
}
|
|
26
|
-
export function bitor(...bit) {
|
|
27
|
-
return bit.reduce((a, b) => a | b);
|
|
28
|
-
}
|
|
29
27
|
;
|
|
30
28
|
;
|
|
31
29
|
;
|