xjs-common 8.3.0 → 8.4.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
@@ -1,4 +1,4 @@
1
- [![CI](https://github.com/begyyal/xjs_commons/actions/workflows/test.yml/badge.svg)](https://github.com/begyyal/xjs_commons/actions/workflows/test.yml)
1
+ [![npm][npm-badge]][npm-url] [![CI][ci-badge]][ci-url]
2
2
 
3
3
  # Overview
4
4
  Library modules for nodejs + typescript that bundled general-purpose implementations.
@@ -219,3 +219,8 @@ XJS throws error with `code` property which has one of the following numbers.
219
219
 
220
220
  # License
221
221
  [Apache-License](./LICENSE)
222
+
223
+ [npm-url]: https://npmjs.org/package/xjs-common
224
+ [npm-badge]: https://badgen.net/npm/v/xjs-common
225
+ [ci-url]: https://github.com/begyyal/xjs_commons/actions/workflows/test.yml
226
+ [ci-badge]: https://github.com/begyyal/xjs_commons/actions/workflows/test.yml/badge.svg
@@ -0,0 +1,18 @@
1
+ export interface Ccy {
2
+ symbol: t_ccySymbol;
3
+ crossUsd: string;
4
+ }
5
+ export type t_ccySymbol = keyof (typeof currencies);
6
+ declare const currencies: {
7
+ jpy: Ccy;
8
+ usd: Ccy;
9
+ gbp: Ccy;
10
+ eur: Ccy;
11
+ cad: Ccy;
12
+ aud: Ccy;
13
+ };
14
+ export declare const s_ccy: {
15
+ [k in t_ccySymbol]: Readonly<Ccy>;
16
+ };
17
+ export declare function resolveCcy(str: string): Ccy;
18
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveCcy = exports.s_ccy = void 0;
4
+ const currencies = {
5
+ jpy: { crossUsd: "usd/jpy" },
6
+ usd: { crossUsd: null },
7
+ gbp: { crossUsd: "gbp/usd" },
8
+ eur: { crossUsd: "eur/usd" },
9
+ cad: { crossUsd: "cad/usd" },
10
+ aud: { crossUsd: "aud/usd" }
11
+ };
12
+ exports.s_ccy = (() => {
13
+ Object.entries(currencies).forEach(kv => { kv[1].symbol = kv[0]; currencies[kv[0]] = Object.freeze(kv[1]); });
14
+ return Object.freeze(currencies);
15
+ })();
16
+ function resolveCcy(str) {
17
+ const ccyKey = Object.keys(exports.s_ccy).find(k => str?.toLowerCase() == k);
18
+ return ccyKey && exports.s_ccy[ccyKey];
19
+ }
20
+ exports.resolveCcy = resolveCcy;
@@ -9,5 +9,5 @@ export declare namespace UFile {
9
9
  function read(p: MaybeArray<string>, encoding: BufferEncoding): string;
10
10
  function cp(from: MaybeArray<string>, to: MaybeArray<string>): void;
11
11
  function mv(from: MaybeArray<string>, to: MaybeArray<string>): void;
12
- function joinPath(p: MaybeArray<string>): string;
12
+ function joinPath(...p: MaybeArray<string>[]): string;
13
13
  }
@@ -74,8 +74,8 @@ var UFile;
74
74
  fs.renameSync(f, t);
75
75
  }
76
76
  UFile.mv = mv;
77
- function joinPath(p) {
78
- return u_type_1.UType.isString(p) ? p : path.join(...p);
77
+ function joinPath(...p) {
78
+ return path.join(...p.flatMap(u_type_1.UType.takeAsArray));
79
79
  }
80
80
  UFile.joinPath = joinPath;
81
81
  })(UFile = exports.UFile || (exports.UFile = {}));
