@qwreey-js/tsutil 1.0.0 → 1.0.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.
@@ -0,0 +1,22 @@
1
+ export declare class CachedGetter<Res> {
2
+ private func;
3
+ private interval;
4
+ private value?;
5
+ private last?;
6
+ constructor(func: () => Promise<Res>, interval: number);
7
+ getValue(): Promise<Res>;
8
+ }
9
+ export declare class CachedGetterMap<Res, Key> {
10
+ private func;
11
+ private interval;
12
+ private values;
13
+ constructor(func: (key: Key) => Promise<Res>, interval: number);
14
+ getValue(key: Key): Promise<Res>;
15
+ }
16
+ export declare namespace CachedGetterMap {
17
+ type Record<Res> = {
18
+ value: Promise<Res>;
19
+ last: number;
20
+ };
21
+ }
22
+ //# sourceMappingURL=cached-getter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cached-getter.d.ts","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY,CAAC,GAAG;IAC3B,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAS;gBAEH,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM;IAKhD,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC;CAStC;AAED,qBAAa,eAAe,CAAC,GAAG,EAAE,GAAG;IACnC,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAwC;gBAEnC,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM;IAMxD,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAc9C;AACD,yBAAiB,eAAe,CAAC;IAC/B,KAAY,MAAM,CAAC,GAAG,IAAI;QACxB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH"}
@@ -0,0 +1,43 @@
1
+ export class CachedGetter {
2
+ func;
3
+ interval;
4
+ value;
5
+ last;
6
+ constructor(func, interval) {
7
+ this.func = func;
8
+ this.interval = interval;
9
+ }
10
+ async getValue() {
11
+ const curr = +new Date();
12
+ if (!this.value || !this.last || this.last + this.interval < curr) {
13
+ this.last = curr;
14
+ this.value = this.func();
15
+ return await this.value;
16
+ }
17
+ return await this.value;
18
+ }
19
+ }
20
+ export class CachedGetterMap {
21
+ func;
22
+ interval;
23
+ values;
24
+ constructor(func, interval) {
25
+ this.func = func;
26
+ this.values = new Map();
27
+ this.interval = interval;
28
+ }
29
+ async getValue(key) {
30
+ const curr = +new Date();
31
+ const record = this.values.get(key);
32
+ if (!record || record.last + this.interval < curr) {
33
+ const value = this.func(key);
34
+ this.values.set(key, {
35
+ last: curr,
36
+ value,
37
+ });
38
+ return await value;
39
+ }
40
+ return await record.value;
41
+ }
42
+ }
43
+ //# sourceMappingURL=cached-getter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cached-getter.js","sourceRoot":"","sources":["../src/cached-getter.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAY;IACf,IAAI,CAAqB;IACzB,QAAQ,CAAS;IACjB,KAAK,CAAgB;IACrB,IAAI,CAAU;IAEtB,YAAmB,IAAwB,EAAE,QAAgB;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC;YAClE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YACzB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC;QAC1B,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IAClB,IAAI,CAA6B;IACjC,QAAQ,CAAS;IACjB,MAAM,CAAwC;IAEtD,YAAmB,IAAgC,EAAE,QAAgB;QACnE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,GAAQ;QAC5B,MAAM,IAAI,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEpC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,EAAE,CAAC;YAClD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE;gBACnB,IAAI,EAAE,IAAI;gBACV,KAAK;aACN,CAAC,CAAC;YACH,OAAO,MAAM,KAAK,CAAC;QACrB,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC;IAC5B,CAAC;CACF"}
package/dist/date.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare namespace DateUtil {
2
+ function removeTime(dateTime: Date): Date;
3
+ function removeDay(dateTime: Date): Date;
4
+ function formatYYYYMMDD(date: Date): string;
5
+ function formatUTCYYYYMMDD(date: Date): string;
6
+ function fromUTCYYYMMDD(str: string): Date;
7
+ function formatUTCHHMMSS(date: Date): string;
8
+ }
9
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAKA,yBAAiB,QAAQ,CAAC;IACxB,SAAgB,UAAU,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAM/C;IAED,SAAgB,SAAS,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAE9C;IAED,SAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEjD;IACD,SAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEpD;IACD,SAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAIhD;IACD,SAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAElD;CACF"}
package/dist/date.js ADDED
@@ -0,0 +1,33 @@
1
+ function zeroPadding(value) {
2
+ if (value > 10)
3
+ return value.toString();
4
+ return "0" + value.toString();
5
+ }
6
+ export var DateUtil;
7
+ (function (DateUtil) {
8
+ function removeTime(dateTime) {
9
+ return new Date(dateTime.getFullYear(), dateTime.getMonth(), dateTime.getDate());
10
+ }
11
+ DateUtil.removeTime = removeTime;
12
+ function removeDay(dateTime) {
13
+ return new Date(dateTime.getFullYear(), dateTime.getMonth());
14
+ }
15
+ DateUtil.removeDay = removeDay;
16
+ function formatYYYYMMDD(date) {
17
+ return `${date.getFullYear()}-${zeroPadding(date.getMonth() + 1)}-${zeroPadding(date.getDate())}`;
18
+ }
19
+ DateUtil.formatYYYYMMDD = formatYYYYMMDD;
20
+ function formatUTCYYYYMMDD(date) {
21
+ return `${date.getUTCFullYear()}-${zeroPadding(date.getUTCMonth() + 1)}-${zeroPadding(date.getUTCDate())}`;
22
+ }
23
+ DateUtil.formatUTCYYYYMMDD = formatUTCYYYYMMDD;
24
+ function fromUTCYYYMMDD(str) {
25
+ return new Date(`${str.slice(0, 4)}-${str.slice(5, 7)}-${str.slice(8, 10)}T00:00:00.000Z`);
26
+ }
27
+ DateUtil.fromUTCYYYMMDD = fromUTCYYYMMDD;
28
+ function formatUTCHHMMSS(date) {
29
+ return `${zeroPadding(date.getUTCHours())}:${zeroPadding(date.getUTCMinutes())}:${zeroPadding(date.getUTCSeconds())}`;
30
+ }
31
+ DateUtil.formatUTCHHMMSS = formatUTCHHMMSS;
32
+ })(DateUtil || (DateUtil = {}));
33
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACxC,OAAO,GAAG,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,KAAW,QAAQ,CA2BxB;AA3BD,WAAiB,QAAQ;IACvB,SAAgB,UAAU,CAAC,QAAc;QACvC,OAAO,IAAI,IAAI,CACb,QAAQ,CAAC,WAAW,EAAE,EACtB,QAAQ,CAAC,QAAQ,EAAE,EACnB,QAAQ,CAAC,OAAO,EAAE,CACnB,CAAC;IACJ,CAAC;IANe,mBAAU,aAMzB,CAAA;IAED,SAAgB,SAAS,CAAC,QAAc;QACtC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/D,CAAC;IAFe,kBAAS,YAExB,CAAA;IAED,SAAgB,cAAc,CAAC,IAAU;QACvC,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;IACpG,CAAC;IAFe,uBAAc,iBAE7B,CAAA;IACD,SAAgB,iBAAiB,CAAC,IAAU;QAC1C,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;IAC7G,CAAC;IAFe,0BAAiB,oBAEhC,CAAA;IACD,SAAgB,cAAc,CAAC,GAAW;QACxC,OAAO,IAAI,IAAI,CACb,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAC1E,CAAC;IACJ,CAAC;IAJe,uBAAc,iBAI7B,CAAA;IACD,SAAgB,eAAe,CAAC,IAAU;QACxC,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,CAAC;IACxH,CAAC;IAFe,wBAAe,kBAE9B,CAAA;AACH,CAAC,EA3BgB,QAAQ,KAAR,QAAQ,QA2BxB"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
+ export * from "./cached-getter.js";
2
+ export * from "./date.js";
3
+ export * from "./interval.js";
4
+ export * from "./json.js";
1
5
  export * from "./mixin.js";
