xjs-common 13.5.2 → 13.6.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-array.js +1 -1
- package/build/cjs/func/u-string.js +1 -1
- package/build/cjs/func/u.js +14 -0
- package/build/esm/func/u-array.js +1 -1
- package/build/esm/func/u-string.d.ts +1 -1
- package/build/esm/func/u-string.js +1 -1
- package/build/esm/func/u.d.ts +3 -1
- package/build/esm/func/u.js +13 -0
- package/package.json +1 -1
|
@@ -44,7 +44,7 @@ var UArray;
|
|
|
44
44
|
if (!array || array.length === 0)
|
|
45
45
|
return [];
|
|
46
46
|
if (op?.k)
|
|
47
|
-
return Array.from(array2_1.Array2.map(array, e => e[op.k]).values()).filter(a => a.length > 1).
|
|
47
|
+
return Array.from(array2_1.Array2.map(array, e => e[op.k]).values()).filter(a => a.length > 1).flat();
|
|
48
48
|
const a = [...array], result = [];
|
|
49
49
|
const p = op?.predicate ?? ((v1, v2) => v1 == v2);
|
|
50
50
|
while (a.length > 0) {
|
|
@@ -17,7 +17,7 @@ var UString;
|
|
|
17
17
|
}
|
|
18
18
|
UString.repeat = repeat;
|
|
19
19
|
/**
|
|
20
|
-
* generate date time number as fixed length (depends on `unit`) string without separator
|
|
20
|
+
* generate date time number as fixed length (depends on `unit`) string without separator character.
|
|
21
21
|
* For example, `2025-06-08T10:15:06.366Z` is to be `20250608101506366`.
|
|
22
22
|
* @param op.date Date object referred by this. default is `new Date()`.
|
|
23
23
|
* @param op.unit time unit. default is second.
|
package/build/cjs/func/u.js
CHANGED
|
@@ -5,6 +5,8 @@ exports.delay = delay;
|
|
|
5
5
|
exports.int2array = int2array;
|
|
6
6
|
exports.retry = retry;
|
|
7
7
|
exports.valueof = valueof;
|
|
8
|
+
exports.toMsec = toMsec;
|
|
9
|
+
const time_unit_1 = require("../const/time-unit");
|
|
8
10
|
const xjs_err_1 = require("../obj/xjs-err");
|
|
9
11
|
const u_type_1 = require("./u-type");
|
|
10
12
|
const s_errCode = 10;
|
|
@@ -91,3 +93,15 @@ function retry(cb, op) {
|
|
|
91
93
|
function valueof(o, v) {
|
|
92
94
|
return Object.values(o).find(v2 => v2 === v);
|
|
93
95
|
}
|
|
96
|
+
function toMsec(value, unit) {
|
|
97
|
+
let v = value;
|
|
98
|
+
if (unit <= time_unit_1.TimeUnit.Sec)
|
|
99
|
+
v *= 1000;
|
|
100
|
+
if (unit <= time_unit_1.TimeUnit.Min)
|
|
101
|
+
v *= 60;
|
|
102
|
+
if (unit <= time_unit_1.TimeUnit.Hour)
|
|
103
|
+
v *= 60;
|
|
104
|
+
if (unit <= time_unit_1.TimeUnit.Day)
|
|
105
|
+
v *= 24;
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
@@ -41,7 +41,7 @@ export var UArray;
|
|
|
41
41
|
if (!array || array.length === 0)
|
|
42
42
|
return [];
|
|
43
43
|
if (op?.k)
|
|
44
|
-
return Array.from(Array2.map(array, e => e[op.k]).values()).filter(a => a.length > 1).
|
|
44
|
+
return Array.from(Array2.map(array, e => e[op.k]).values()).filter(a => a.length > 1).flat();
|
|
45
45
|
const a = [...array], result = [];
|
|
46
46
|
const p = op?.predicate ?? ((v1, v2) => v1 == v2);
|
|
47
47
|
while (a.length > 0) {
|
|
@@ -3,7 +3,7 @@ export declare namespace UString {
|
|
|
3
3
|
function eq(s1: string, s2: string): boolean;
|
|
4
4
|
function repeat(token: string, mlt: number): string;
|
|
5
5
|
/**
|
|
6
|
-
* generate date time number as fixed length (depends on `unit`) string without separator
|
|
6
|
+
* generate date time number as fixed length (depends on `unit`) string without separator character.
|
|
7
7
|
* For example, `2025-06-08T10:15:06.366Z` is to be `20250608101506366`.
|
|
8
8
|
* @param op.date Date object referred by this. default is `new Date()`.
|
|
9
9
|
* @param op.unit time unit. default is second.
|
|
@@ -14,7 +14,7 @@ export var UString;
|
|
|
14
14
|
}
|
|
15
15
|
UString.repeat = repeat;
|
|
16
16
|
/**
|
|
17
|
-
* generate date time number as fixed length (depends on `unit`) string without separator
|
|
17
|
+
* generate date time number as fixed length (depends on `unit`) string without separator character.
|
|
18
18
|
* For example, `2025-06-08T10:15:06.366Z` is to be `20250608101506366`.
|
|
19
19
|
* @param op.date Date object referred by this. default is `new Date()`.
|
|
20
20
|
* @param op.unit time unit. default is second.
|
package/build/esm/func/u.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TimeUnit } from "../const/time-unit";
|
|
1
2
|
import { IndexSignature, Loggable, MaybePromise } from "../const/types";
|
|
2
3
|
export declare function getJSTDate(d?: Date | number): Date;
|
|
3
4
|
export declare function delay(sec: number): Promise<void>;
|
|
@@ -12,7 +13,7 @@ export interface RetryOption<T = MaybePromise> {
|
|
|
12
13
|
*/
|
|
13
14
|
logger?: Loggable;
|
|
14
15
|
/**
|
|
15
|
-
* distinguish whether retry is required
|
|
16
|
+
* distinguish whether retry is required from exceptions. default is none. (i.e. always required.)
|
|
16
17
|
*/
|
|
17
18
|
errorCriterion?: (e: any) => boolean;
|
|
18
19
|
/**
|
|
@@ -55,3 +56,4 @@ export declare function retry<T>(cb: () => Promise<T>, op?: AsyncRetryOption): P
|
|
|
55
56
|
export declare function valueof<E extends {
|
|
56
57
|
[k: string]: IndexSignature;
|
|
57
58
|
}>(o: E, v: IndexSignature): (typeof o)[keyof typeof o];
|
|
59
|
+
export declare function toMsec(value: number, unit: TimeUnit.Sec | TimeUnit.Min | TimeUnit.Hour | TimeUnit.Day): number;
|
package/build/esm/func/u.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TimeUnit } from "../const/time-unit";
|
|
1
2
|
import { XjsErr } from "../obj/xjs-err";
|
|
2
3
|
import { UType } from "./u-type";
|
|
3
4
|
const s_errCode = 10;
|
|
@@ -84,3 +85,15 @@ export function retry(cb, op) {
|
|
|
84
85
|
export function valueof(o, v) {
|
|
85
86
|
return Object.values(o).find(v2 => v2 === v);
|
|
86
87
|
}
|
|
88
|
+
export function toMsec(value, unit) {
|
|
89
|
+
let v = value;
|
|
90
|
+
if (unit <= TimeUnit.Sec)
|
|
91
|
+
v *= 1000;
|
|
92
|
+
if (unit <= TimeUnit.Min)
|
|
93
|
+
v *= 60;
|
|
94
|
+
if (unit <= TimeUnit.Hour)
|
|
95
|
+
v *= 60;
|
|
96
|
+
if (unit <= TimeUnit.Day)
|
|
97
|
+
v *= 24;
|
|
98
|
+
return v;
|
|
99
|
+
}
|