xjs-common 13.5.0 → 13.5.1

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
@@ -14,7 +14,7 @@ if you has been used the features (e.g. `HttpResolver`, `UFile`), please use the
14
14
  # Code example (only part)
15
15
  ### Miscellaneous utilities.
16
16
  ```ts
17
- import { delay, int2array, UHttp, retry, MaybeArray, Loggable } from "xjs-common";
17
+ import { delay, int2array, UHttp, retry, MaybeArray, Loggable, valueof } from "xjs-common";
18
18
 
19
19
  (async () => {
20
20
  // await 3 seconds.
@@ -35,8 +35,9 @@ import { delay, int2array, UHttp, retry, MaybeArray, Loggable } from "xjs-common
35
35
  console.log(UHttp.isHttpSuccess(204));
36
36
  // https://aaa.com?p1=a&p2=1&p2=2
37
37
  console.log(UHttp.concatParamsWithEncoding("https://aaa.com", { p1: "a", p2: ["1", "2"] }));
38
- // p1=a&p2=1&p2=2
39
- console.log(UHttp.concatParamsWithEncoding(null, { p1: "a", p2: ["1", "2"] }));
38
+ // checks and casts a value like enum valueof.
39
+ enum EnumA { A = "a", B = "b" }
40
+ const e: EnumA = valueof(EnumA, "a");
40
41
  })();
41
42
  ```
42
43
  ### Array utilities.
@@ -4,6 +4,7 @@ exports.getJSTDate = getJSTDate;
4
4
  exports.delay = delay;
5
5
  exports.int2array = int2array;
6
6
  exports.retry = retry;
7
+ exports.valueof = valueof;
7
8
  const xjs_err_1 = require("../obj/xjs-err");
8
9
  const u_type_1 = require("./u-type");
9
10
  const s_errCode = 10;
@@ -76,3 +77,17 @@ function retry(cb, op) {
76
77
  };
77
78
  return prcs(initialCount);
78
79
  }
80
+ /**
81
+ * this checks whether the object (**mainly enum**) has the value or not.
82
+ * if true this returns the value as value type of the object.
83
+ * ```js
84
+ * enum EnumA {
85
+ * A = "a",
86
+ * B = "b"
87
+ * }
88
+ * const enm: EnumA = valueof(EnumA, "a");
89
+ * ```
90
+ */
91
+ function valueof(o, v) {
92
+ return Object.values(o).find(v2 => v2 === v);
93
+ }
@@ -1,4 +1,4 @@
1
- import { Loggable, MaybePromise } from "../const/types";
1
+ import { IndexSignature, Loggable, MaybePromise } from "../const/types";
2
2
  export declare function getJSTDate(d?: Date | number): Date;
3
3
  export declare function delay(sec: number): Promise<void>;
4
4
  export declare function int2array(size: number): number[];
@@ -41,3 +41,17 @@ export declare function retry<T>(cb: () => T, op?: SyncRetryOption): T;
41
41
  export declare function retry<T>(cb: () => T, op?: AsyncRetryOption): Promise<T>;
42
42
  export declare function retry<T>(cb: () => Promise<T>, op?: SyncRetryOption): Promise<T>;
43
43
  export declare function retry<T>(cb: () => Promise<T>, op?: AsyncRetryOption): Promise<T>;
44
+ /**
45
+ * this checks whether the object (**mainly enum**) has the value or not.
46
+ * if true this returns the value as value type of the object.
47
+ * ```js
48
+ * enum EnumA {
49
+ * A = "a",
50
+ * B = "b"
51
+ * }
52
+ * const enm: EnumA = valueof(EnumA, "a");
53
+ * ```
54
+ */
55
+ export declare function valueof<E extends {
56
+ [k: string]: IndexSignature;
57
+ }>(o: E, v: IndexSignature): (typeof o)[keyof typeof o];
@@ -70,3 +70,17 @@ export function retry(cb, op) {
70
70
  };
71
71
  return prcs(initialCount);
72
72
  }
73
+ /**
74
+ * this checks whether the object (**mainly enum**) has the value or not.
75
+ * if true this returns the value as value type of the object.
76
+ * ```js
77
+ * enum EnumA {
78
+ * A = "a",
79
+ * B = "b"
80
+ * }
81
+ * const enm: EnumA = valueof(EnumA, "a");
82
+ * ```
83
+ */
84
+ export function valueof(o, v) {
85
+ return Object.values(o).find(v2 => v2 === v);
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "13.5.0",
3
+ "version": "13.5.1",
4
4
  "description": "library modules for typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",