6
+ export * from "./promise.js";
7
+ export * from "./result.js";
2
8
  export * from "./utils.js";
9
+ import { setLogErr as _setLogErr } from "./libLog.js";
10
+ export declare namespace UtilLogging {
11
+ const setLogErr: typeof _setLogErr;
12
+ const logErr: import("./libLog.js").LogErr;
13
+ }
3
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,SAAS,IAAI,UAAU,EAAqB,MAAM,aAAa,CAAC;AACzE,yBAAiB,WAAW,CAAC;IACpB,MAAM,SAAS,mBAAa,CAAC;IAC7B,MAAM,MAAM,8BAAU,CAAC;CAC/B"}
package/dist/index.js CHANGED
@@ -1,3 +1,15 @@
1
+ export * from "./cached-getter.js";
2
+ export * from "./date.js";
3
+ export * from "./interval.js";
4
+ export * from "./json.js";
1
5
  export * from "./mixin.js";
6
+ export * from "./promise.js";
7
+ export * from "./result.js";
2
8
  export * from "./utils.js";
9
+ import { setLogErr as _setLogErr, logErr as _logErr } from "./libLog.js";
10
+ export var UtilLogging;
11
+ (function (UtilLogging) {
12
+ UtilLogging.setLogErr = _setLogErr;
13
+ UtilLogging.logErr = _logErr;
14
+ })(UtilLogging || (UtilLogging = {}));
3
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,SAAS,IAAI,UAAU,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AACzE,MAAM,KAAW,WAAW,CAG3B;AAHD,WAAiB,WAAW;IACb,qBAAS,GAAG,UAAU,CAAC;IACvB,kBAAM,GAAG,OAAO,CAAC;AAChC,CAAC,EAHgB,WAAW,KAAX,WAAW,QAG3B"}
@@ -0,0 +1,16 @@
1
+ export declare class Interval {
2
+ private func;
3
+ private interval;
4
+ private id?;
5
+ private running;
6
+ private name;
7
+ constructor(func: Function, interval: number, name?: string);
8
+ run(): void;
9
+ drop(): void;
10
+ executeAsync(): Promise<void>;
11
+ execute(options?: {
12
+ runTimerAfterExecute?: boolean;
13
+ runIn?: number;
14
+ }): void;
15
+ }
16
+ //# sourceMappingURL=interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAMA,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,EAAE,CAAC,CAAM;IACjB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAS;gBAGnB,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,MAAkB;IAQnB,GAAG;IAgBH,IAAI;IAQE,YAAY;IAWlB,OAAO,CACZ,OAAO,GAAE;QACP,oBAAoB,CAAC,EAAE,OAAO,CAAC;QAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;KACX;CAST"}
@@ -0,0 +1,63 @@
1
+ import { logErr } from "./libLog.js";
2
+ // 입력받은 시간을 기준으로 함수를 반복 실행합니다.
3
+ // 처음 실행되지는 않습니다. drop 하거나 execute 할 수 있습니다
4
+ // execute 시 시간은 초기화됩니다 (0 초 부터 다시 카운팅)
5
+ // 내부 구현은 setInterval 로 구현됩니다
6
+ export class Interval {
7
+ func;
8
+ interval;
9
+ id;
10
+ running;
11
+ name;
12
+ constructor(func, interval, name = "default") {
13
+ this.func = func;
14
+ this.interval = interval;
15
+ this.running = false;
16
+ this.name = name;
17
+ }
18
+ run() {
19
+ if (this.running) {
20
+ throw Error("interval already started");
21
+ }
22
+ this.running = true;
23
+ this.id = setTimeout(async () => {
24
+ try {
25
+ await (this.func() ?? null);
26
+ }
27
+ catch (e) {
28
+ logErr(`interval failed(${this.name}): ${e}`);
29
+ }
30
+ this.running = false;
31
+ this.run();
32
+ }, this.interval);
33
+ }
34
+ drop() {
35
+ this.running = false;
36
+ if (this.id) {
37
+ clearTimeout(this.id);
38
+ delete this.id;
39
+ }
40
+ }
41
+ async executeAsync() {
42
+ const running = this.running;
43
+ if (running)
44
+ this.drop();
45
+ try {
46
+ await (this.func() ?? null);
47
+ }
48
+ catch (e) {
49
+ logErr(`interval failed(${this.name}): ${e}`);
50
+ }
51
+ if (running)
52
+ this.run();
53
+ }
54
+ execute(options = {}) {
55
+ setTimeout(async () => {
56
+ await this.executeAsync();
57
+ if (options.runTimerAfterExecute && !this.running) {
58
+ this.run();
59
+ }
60
+ }, options.runIn ?? 0);
61
+ }
62
+ }
63
+ //# sourceMappingURL=interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.js","sourceRoot":"","sources":["../src/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,8BAA8B;AAC9B,2CAA2C;AAC3C,uCAAuC;AACvC,6BAA6B;AAC7B,MAAM,OAAO,QAAQ;IACX,IAAI,CAAW;IACf,QAAQ,CAAS;IACjB,EAAE,CAAO;IACT,OAAO,CAAU;IACjB,IAAI,CAAS;IAErB,YACE,IAAc,EACd,QAAgB,EAChB,OAAe,SAAS;QAExB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,GAAG;QACR,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,KAAK,IAAI,EAAE;YAC9B,IAAI,CAAC;gBACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC;YAC9B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,mBAAmB,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;YAChD,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAQ,CAAC;IAC3B,CAAC;IAEM,IAAI;QACT,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,YAAY,CAAC,IAAI,CAAC,EAAS,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,OAAO;YAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,mBAAmB,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,OAAO;YAAE,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAEM,OAAO,CACZ,UAGI,EAAE;QAEN,UAAU,CAAC,KAAK,IAAI,EAAE;YACpB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1B,IAAI,OAAO,CAAC,oBAAoB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClD,IAAI,CAAC,GAAG,EAAE,CAAC;YACb,CAAC;QACH,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;IACzB,CAAC;CACF"}
package/dist/json.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function parseJsonSafe<T = any>(content: string | undefined | null): T | null;
2
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,GAAG,GAAG,EACnC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GACjC,CAAC,GAAG,IAAI,CAOV"}
package/dist/json.js ADDED
@@ -0,0 +1,11 @@
1
+ export function parseJsonSafe(content) {
2
+ if (!content)
3
+ return null;
4
+ try {
5
+ return JSON.parse(content);
6
+ }
7
+ catch (e) {
8
+ return null;
9
+ }
10
+ }
11
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAC3B,OAAkC;IAElC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ export type LogErr = (msg: string) => any;
2
+ export declare const logErr: LogErr;
3
+ export declare function setLogErr(newLogger: LogErr): void;
4
+ //# sourceMappingURL=libLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libLog.d.ts","sourceRoot":"","sources":["../src/libLog.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;AAG1C,eAAO,MAAM,MAAM,EAAE,MAEpB,CAAC;AACF,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,QAE1C"}
package/dist/libLog.js ADDED
@@ -0,0 +1,8 @@
1
+ let logErrInner = console.log.bind(console);
2
+ export const logErr = (msg) => {
3
+ logErr(msg);
4
+ };
5
+ export function setLogErr(newLogger) {
6
+ logErrInner = newLogger;
7
+ }
8
+ //# sourceMappingURL=libLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libLog.js","sourceRoot":"","sources":["../src/libLog.ts"],"names":[],"mappings":"AAEA,IAAI,WAAW,GAAW,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,MAAM,GAAW,CAAC,GAAW,EAAE,EAAE;IAC5C,MAAM,CAAC,GAAG,CAAC,CAAC;AACd,CAAC,CAAC;AACF,MAAM,UAAU,SAAS,CAAC,SAAiB;IACzC,WAAW,GAAG,SAAS,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare function AsOk(promise: Promise<any>): Promise<boolean>;
2
+ export declare function NullCatch<T>(promise: Promise<T>): Promise<T | null>;
3
+ export declare function EmptyPromise(): Promise<undefined>;
4
+ export declare function ErrorPromise(err: Error): Promise<any>;
5
+ //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAEA,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAO5D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAKnE;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC,CAAG;AAC3D,wBAAsB,YAAY,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAE3D"}
@@ -0,0 +1,20 @@
1
+ import { logErr } from "./libLog.js";
2
+ export function AsOk(promise) {
3
+ return promise
4
+ .then((_) => true)
5
+ .catch((i) => {
6
+ logErr("Promise throw(catch in AsOk): " + i);
7
+ return false;
8
+ });
9
+ }
10
+ export function NullCatch(promise) {
11
+ return promise.catch((i) => {
12
+ logErr("Promise throw(catch in NullCatch): " + i);
13
+ return null;
14
+ });
15
+ }
16
+ export async function EmptyPromise() { }
17
+ export async function ErrorPromise(err) {
18
+ throw err;
19
+ }
20
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,IAAI,CAAC,OAAqB;IACxC,OAAO,OAAO;SACX,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;SACjB,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACX,MAAM,CAAC,gCAAgC,GAAG,CAAC,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,OAAmB;IAC9C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,CAAC,qCAAqC,GAAG,CAAC,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,KAAwB,CAAC;AAC3D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAU;IAC3C,MAAM,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,18 @@
1
+ export type Result<T, U> = {
2
+ result: undefined;
3
+ error: U;
4
+ } | {
5
+ result: T;
6
+ error: undefined;
7
+ };
8
+ export declare namespace Result {
9
+ function ok<T>(result: T): {
10
+ result: T;
11
+ error: undefined;
12
+ };
13
+ function err<U>(error: U): {
14
+ result: undefined;
15
+ error: U;
16
+ };
17
+ }
18
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEN,yBAAiB,MAAM,CAAC;IACtB,SAAgB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAEhE;IACD,SAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,CAEhE;CACF"}
package/dist/result.js ADDED
@@ -0,0 +1,12 @@
1
+ export var Result;
2
+ (function (Result) {
3
+ function ok(result) {
4
+ return { error: undefined, result };
5
+ }
6
+ Result.ok = ok;
7
+ function err(error) {
8
+ return { error, result: undefined };
9
+ }
10
+ Result.err = err;
11
+ })(Result || (Result = {}));
12
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAUA,MAAM,KAAW,MAAM,CAOtB;AAPD,WAAiB,MAAM;IACrB,SAAgB,EAAE,CAAI,MAAS;QAC7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;IAFe,SAAE,KAEjB,CAAA;IACD,SAAgB,GAAG,CAAI,KAAQ;QAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;IAFe,UAAG,MAElB,CAAA;AACH,CAAC,EAPgB,MAAM,KAAN,MAAM,QAOtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qwreey-js/tsutil",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Typescript utilities",
5
5
  "keywords": [
6
6
  "typescript"