@rg-dev/stdlib 1.0.22 → 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)) {
package/lib/index.cjs ADDED
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/index.ts
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
@@ -0,0 +1,5 @@
1
+ export { AsyncReturnType, MaybeFunction, MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer } from './common-env.cjs';
2
+ export { downloadFile } from './node-download.cjs';
3
+ export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty } from './node-env.cjs';
4
+ import 'express';
5
+ import 'events';
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { AsyncReturnType, MaybeFunction, MyFn, Optional, StringBuilder, catchInline, doSafe, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer } from './common-env.js';
2
+ export { downloadFile } from './node-download.js';
3
+ export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty } from './node-env.js';
4
+ import 'express';
5
+ import 'events';
package/lib/index.js ADDED
File without changes
@@ -81,7 +81,7 @@ var require_ponyfill_es2018 = __commonJS({
81
81
  "node_modules/web-streams-polyfill/dist/ponyfill.es2018.js"(exports, module2) {
82
82
  (function(global2, factory) {
83
83
  typeof exports === "object" && typeof module2 !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.WebStreamsPolyfill = {}));
84
- })(exports, function(exports2) {
84
+ })(exports, (function(exports2) {
85
85
  "use strict";
86
86
  const SymbolPolyfill = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? Symbol : (description) => `Symbol(${description})`;
87
87
  function noop2() {
@@ -716,8 +716,7 @@ var require_ponyfill_es2018 = __commonJS({
716
716
  if (this._associatedReadableByteStreamController === void 0) {
717
717
  throw new TypeError("This BYOB request has been invalidated");
718
718
  }
719
- if (IsDetachedBuffer(this._view.buffer))
720
- ;
719
+ if (IsDetachedBuffer(this._view.buffer)) ;
721
720
  ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
722
721
  }
723
722
  respondWithNewView(view) {
@@ -731,8 +730,7 @@ var require_ponyfill_es2018 = __commonJS({
731
730
  if (this._associatedReadableByteStreamController === void 0) {
732
731
  throw new TypeError("This BYOB request has been invalidated");
733
732
  }
734
- if (IsDetachedBuffer(view.buffer))
735
- ;
733
+ if (IsDetachedBuffer(view.buffer)) ;
736
734
  ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
737
735
  }
738
736
  }
@@ -1145,8 +1143,7 @@ var require_ponyfill_es2018 = __commonJS({
1145
1143
  const transferredBuffer = TransferArrayBuffer(buffer);
1146
1144
  if (controller._pendingPullIntos.length > 0) {
1147
1145
  const firstPendingPullInto = controller._pendingPullIntos.peek();
1148
- if (IsDetachedBuffer(firstPendingPullInto.buffer))
1149
- ;
1146
+ if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
1150
1147
  firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
1151
1148
  }
1152
1149
  ReadableByteStreamControllerInvalidateBYOBRequest(controller);
@@ -1375,8 +1372,7 @@ var require_ponyfill_es2018 = __commonJS({
1375
1372
  if (view.buffer.byteLength === 0) {
1376
1373
  return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
1377
1374
  }
1378
- if (IsDetachedBuffer(view.buffer))
1379
- ;
1375
+ if (IsDetachedBuffer(view.buffer)) ;
1380
1376
  if (this._ownerReadableStream === void 0) {
1381
1377
  return promiseRejectedWith(readerLockException("read from"));
1382
1378
  }
@@ -3886,7 +3882,7 @@ var require_ponyfill_es2018 = __commonJS({
3886
3882
  exports2.WritableStreamDefaultController = WritableStreamDefaultController;
3887
3883
  exports2.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
3888
3884
  Object.defineProperty(exports2, "__esModule", { value: true });
3889
- });
3885
+ }));
3890
3886
  }
3891
3887
  });
3892
3888
 
@@ -4000,8 +3996,7 @@ var init_fetch_blob = __esm({
4000
3996
  if (typeof options !== "object" && typeof options !== "function") {
4001
3997
  throw new TypeError("Failed to construct 'Blob': parameter 2 cannot convert to dictionary.");
4002
3998
  }
4003
- if (options === null)
4004
- options = {};
3999
+ if (options === null) options = {};
4005
4000
  const encoder = new TextEncoder();
4006
4001
  for (const element of blobParts) {
4007
4002
  let part;
@@ -4160,8 +4155,7 @@ var init_file = __esm({
4160
4155
  throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);
4161
4156
  }
4162
4157
  super(fileBits, options);
4163
- if (options === null)
4164
- options = {};
4158
+ if (options === null) options = {};
4165
4159
  const lastModified = options.lastModified === void 0 ? Date.now() : Number(options.lastModified);
4166
4160
  if (!Number.isNaN(lastModified)) {
4167
4161
  this.#lastModified = lastModified;
@@ -4218,8 +4212,7 @@ var init_esm_min = __esm({
4218
4212
  FormData = class FormData2 {
4219
4213
  #d = [];
4220
4214
  constructor(...a) {
4221
- if (a.length)
4222
- throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
4215
+ if (a.length) throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
4223
4216
  }
4224
4217
  get [t]() {
4225
4218
  return "FormData";
@@ -4242,9 +4235,7 @@ var init_esm_min = __esm({
4242
4235
  get(a) {
4243
4236
  x("get", arguments, 1);
4244
4237
  a += "";
4245
- for (var b = this.#d, l = b.length, c = 0; c < l; c++)
4246
- if (b[c][0] === a)
4247
- return b[c][1];
4238
+ for (var b = this.#d, l = b.length, c = 0; c < l; c++) if (b[c][0] === a) return b[c][1];
4248
4239
  return null;
4249
4240
  }
4250
4241
  getAll(a, b) {
@@ -4261,8 +4252,7 @@ var init_esm_min = __esm({
4261
4252
  }
4262
4253
  forEach(a, b) {
4263
4254
  x("forEach", arguments, 1);
4264
- for (var [c, d] of this)
4265
- a.call(b, d, c, this);
4255
+ for (var [c, d] of this) a.call(b, d, c, this);
4266
4256
  }
4267
4257
  set(...a) {
4268
4258
  x("set", arguments, 2);
@@ -4278,12 +4268,10 @@ var init_esm_min = __esm({
4278
4268
  yield* this.#d;
4279
4269
  }
4280
4270
  *keys() {
4281
- for (var [a] of this)
4282
- yield a;
4271
+ for (var [a] of this) yield a;
4283
4272
  }
4284
4273
  *values() {
4285
- for (var [, a] of this)
4286
- yield a;
4274
+ for (var [, a] of this) yield a;
4287
4275
  }
4288
4276
  };
4289
4277
  }
@@ -4660,6 +4648,7 @@ var init_multipart_parser = __esm({
4660
4648
  state = S.HEADER_FIELD;
4661
4649
  mark("onHeaderField");
4662
4650
  index = 0;
4651
+ // falls through
4663
4652
  case S.HEADER_FIELD:
4664
4653
  if (c === CR) {
4665
4654
  clear("onHeaderField");
@@ -4689,6 +4678,7 @@ var init_multipart_parser = __esm({
4689
4678
  }
4690
4679
  mark("onHeaderValue");
4691
4680
  state = S.HEADER_VALUE;
4681
+ // falls through
4692
4682
  case S.HEADER_VALUE:
4693
4683
  if (c === CR) {
4694
4684
  dataCallback("onHeaderValue", true);
@@ -4712,6 +4702,7 @@ var init_multipart_parser = __esm({
4712
4702
  case S.PART_DATA_START:
4713
4703
  state = S.PART_DATA;
4714
4704
  mark("onPartData");
4705
+ // falls through
4715
4706
  case S.PART_DATA:
4716
4707
  previousIndex = index;
4717
4708
  if (index === 0) {
@@ -7,8 +7,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __require = /* @__PURE__ */ ((x2) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x2, {
8
8
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
9
  }) : x2)(function(x2) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
11
  throw Error('Dynamic require of "' + x2 + '" is not supported');
13
12
  });
14
13
  var __esm = (fn, res) => function __init() {
@@ -87,7 +86,7 @@ var require_ponyfill_es2018 = __commonJS({
87
86
  "node_modules/web-streams-polyfill/dist/ponyfill.es2018.js"(exports, module) {
88
87
  (function(global2, factory) {
89
88
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.WebStreamsPolyfill = {}));
90
- })(exports, function(exports2) {
89
+ })(exports, (function(exports2) {
91
90
  "use strict";
92
91
  const SymbolPolyfill = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? Symbol : (description) => `Symbol(${description})`;
93
92
  function noop2() {
@@ -722,8 +721,7 @@ var require_ponyfill_es2018 = __commonJS({
722
721
  if (this._associatedReadableByteStreamController === void 0) {
723
722
  throw new TypeError("This BYOB request has been invalidated");
724
723
  }
725
- if (IsDetachedBuffer(this._view.buffer))
726
- ;
724
+ if (IsDetachedBuffer(this._view.buffer)) ;
727
725
  ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten);
728
726
  }
729
727
  respondWithNewView(view) {
@@ -737,8 +735,7 @@ var require_ponyfill_es2018 = __commonJS({
737
735
  if (this._associatedReadableByteStreamController === void 0) {
738
736
  throw new TypeError("This BYOB request has been invalidated");
739
737
  }
740
- if (IsDetachedBuffer(view.buffer))
741
- ;
738
+ if (IsDetachedBuffer(view.buffer)) ;
742
739
  ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view);
743
740
  }
744
741
  }
@@ -1151,8 +1148,7 @@ var require_ponyfill_es2018 = __commonJS({
1151
1148
  const transferredBuffer = TransferArrayBuffer(buffer);
1152
1149
  if (controller._pendingPullIntos.length > 0) {
1153
1150
  const firstPendingPullInto = controller._pendingPullIntos.peek();
1154
- if (IsDetachedBuffer(firstPendingPullInto.buffer))
1155
- ;
1151
+ if (IsDetachedBuffer(firstPendingPullInto.buffer)) ;
1156
1152
  firstPendingPullInto.buffer = TransferArrayBuffer(firstPendingPullInto.buffer);
1157
1153
  }
1158
1154
  ReadableByteStreamControllerInvalidateBYOBRequest(controller);
@@ -1381,8 +1377,7 @@ var require_ponyfill_es2018 = __commonJS({
1381
1377
  if (view.buffer.byteLength === 0) {
1382
1378
  return promiseRejectedWith(new TypeError(`view's buffer must have non-zero byteLength`));
1383
1379
  }
1384
- if (IsDetachedBuffer(view.buffer))
1385
- ;
1380
+ if (IsDetachedBuffer(view.buffer)) ;
1386
1381
  if (this._ownerReadableStream === void 0) {
1387
1382
  return promiseRejectedWith(readerLockException("read from"));
1388
1383
  }
@@ -3892,7 +3887,7 @@ var require_ponyfill_es2018 = __commonJS({
3892
3887
  exports2.WritableStreamDefaultController = WritableStreamDefaultController;
3893
3888
  exports2.WritableStreamDefaultWriter = WritableStreamDefaultWriter;
3894
3889
  Object.defineProperty(exports2, "__esModule", { value: true });
3895
- });
3890
+ }));
3896
3891
  }
3897
3892
  });
3898
3893
 
@@ -3902,12 +3897,12 @@ var require_streams = __commonJS({
3902
3897
  var POOL_SIZE2 = 65536;
3903
3898
  if (!globalThis.ReadableStream) {
3904
3899
  try {
3905
- const process2 = __require("node:process");
3900
+ const process2 = __require("process");
3906
3901
  const { emitWarning } = process2;
3907
3902
  try {
3908
3903
  process2.emitWarning = () => {
3909
3904
  };
3910
- Object.assign(globalThis, __require("node:stream/web"));
3905
+ Object.assign(globalThis, __require("stream/web"));
3911
3906
  process2.emitWarning = emitWarning;
3912
3907
  } catch (error) {
3913
3908
  process2.emitWarning = emitWarning;
@@ -4006,8 +4001,7 @@ var init_fetch_blob = __esm({
4006
4001
  if (typeof options !== "object" && typeof options !== "function") {
4007
4002
  throw new TypeError("Failed to construct 'Blob': parameter 2 cannot convert to dictionary.");
4008
4003
  }
4009
- if (options === null)
4010
- options = {};
4004
+ if (options === null) options = {};
4011
4005
  const encoder = new TextEncoder();
4012
4006
  for (const element of blobParts) {
4013
4007
  let part;
@@ -4166,8 +4160,7 @@ var init_file = __esm({
4166
4160
  throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);
4167
4161
  }
4168
4162
  super(fileBits, options);
4169
- if (options === null)
4170
- options = {};
4163
+ if (options === null) options = {};
4171
4164
  const lastModified = options.lastModified === void 0 ? Date.now() : Number(options.lastModified);
4172
4165
  if (!Number.isNaN(lastModified)) {
4173
4166
  this.#lastModified = lastModified;
@@ -4224,8 +4217,7 @@ var init_esm_min = __esm({
4224
4217
  FormData = class FormData2 {
4225
4218
  #d = [];
4226
4219
  constructor(...a) {
4227
- if (a.length)
4228
- throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
4220
+ if (a.length) throw new TypeError(`Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'.`);
4229
4221
  }
4230
4222
  get [t]() {
4231
4223
  return "FormData";
@@ -4248,9 +4240,7 @@ var init_esm_min = __esm({
4248
4240
  get(a) {
4249
4241
  x("get", arguments, 1);
4250
4242
  a += "";
4251
- for (var b = this.#d, l = b.length, c = 0; c < l; c++)
4252
- if (b[c][0] === a)
4253
- return b[c][1];
4243
+ for (var b = this.#d, l = b.length, c = 0; c < l; c++) if (b[c][0] === a) return b[c][1];
4254
4244
  return null;
4255
4245
  }
4256
4246
  getAll(a, b) {
@@ -4267,8 +4257,7 @@ var init_esm_min = __esm({
4267
4257
  }
4268
4258
  forEach(a, b) {
4269
4259
  x("forEach", arguments, 1);
4270
- for (var [c, d] of this)
4271
- a.call(b, d, c, this);
4260
+ for (var [c, d] of this) a.call(b, d, c, this);
4272
4261
  }
4273
4262
  set(...a) {
4274
4263
  x("set", arguments, 2);
@@ -4284,12 +4273,10 @@ var init_esm_min = __esm({
4284
4273
  yield* this.#d;
4285
4274
  }
4286
4275
  *keys() {
4287
- for (var [a] of this)
4288
- yield a;
4276
+ for (var [a] of this) yield a;
4289
4277
  }
4290
4278
  *values() {
4291
- for (var [, a] of this)
4292
- yield a;
4279
+ for (var [, a] of this) yield a;
4293
4280
  }
4294
4281
  };
4295
4282
  }
@@ -4380,8 +4367,8 @@ var require_node_domexception = __commonJS({
4380
4367
  });
4381
4368
 
4382
4369
  // node_modules/fetch-blob/from.js
4383
- import { statSync, createReadStream, promises as fs } from "node:fs";
4384
- import { basename } from "node:path";
4370
+ import { statSync, createReadStream, promises as fs } from "fs";
4371
+ import { basename } from "path";
4385
4372
  var import_node_domexception, stat, blobFromSync, blobFrom, fileFrom, fileFromSync, fromBlob, fromFile, BlobDataItem;
4386
4373
  var init_from = __esm({
4387
4374
  "node_modules/fetch-blob/from.js"() {
@@ -4666,6 +4653,7 @@ var init_multipart_parser = __esm({
4666
4653
  state = S.HEADER_FIELD;
4667
4654
  mark("onHeaderField");
4668
4655
  index = 0;
4656
+ // falls through
4669
4657
  case S.HEADER_FIELD:
4670
4658
  if (c === CR) {
4671
4659
  clear("onHeaderField");
@@ -4695,6 +4683,7 @@ var init_multipart_parser = __esm({
4695
4683
  }
4696
4684
  mark("onHeaderValue");
4697
4685
  state = S.HEADER_VALUE;
4686
+ // falls through
4698
4687
  case S.HEADER_VALUE:
4699
4688
  if (c === CR) {
4700
4689
  dataCallback("onHeaderValue", true);
@@ -4718,6 +4707,7 @@ var init_multipart_parser = __esm({
4718
4707
  case S.PART_DATA_START:
4719
4708
  state = S.PART_DATA;
4720
4709
  mark("onPartData");
4710
+ // falls through
4721
4711
  case S.PART_DATA:
4722
4712
  previousIndex = index;
4723
4713
  if (index === 0) {
@@ -4803,9 +4793,9 @@ var init_multipart_parser = __esm({
4803
4793
  });
4804
4794
 
4805
4795
  // node_modules/node-fetch/src/body.js
4806
- import Stream, { PassThrough } from "node:stream";
4807
- import { types, deprecate, promisify } from "node:util";
4808
- import { Buffer as Buffer2 } from "node:buffer";
4796
+ import Stream, { PassThrough } from "stream";
4797
+ import { types, deprecate, promisify } from "util";
4798
+ import { Buffer as Buffer2 } from "buffer";
4809
4799
  async function consumeBody(data) {
4810
4800
  if (data[INTERNALS].disturbed) {
4811
4801
  throw new TypeError(`body used already for: ${data.url}`);
@@ -5061,8 +5051,8 @@ var init_body = __esm({
5061
5051
  });
5062
5052
 
5063
5053
  // node_modules/node-fetch/src/headers.js
5064
- import { types as types2 } from "node:util";
5065
- import http from "node:http";
5054
+ import { types as types2 } from "util";
5055
+ import http from "http";
5066
5056
  function fromRawHeaders(headers = []) {
5067
5057
  return new Headers(
5068
5058
  headers.reduce((result, value, index, array) => {
@@ -5404,7 +5394,7 @@ var init_get_search = __esm({
5404
5394
  });
5405
5395
 
5406
5396
  // node_modules/node-fetch/src/utils/referrer.js
5407
- import { isIP } from "node:net";
5397
+ import { isIP } from "net";
5408
5398
  function stripURLForUseAsAReferrer(url, originOnly = false) {
5409
5399
  if (url == null) {
5410
5400
  return "no-referrer";
@@ -5549,8 +5539,8 @@ var init_referrer = __esm({
5549
5539
  });
5550
5540
 
5551
5541
  // node_modules/node-fetch/src/request.js
5552
- import { format as formatUrl } from "node:url";
5553
- import { deprecate as deprecate2 } from "node:util";
5542
+ import { format as formatUrl } from "url";
5543
+ import { deprecate as deprecate2 } from "util";
5554
5544
  var INTERNALS3, isRequest, doBadDataWarn, Request, getNodeRequestOptions;
5555
5545
  var init_request = __esm({
5556
5546
  "node_modules/node-fetch/src/request.js"() {
@@ -5784,11 +5774,11 @@ __export(src_exports, {
5784
5774
  fileFromSync: () => fileFromSync,
5785
5775
  isRedirect: () => isRedirect
5786
5776
  });
5787
- import http2 from "node:http";
5788
- import https from "node:https";
5789
- import zlib from "node:zlib";
5790
- import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "node:stream";
5791
- import { Buffer as Buffer3 } from "node:buffer";
5777
+ import http2 from "http";
5778
+ import https from "https";
5779
+ import zlib from "zlib";
5780
+ import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "stream";
5781
+ import { Buffer as Buffer3 } from "buffer";
5792
5782
  async function fetch2(url, options_) {
5793
5783
  return new Promise((resolve, reject) => {
5794
5784
  const request = new Request(url, options_);
package/lib/node-env.cjs CHANGED
@@ -219,8 +219,7 @@ var SSEResponse = class {
219
219
  }
220
220
  /** Send JSON to client, optionally with a custom event type */
221
221
  emit(data, event) {
222
- if (!this.isOpen)
223
- return;
222
+ if (!this.isOpen) return;
224
223
  try {
225
224
  let payload = "";
226
225
  if (event) {
@@ -286,15 +285,13 @@ var SSEClient = class extends import_events.EventEmitter {
286
285
  let eventName = "message";
287
286
  while (true) {
288
287
  const { value, done } = await reader.read();
289
- if (done)
290
- break;
288
+ if (done) break;
291
289
  buffer += decoder.decode(value, { stream: true });
292
290
  let lines = buffer.split("\n");
293
291
  buffer = lines.pop();
294
292
  for (let line of lines) {
295
293
  line = line.trim();
296
- if (!line)
297
- continue;
294
+ if (!line) continue;
298
295
  if (line.startsWith("event:")) {
299
296
  eventName = line.slice(6).trim();
300
297
  } else if (line.startsWith("data:")) {
@@ -339,13 +336,10 @@ function chmodPlusX(filePath) {
339
336
  }
340
337
  }
341
338
  async function checkIfDirExistsOrThrow(path2) {
342
- if (!path2)
343
- throw "path is empty";
339
+ if (!path2) throw "path is empty";
344
340
  path2 = removeQuotes(path2);
345
- if (!await fs.pathExists(path2))
346
- throw new Error(`path ${path2} not exists`);
347
- if (!(await fs.stat(path2)).isDirectory())
348
- throw new Error(`${path2} is a file, require dir`);
341
+ if (!await fs.pathExists(path2)) throw new Error(`path ${path2} not exists`);
342
+ if (!(await fs.stat(path2)).isDirectory()) throw new Error(`${path2} is a file, require dir`);
349
343
  }
350
344
  function createTempDir() {
351
345
  const tmpDir = import_os.default.tmpdir();
@@ -357,11 +351,9 @@ function createTempDir() {
357
351
  return tempDirPath;
358
352
  }
359
353
  async function throwIfDirNotEmpty(dir_path) {
360
- if (!await fs.pathExists(dir_path))
361
- throw new Error("dir not exists");
354
+ if (!await fs.pathExists(dir_path)) throw new Error("dir not exists");
362
355
  const isEmpty = await fs.readdir(dir_path).then((x) => x.length === 0);
363
- if (!isEmpty)
364
- throw new Error(`dir ${dir_path} must be empty`);
356
+ if (!isEmpty) throw new Error(`dir ${dir_path} must be empty`);
365
357
  }
366
358
  async function checkCommandExistsOrThrow(cmd) {
367
359
  try {
@@ -371,13 +363,10 @@ async function checkCommandExistsOrThrow(cmd) {
371
363
  }
372
364
  }
373
365
  async function checkIfFileExistsOrThrow(the_path) {
374
- if (!the_path)
375
- throw "path is empty";
366
+ if (!the_path) throw "path is empty";
376
367
  the_path = removeQuotes(the_path);
377
- if (!await fs.pathExists(the_path))
378
- throw new Error(`path ${the_path} not exists`);
379
- if (!(await fs.stat(the_path)).isFile())
380
- throw new Error(`${the_path} is a dir, require file`);
368
+ if (!await fs.pathExists(the_path)) throw new Error(`path ${the_path} not exists`);
369
+ if (!(await fs.stat(the_path)).isFile()) throw new Error(`${the_path} is a dir, require file`);
381
370
  }
382
371
  function removeQuotes(str) {
383
372
  if (str.startsWith('"') && str.endsWith('"')) {
@@ -1,38 +1,38 @@
1
1
  import { Response } from 'express';
2
2
  import { EventEmitter } from 'events';
3
3
 
4
- declare class SSEResponse<Events extends string = 'message'> {
5
- private res;
6
- private isOpen;
7
- constructor(res: Response);
8
- flushHeaders(): void;
9
- /** Send JSON to client, optionally with a custom event type */
10
- emit(data: unknown, event?: Events): void;
11
- /** Close the SSE connection */
12
- close(): void;
4
+ declare class SSEResponse<Events extends string = 'message'> {
5
+ private res;
6
+ private isOpen;
7
+ constructor(res: Response);
8
+ flushHeaders(): void;
9
+ /** Send JSON to client, optionally with a custom event type */
10
+ emit(data: unknown, event?: Events): void;
11
+ /** Close the SSE connection */
12
+ close(): void;
13
13
  }
14
14
 
15
- interface SSEClientOptions {
16
- url: string;
17
- payload?: Record<string, any>;
18
- headers?: Record<string, string>;
19
- }
20
- declare class SSEClient extends EventEmitter {
21
- private url;
22
- private payload;
23
- private headers;
24
- private controller;
25
- constructor(options: SSEClientOptions);
26
- connect(): Promise<void>;
27
- close(): void;
15
+ interface SSEClientOptions {
16
+ url: string;
17
+ payload?: Record<string, any>;
18
+ headers?: Record<string, string>;
19
+ }
20
+ declare class SSEClient extends EventEmitter {
21
+ private url;
22
+ private payload;
23
+ private headers;
24
+ private controller;
25
+ constructor(options: SSEClientOptions);
26
+ connect(): Promise<void>;
27
+ close(): void;
28
28
  }
29
29
 
30
- declare function isWindows(): boolean;
31
- declare function chmodPlusX(filePath: string): void;
32
- declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
33
- declare function createTempDir(): string;
34
- declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
35
- declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
30
+ declare function isWindows(): boolean;
31
+ declare function chmodPlusX(filePath: string): void;
32
+ declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
33
+ declare function createTempDir(): string;
34
+ declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
35
+ declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
36
36
  declare function checkIfFileExistsOrThrow(the_path: string): Promise<void>;
37
37
 
38
38
  export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty };
package/lib/node-env.d.ts CHANGED
@@ -1,38 +1,38 @@
1
1
  import { Response } from 'express';
2
2
  import { EventEmitter } from 'events';
3
3
 
4
- declare class SSEResponse<Events extends string = 'message'> {
5
- private res;
6
- private isOpen;
7
- constructor(res: Response);
8
- flushHeaders(): void;
9
- /** Send JSON to client, optionally with a custom event type */
10
- emit(data: unknown, event?: Events): void;
11
- /** Close the SSE connection */
12
- close(): void;
4
+ declare class SSEResponse<Events extends string = 'message'> {
5
+ private res;
6
+ private isOpen;
7
+ constructor(res: Response);
8
+ flushHeaders(): void;
9
+ /** Send JSON to client, optionally with a custom event type */
10
+ emit(data: unknown, event?: Events): void;
11
+ /** Close the SSE connection */
12
+ close(): void;
13
13
  }
14
14
 
15
- interface SSEClientOptions {
16
- url: string;
17
- payload?: Record<string, any>;
18
- headers?: Record<string, string>;
19
- }
20
- declare class SSEClient extends EventEmitter {
21
- private url;
22
- private payload;
23
- private headers;
24
- private controller;
25
- constructor(options: SSEClientOptions);
26
- connect(): Promise<void>;
27
- close(): void;
15
+ interface SSEClientOptions {
16
+ url: string;
17
+ payload?: Record<string, any>;
18
+ headers?: Record<string, string>;
19
+ }
20
+ declare class SSEClient extends EventEmitter {
21
+ private url;
22
+ private payload;
23
+ private headers;
24
+ private controller;
25
+ constructor(options: SSEClientOptions);
26
+ connect(): Promise<void>;
27
+ close(): void;
28
28
  }
29
29
 
30
- declare function isWindows(): boolean;
31
- declare function chmodPlusX(filePath: string): void;
32
- declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
33
- declare function createTempDir(): string;
34
- declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
35
- declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
30
+ declare function isWindows(): boolean;
31
+ declare function chmodPlusX(filePath: string): void;
32
+ declare function checkIfDirExistsOrThrow(path: string): Promise<void>;
33
+ declare function createTempDir(): string;
34
+ declare function throwIfDirNotEmpty(dir_path: string): Promise<void>;
35
+ declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
36
36
  declare function checkIfFileExistsOrThrow(the_path: string): Promise<void>;
37
37
 
38
38
  export { SSEClient, SSEResponse, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, isWindows, throwIfDirNotEmpty };
package/lib/node-env.js CHANGED
@@ -7,8 +7,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
8
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
9
  }) : x)(function(x) {
10
- if (typeof require !== "undefined")
11
- return require.apply(this, arguments);
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
11
  throw Error('Dynamic require of "' + x + '" is not supported');
13
12
  });
14
13
  var __commonJS = (cb, mod) => function __require2() {
@@ -208,8 +207,7 @@ var SSEResponse = class {
208
207
  }
209
208
  /** Send JSON to client, optionally with a custom event type */
210
209
  emit(data, event) {
211
- if (!this.isOpen)
212
- return;
210
+ if (!this.isOpen) return;
213
211
  try {
214
212
  let payload = "";
215
213
  if (event) {
@@ -275,15 +273,13 @@ var SSEClient = class extends EventEmitter {
275
273
  let eventName = "message";
276
274
  while (true) {
277
275
  const { value, done } = await reader.read();
278
- if (done)
279
- break;
276
+ if (done) break;
280
277
  buffer += decoder.decode(value, { stream: true });
281
278
  let lines = buffer.split("\n");
282
279
  buffer = lines.pop();
283
280
  for (let line of lines) {
284
281
  line = line.trim();
285
- if (!line)
286
- continue;
282
+ if (!line) continue;
287
283
  if (line.startsWith("event:")) {
288
284
  eventName = line.slice(6).trim();
289
285
  } else if (line.startsWith("data:")) {
@@ -328,13 +324,10 @@ function chmodPlusX(filePath) {
328
324
  }
329
325
  }
330
326
  async function checkIfDirExistsOrThrow(path2) {
331
- if (!path2)
332
- throw "path is empty";
327
+ if (!path2) throw "path is empty";
333
328
  path2 = removeQuotes(path2);
334
- if (!await fs.pathExists(path2))
335
- throw new Error(`path ${path2} not exists`);
336
- if (!(await fs.stat(path2)).isDirectory())
337
- throw new Error(`${path2} is a file, require dir`);
329
+ if (!await fs.pathExists(path2)) throw new Error(`path ${path2} not exists`);
330
+ if (!(await fs.stat(path2)).isDirectory()) throw new Error(`${path2} is a file, require dir`);
338
331
  }
339
332
  function createTempDir() {
340
333
  const tmpDir = os.tmpdir();
@@ -346,11 +339,9 @@ function createTempDir() {
346
339
  return tempDirPath;
347
340
  }
348
341
  async function throwIfDirNotEmpty(dir_path) {
349
- if (!await fs.pathExists(dir_path))
350
- throw new Error("dir not exists");
342
+ if (!await fs.pathExists(dir_path)) throw new Error("dir not exists");
351
343
  const isEmpty = await fs.readdir(dir_path).then((x) => x.length === 0);
352
- if (!isEmpty)
353
- throw new Error(`dir ${dir_path} must be empty`);
344
+ if (!isEmpty) throw new Error(`dir ${dir_path} must be empty`);
354
345
  }
355
346
  async function checkCommandExistsOrThrow(cmd) {
356
347
  try {
@@ -360,13 +351,10 @@ async function checkCommandExistsOrThrow(cmd) {
360
351
  }
361
352
  }
362
353
  async function checkIfFileExistsOrThrow(the_path) {
363
- if (!the_path)
364
- throw "path is empty";
354
+ if (!the_path) throw "path is empty";
365
355
  the_path = removeQuotes(the_path);
366
- if (!await fs.pathExists(the_path))
367
- throw new Error(`path ${the_path} not exists`);
368
- if (!(await fs.stat(the_path)).isFile())
369
- throw new Error(`${the_path} is a dir, require file`);
356
+ if (!await fs.pathExists(the_path)) throw new Error(`path ${the_path} not exists`);
357
+ if (!(await fs.stat(the_path)).isFile()) throw new Error(`${the_path} is a dir, require file`);
370
358
  }
371
359
  function removeQuotes(str) {
372
360
  if (str.startsWith('"') && str.endsWith('"')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/stdlib",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -57,7 +57,7 @@
57
57
  "command-exists": "^1.2.9",
58
58
  "express": "^5.1.0",
59
59
  "node-fetch": "^3.3.2",
60
- "tsup": "^8.0.1",
61
- "typescript": "^4.9.5"
60
+ "tsup": "^8.5.0",
61
+ "typescript": "^5.9.2"
62
62
  }
63
63
  }