xjs-common 13.2.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 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));
@@ -23,12 +23,13 @@ var UObj;
23
23
  return t;
24
24
  }
25
25
  UObj.assignProperties = assignProperties;
26
- function crop(o, keys_or_ctor, removeKeys) {
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 removeKeys ? o : {};
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
- return !!removeKeys === _keys.includes(k);
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
  }
@@ -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)[], removeKeys?: boolean): Partial<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.
@@ -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, removeKeys) {
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 removeKeys ? o : {};
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
- return !!removeKeys === _keys.includes(k);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "13.2.0",
3
+ "version": "13.3.0",
4
4
  "description": "library modules for typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",