@rg-dev/stdlib 1.0.23 → 1.0.24

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.
@@ -96,8 +96,7 @@ var Optional = class _Optional {
96
96
  return new _Optional(val);
97
97
  }
98
98
  orElseThrow(msg) {
99
- if (this.value === void 0)
100
- throw new Error(msg || "Value is empty");
99
+ if (this.value === void 0) throw new Error(msg || "Value is empty");
101
100
  return this.value;
102
101
  }
103
102
  setValue(newValue) {
@@ -108,8 +107,7 @@ var Optional = class _Optional {
108
107
  return this.value;
109
108
  }
110
109
  ifPresent(action) {
111
- if (this.value === void 0)
112
- return;
110
+ if (this.value === void 0) return;
113
111
  try {
114
112
  action(this.value);
115
113
  } catch (e) {
@@ -149,8 +147,7 @@ async function catchInline(cb) {
149
147
  }
150
148
  function doSafe(safe, onError) {
151
149
  var _a;
152
- if (!safe)
153
- return;
150
+ if (!safe) return;
154
151
  try {
155
152
  const result = safe();
156
153
  if (isPromise(result)) {
@@ -1,73 +1,73 @@
1
- type Options = {
2
- maxAttempts: number;
3
- retryDelay: number;
4
- onError: (err: any, attempt: number) => void;
5
- };
1
+ type Options = {
2
+ maxAttempts: number;
3
+ retryDelay: number;
4
+ onError: (err: any, attempt: number) => void;
5
+ };
6
6
  declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?: Partial<Options>, attempt?: number): Promise<T>;
7
7
 
8
- interface IStringBuilder {
9
- /**
10
- * Append the specified text to the buffer.
11
- */
12
- append(text: string): void;
13
- /**
14
- * Returns a single string containing all the text that was appended to the buffer so far.
15
- *
16
- * @remarks
17
- *
18
- * This is a potentially expensive operation.
19
- */
20
- toString(): string;
21
- }
22
- /**
23
- * This class allows a large text string to be constructed incrementally by appending small chunks. The final
24
- * string can be obtained by calling StringBuilder.toString().
25
- *
26
- * @remarks
27
- * A naive approach might use the `+=` operator to append strings: This would have the downside of copying
28
- * the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
29
- * (and later freed by the garbage collector), and many of the allocations could be very large objects.
30
- * StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
31
- * when `getText()` is finally called.
32
- *
33
- * @public
34
- */
35
- declare class StringBuilder implements IStringBuilder {
36
- private _chunks;
37
- constructor();
38
- /** {@inheritDoc IStringBuilder.append} */
39
- append(text: string): this;
40
- /** {@inheritDoc IStringBuilder.toString} */
41
- toString(): string;
8
+ interface IStringBuilder {
9
+ /**
10
+ * Append the specified text to the buffer.
11
+ */
12
+ append(text: string): void;
13
+ /**
14
+ * Returns a single string containing all the text that was appended to the buffer so far.
15
+ *
16
+ * @remarks
17
+ *
18
+ * This is a potentially expensive operation.
19
+ */
20
+ toString(): string;
21
+ }
22
+ /**
23
+ * This class allows a large text string to be constructed incrementally by appending small chunks. The final
24
+ * string can be obtained by calling StringBuilder.toString().
25
+ *
26
+ * @remarks
27
+ * A naive approach might use the `+=` operator to append strings: This would have the downside of copying
28
+ * the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
29
+ * (and later freed by the garbage collector), and many of the allocations could be very large objects.
30
+ * StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
31
+ * when `getText()` is finally called.
32
+ *
33
+ * @public
34
+ */
35
+ declare class StringBuilder implements IStringBuilder {
36
+ private _chunks;
37
+ constructor();
38
+ /** {@inheritDoc IStringBuilder.append} */
39
+ append(text: string): this;
40
+ /** {@inheritDoc IStringBuilder.toString} */
41
+ toString(): string;
42
42
  }
43
43
 
44
- type MyFn<T extends Record<string, (...args: any[]) => any>> = {
45
- [K in keyof T]: (...args: Parameters<T[K]>) => void;
46
- };
47
- type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
48
- type MaybeFunction = ((...args: any) => void) | undefined;
49
- declare class Optional<T> {
50
- private value;
51
- private constructor();
52
- static of<T>(val: T | any): Optional<T>;
53
- orElseThrow(msg?: string): T;
54
- setValue(newValue: T): this;
55
- getValue(): T | undefined;
56
- ifPresent(action: (val: Exclude<T, undefined>) => void): void;
57
- }
58
- declare function sleep(ms: number): Promise<unknown>;
59
- declare function isNumber(num: any): boolean;
60
- declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
61
- declare function catchInline<T>(cb: Promise<T>): Promise<{
62
- error: undefined;
63
- result: T;
64
- } | {
65
- error: Error;
66
- result: undefined;
67
- }>;
68
- declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
69
- declare function isRunningOnServer(): boolean;
70
- declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
44
+ type MyFn<T extends Record<string, (...args: any[]) => any>> = {
45
+ [K in keyof T]: (...args: Parameters<T[K]>) => void;
46
+ };
47
+ type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
48
+ type MaybeFunction = ((...args: any) => void) | undefined;
49
+ declare class Optional<T> {
50
+ private value;
51
+ private constructor();
52
+ static of<T>(val: T | any): Optional<T>;
53
+ orElseThrow(msg?: string): T;
54
+ setValue(newValue: T): this;
55
+ getValue(): T | undefined;
56
+ ifPresent(action: (val: Exclude<T, undefined>) => void): void;
57
+ }
58
+ declare function sleep(ms: number): Promise<unknown>;
59
+ declare function isNumber(num: any): boolean;
60
+ declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
61
+ declare function catchInline<T>(cb: Promise<T>): Promise<{
62
+ error: undefined;
63
+ result: T;
64
+ } | {
65
+ error: Error;
66
+ result: undefined;
67
+ }>;
68
+ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
69
+ declare function isRunningOnServer(): boolean;
70
+ declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
71
71
  declare function isNonEmptyString(str?: string): boolean;
72
72
 
73
73
  export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
@@ -1,73 +1,73 @@
1
- type Options = {
2
- maxAttempts: number;
3
- retryDelay: number;
4
- onError: (err: any, attempt: number) => void;
5
- };
1
+ type Options = {
2
+ maxAttempts: number;
3
+ retryDelay: number;
4
+ onError: (err: any, attempt: number) => void;
5
+ };
6
6
  declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?: Partial<Options>, attempt?: number): Promise<T>;
7
7
 
8
- interface IStringBuilder {
9
- /**
10
- * Append the specified text to the buffer.
11
- */
12
- append(text: string): void;
13
- /**
14
- * Returns a single string containing all the text that was appended to the buffer so far.
15
- *
16
- * @remarks
17
- *
18
- * This is a potentially expensive operation.
19
- */
20
- toString(): string;
21
- }
22
- /**
23
- * This class allows a large text string to be constructed incrementally by appending small chunks. The final
24
- * string can be obtained by calling StringBuilder.toString().
25
- *
26
- * @remarks
27
- * A naive approach might use the `+=` operator to append strings: This would have the downside of copying
28
- * the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
29
- * (and later freed by the garbage collector), and many of the allocations could be very large objects.
30
- * StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
31
- * when `getText()` is finally called.
32
- *
33
- * @public
34
- */
35
- declare class StringBuilder implements IStringBuilder {
36
- private _chunks;
37
- constructor();
38
- /** {@inheritDoc IStringBuilder.append} */
39
- append(text: string): this;
40
- /** {@inheritDoc IStringBuilder.toString} */
41
- toString(): string;
8
+ interface IStringBuilder {
9
+ /**
10
+ * Append the specified text to the buffer.
11
+ */
12
+ append(text: string): void;
13
+ /**
14
+ * Returns a single string containing all the text that was appended to the buffer so far.
15
+ *
16
+ * @remarks
17
+ *
18
+ * This is a potentially expensive operation.
19
+ */
20
+ toString(): string;
21
+ }
22
+ /**
23
+ * This class allows a large text string to be constructed incrementally by appending small chunks. The final
24
+ * string can be obtained by calling StringBuilder.toString().
25
+ *
26
+ * @remarks
27
+ * A naive approach might use the `+=` operator to append strings: This would have the downside of copying
28
+ * the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
29
+ * (and later freed by the garbage collector), and many of the allocations could be very large objects.
30
+ * StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
31
+ * when `getText()` is finally called.
32
+ *
33
+ * @public
34
+ */
35
+ declare class StringBuilder implements IStringBuilder {
36
+ private _chunks;
37
+ constructor();
38
+ /** {@inheritDoc IStringBuilder.append} */
39
+ append(text: string): this;
40
+ /** {@inheritDoc IStringBuilder.toString} */
41
+ toString(): string;
42
42
  }
43
43
 
44
- type MyFn<T extends Record<string, (...args: any[]) => any>> = {
45
- [K in keyof T]: (...args: Parameters<T[K]>) => void;
46
- };
47
- type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
48
- type MaybeFunction = ((...args: any) => void) | undefined;
49
- declare class Optional<T> {
50
- private value;
51
- private constructor();
52
- static of<T>(val: T | any): Optional<T>;
53
- orElseThrow(msg?: string): T;
54
- setValue(newValue: T): this;
55
- getValue(): T | undefined;
56
- ifPresent(action: (val: Exclude<T, undefined>) => void): void;
57
- }
58
- declare function sleep(ms: number): Promise<unknown>;
59
- declare function isNumber(num: any): boolean;
60
- declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
61
- declare function catchInline<T>(cb: Promise<T>): Promise<{
62
- error: undefined;
63
- result: T;
64
- } | {
65
- error: Error;
66
- result: undefined;
67
- }>;
68
- declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
69
- declare function isRunningOnServer(): boolean;
70
- declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
44
+ type MyFn<T extends Record<string, (...args: any[]) => any>> = {
45
+ [K in keyof T]: (...args: Parameters<T[K]>) => void;
46
+ };
47
+ type AsyncReturnType<T extends (...args: any) => any> = Awaited<ReturnType<T>>;
48
+ type MaybeFunction = ((...args: any) => void) | undefined;
49
+ declare class Optional<T> {
50
+ private value;
51
+ private constructor();
52
+ static of<T>(val: T | any): Optional<T>;
53
+ orElseThrow(msg?: string): T;
54
+ setValue(newValue: T): this;
55
+ getValue(): T | undefined;
56
+ ifPresent(action: (val: Exclude<T, undefined>) => void): void;
57
+ }
58
+ declare function sleep(ms: number): Promise<unknown>;
59
+ declare function isNumber(num: any): boolean;
60
+ declare function promiseWithTimeout<T>(promise: Promise<T>, timeout: number, errMsg?: string): Promise<T>;
61
+ declare function catchInline<T>(cb: Promise<T>): Promise<{
62
+ error: undefined;
63
+ result: T;
64
+ } | {
65
+ error: Error;
66
+ result: undefined;
67
+ }>;
68
+ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Error) => void): void;
69
+ declare function isRunningOnServer(): boolean;
70
+ declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
71
71
  declare function isNonEmptyString(str?: string): boolean;
72
72
 
73
73
  export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
package/lib/common-env.js CHANGED
@@ -61,8 +61,7 @@ var Optional = class _Optional {
61
61
  return new _Optional(val);
62
62
  }
63
63
  orElseThrow(msg) {
64
- if (this.value === void 0)
65
- throw new Error(msg || "Value is empty");
64
+ if (this.value === void 0) throw new Error(msg || "Value is empty");
66
65
  return this.value;
67
66
  }
68
67
  setValue(newValue) {
@@ -73,8 +72,7 @@ var Optional = class _Optional {
73
72
  return this.value;
74
73
  }
75
74
  ifPresent(action) {
76
- if (this.value === void 0)
77
- return;
75
+ if (this.value === void 0) return;
78
76
  try {
79
77
  action(this.value);
80
78
  } catch (e) {
@@ -114,8 +112,7 @@ async function catchInline(cb) {
114
112
  }
115
113
  function doSafe(safe, onError) {
116
114
  var _a;
117
- if (!safe)
118
- return;
115
+ if (!safe) return;
119
116
  try {
120
117
  const result = safe();
121
118
  if (isPromise(result)) {