xjs-common 13.1.0 → 13.3.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/README.md +2 -1
- package/build/cjs/func/u-obj.js +7 -3
- package/build/cjs/func/u.js +4 -7
- package/build/esm/func/u-obj.d.ts +6 -2
- package/build/esm/func/u-obj.js +7 -3
- package/build/esm/func/u.d.ts +12 -1
- package/build/esm/func/u.js +4 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,6 @@ import { delay, int2array, UHttp, retry, MaybeArray, Loggable } from "xjs-common
|
|
|
33
33
|
|
|
34
34
|
// true
|
|
35
35
|
console.log(UHttp.isHttpSuccess(204));
|
|
36
|
-
|
|
37
36
|
// https://aaa.com?p1=a&p2=1&p2=2
|
|
38
37
|
console.log(UHttp.concatParamsWithEncoding("https://aaa.com", { p1: "a", p2: ["1", "2"] }));
|
|
39
38
|
// p1=a&p2=1&p2=2
|
|
@@ -48,6 +47,8 @@ import { UArray } from "xjs-common";
|
|
|
48
47
|
// [ 1, 3, 2, 5, 4 ]
|
|
49
48
|
const ary1 = UArray.distinct([1, 3, 2, 2, 1, 5, 4]);
|
|
50
49
|
console.log(ary1);
|
|
50
|
+
// [1, 1, 2, 2]
|
|
51
|
+
console.log(UArray.duplicate([1, 3, 2, 2, 1, 5, 4]));
|
|
51
52
|
|
|
52
53
|
// [ 5, 4 ]
|
|
53
54
|
console.log(UArray.takeOut(ary1, v => v > 3));
|
package/build/cjs/func/u-obj.js
CHANGED
|
@@ -23,12 +23,13 @@ var UObj;
|
|
|
23
23
|
return t;
|
|
24
24
|
}
|
|
25
25
|
UObj.assignProperties = assignProperties;
|
|
26
|
-
function crop(o, keys_or_ctor,
|
|
26
|
+
function crop(o, keys_or_ctor, op) {
|
|
27
|
+
const _removeKeys = !!op?.removeKeys;
|
|
27
28
|
const tm = Array.isArray(keys_or_ctor) ? null
|
|
28
29
|
: (!keys_or_ctor || o instanceof keys_or_ctor ? o[d_type_1.smbl_tm] : new keys_or_ctor()[d_type_1.smbl_tm]);
|
|
29
30
|
const _keys = tm ? Object.keys(tm) : (keys_or_ctor ?? []);
|
|
30
31
|
if (_keys.length === 0)
|
|
31
|
-
return
|
|
32
|
+
return _removeKeys ? o : {};
|
|
32
33
|
Object.keys(o).filter(k => {
|
|
33
34
|
if (tm && tm[k] && o[k]) {
|
|
34
35
|
if (tm[k].cls)
|
|
@@ -38,7 +39,10 @@ var UObj;
|
|
|
38
39
|
Object.values(o[k]).forEach(v => crop(v, vCtor));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
const rm = _removeKeys === _keys.includes(k);
|
|
43
|
+
if (!rm && op?.recursive && u_type_1.UType.isObject(o[k]))
|
|
44
|
+
crop(o[k], _keys, op);
|
|
45
|
+
return rm;
|
|
42
46
|
}).forEach(k => delete o[k]);
|
|
43
47
|
return o;
|
|
44
48
|
}
|
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
|
;
|
|
@@ -12,9 +12,13 @@ export declare namespace UObj {
|
|
|
12
12
|
* crop properties of the object other than specified. the properties are to be removed with `delete` operator.
|
|
13
13
|
* @param o object whose properties to be removed.
|
|
14
14
|
* @param keys property names to be remained.
|
|
15
|
-
* @param removeKeys if true, it removes `keys` instead of remaining it.
|
|
15
|
+
* @param op.removeKeys if true, it removes `keys` instead of remaining it.
|
|
16
|
+
* @param op.recursive whether it crops properties of an object recursively. default is false.
|
|
16
17
|
*/
|
|
17
|
-
function crop<T extends NormalRecord>(o: T, keys: (keyof T)[],
|
|
18
|
+
function crop<T extends NormalRecord>(o: T, keys: (keyof T)[], op?: {
|
|
19
|
+
removeKeys?: boolean;
|
|
20
|
+
recursive?: boolean;
|
|
21
|
+
}): Partial<T>;
|
|
18
22
|
/**
|
|
19
23
|
* crop properties that is not decorated with {@link DType}. the properties will be removed with `delete` operator.
|
|
20
24
|
* this treats constructual decorator such as {@link DType.object} recursively.
|
package/build/esm/func/u-obj.js
CHANGED
|
@@ -20,12 +20,13 @@ export var UObj;
|
|
|
20
20
|
return t;
|
|
21
21
|
}
|
|
22
22
|
UObj.assignProperties = assignProperties;
|
|
23
|
-
function crop(o, keys_or_ctor,
|
|
23
|
+
function crop(o, keys_or_ctor, op) {
|
|
24
|
+
const _removeKeys = !!op?.removeKeys;
|
|
24
25
|
const tm = Array.isArray(keys_or_ctor) ? null
|
|
25
26
|
: (!keys_or_ctor || o instanceof keys_or_ctor ? o[smbl_tm] : new keys_or_ctor()[smbl_tm]);
|
|
26
27
|
const _keys = tm ? Object.keys(tm) : (keys_or_ctor ?? []);
|
|
27
28
|
if (_keys.length === 0)
|
|
28
|
-
return
|
|
29
|
+
return _removeKeys ? o : {};
|
|
29
30
|
Object.keys(o).filter(k => {
|
|
30
31
|
if (tm && tm[k] && o[k]) {
|
|
31
32
|
if (tm[k].cls)
|
|
@@ -35,7 +36,10 @@ export var UObj;
|
|
|
35
36
|
Object.values(o[k]).forEach(v => crop(v, vCtor));
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
const rm = _removeKeys === _keys.includes(k);
|
|
40
|
+
if (!rm && op?.recursive && UType.isObject(o[k]))
|
|
41
|
+
crop(o[k], _keys, op);
|
|
42
|
+
return rm;
|
|
39
43
|
}).forEach(k => delete o[k]);
|
|
40
44
|
return o;
|
|
41
45
|
}
|
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
|
;
|