@@ -15,4 +15,10 @@ export declare namespace UString {
15
15
  function generateRandomString(len: number): string;
16
16
  function idx2az(idx: number): string;
17
17
  function az2idx(az: string): number;
18
+ function is_yyyy(v: string): boolean;
19
+ function is_yyyyMM(v: string): boolean;
20
+ function is_yyyyMMdd(v: string): boolean;
21
+ function is_yyyyMMddhh(v: string): boolean;
22
+ function is_yyyyMMddhhmm(v: string): boolean;
23
+ function is_yyyyMMddhhmmss(v: string): boolean;
18
24
  }
@@ -59,4 +59,28 @@ var UString;
59
59
  .map((idx, i) => (idx + 1) * (26 ** i)).reduce((v1, v2) => v1 + v2) - 1;
60
60
  }
61
61
  UString.az2idx = az2idx;
62
+ function is_yyyy(v) {
63
+ return !!v?.match(/^[1-9]\d{3}$/);
64
+ }
65
+ UString.is_yyyy = is_yyyy;
66
+ function is_yyyyMM(v) {
67
+ return !!v?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])$/);
68
+ }
69
+ UString.is_yyyyMM = is_yyyyMM;
70
+ function is_yyyyMMdd(v) {
71
+ return !!v?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])$/);
72
+ }
73
+ UString.is_yyyyMMdd = is_yyyyMMdd;
74
+ function is_yyyyMMddhh(v) {
75
+ return !!v?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])(0[1-9]|1\d|2[0-3])$/);
76
+ }
77
+ UString.is_yyyyMMddhh = is_yyyyMMddhh;
78
+ function is_yyyyMMddhhmm(v) {
79
+ return !!v?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])(0[1-9]|1\d|2[0-3])[0-5]\d$/);
80
+ }
81
+ UString.is_yyyyMMddhhmm = is_yyyyMMddhhmm;
82
+ function is_yyyyMMddhhmmss(v) {
83
+ return !!v?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])(0[1-9]|1\d|2[0-3])[0-5]\d[0-5]\d$/);
84
+ }
85
+ UString.is_yyyyMMddhhmmss = is_yyyyMMddhhmmss;
62
86
  })(UString = exports.UString || (exports.UString = {}));
package/dist/func/u.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare function int2array(size: number): number[];
5
5
  export declare function array2map<K, T>(array: T[], keyGen: (e: T) => K): Map<K, T[]>;
6
6
  export declare function bitor(...bit: number[]): number;
7
7
  export declare function checkPortAvailability(port: number): Promise<boolean>;
8
- interface RetryOption<T = void | Promise<void>> {
8
+ export interface RetryOption<T = void | Promise<void>> {
9
9
  count?: number;
10
10
  logger?: Loggable;
11
11
  errorCriterion?: (e: any) => boolean;
@@ -23,4 +23,3 @@ export declare function retry<T>(cb: () => T, op?: RetryOption<void>): T;
23
23
  export declare function retry<T>(cb: () => T, op?: RetryOption<Promise<void>>): Promise<T>;
24
24
  export declare function retry<T>(cb: () => Promise<T>, op?: RetryOption<void>): Promise<T>;
25
25
  export declare function retry<T>(cb: () => Promise<T>, op?: RetryOption<Promise<void>>): Promise<T>;
26
- export {};
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./const/types";
2
2
  export * from "./const/time-unit";
3
3
  export * from "./const/gender";
4
4
  export * from "./const/http-method";
5
+ export * from "./const/ccy";
5
6
  export * from "./func/u";
6
7
  export * from "./func/u-obj";
7
8
  export * from "./func/u-string";
package/dist/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./const/types"), exports);
19
19
  __exportStar(require("./const/time-unit"), exports);
20
20
  __exportStar(require("./const/gender"), exports);
21
21
  __exportStar(require("./const/http-method"), exports);
22
+ __exportStar(require("./const/ccy"), exports);
22
23
  __exportStar(require("./func/u"), exports);
23
24
  __exportStar(require("./func/u-obj"), exports);
24
25
  __exportStar(require("./func/u-string"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "library modules for nodejs + typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",