@rg-dev/stdlib 1.0.52 → 1.0.54

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.
@@ -19,10 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/browser-env.ts
20
20
  var browser_env_exports = {};
21
21
  __export(browser_env_exports, {
22
+ VERSION: () => VERSION,
22
23
  copyToClipboard: () => copyToClipboard,
23
24
  parseFormData: () => parseFormData
24
25
  });
25
26
  module.exports = __toCommonJS(browser_env_exports);
27
+
28
+ // src/index.ts
29
+ var VERSION = "1";
30
+
31
+ // src/browser-env.ts
26
32
  function parseFormData(e) {
27
33
  if (e instanceof FormData) {
28
34
  return Object.fromEntries(e.entries());
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.cjs';
2
+
1
3
  declare function parseFormData<T = Record<string, string>>(e: Event | FormData | HTMLFormElement): T;
2
4
  declare function copyToClipboard(content: any, opts?: {
3
5
  throwOnError: boolean;
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.js';
2
+
1
3
  declare function parseFormData<T = Record<string, string>>(e: Event | FormData | HTMLFormElement): T;
2
4
  declare function copyToClipboard(content: any, opts?: {
3
5
  throwOnError: boolean;
@@ -1,3 +1,6 @@
1
+ // src/index.ts
2
+ var VERSION = "1";
3
+
1
4
  // src/browser-env.ts
2
5
  function parseFormData(e) {
3
6
  if (e instanceof FormData) {
@@ -67,6 +70,7 @@ function fallback(content) {
67
70
  }
68
71
  }
69
72
  export {
73
+ VERSION,
70
74
  copyToClipboard,
71
75
  parseFormData
72
76
  };
@@ -36,6 +36,7 @@ var common_env_exports = {};
36
36
  __export(common_env_exports, {
37
37
  Optional: () => Optional,
38
38
  StringBuilder: () => StringBuilder,
39
+ VERSION: () => VERSION,
39
40
  catchInline: () => catchInline,
40
41
  doSafe: () => doSafe,
41
42
  fetchHelperJSON: () => fetchHelperJSON,
@@ -44,6 +45,7 @@ __export(common_env_exports, {
44
45
  isNonEmptyString: () => isNonEmptyString,
45
46
  isNumber: () => isNumber,
46
47
  isRunningOnServer: () => isRunningOnServer,
48
+ lazyValue: () => lazyValue,
47
49
  promiseRetry: () => promiseRetry,
48
50
  promiseWithTimeout: () => promiseWithTimeout,
49
51
  sleep: () => sleep,
@@ -51,6 +53,9 @@ __export(common_env_exports, {
51
53
  });
52
54
  module.exports = __toCommonJS(common_env_exports);
53
55
 
56
+ // src/index.ts
57
+ var VERSION = "1";
58
+
54
59
  // src/promise-retry.ts
55
60
  var defaultOptions = {
56
61
  maxAttempts: 10,
@@ -255,3 +260,14 @@ function isPromise(value) {
255
260
  function isNonEmptyString(str) {
256
261
  return typeof str == "string" && str.trim().length > 0;
257
262
  }
263
+ function lazyValue(function_) {
264
+ let isCalled = false;
265
+ let result = void 0;
266
+ return () => {
267
+ if (!isCalled) {
268
+ isCalled = true;
269
+ result = function_();
270
+ }
271
+ return result;
272
+ };
273
+ }
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.cjs';
2
+
1
3
  type Options = {
2
4
  maxAttempts: number;
3
5
  retryDelay: number;
@@ -73,5 +75,6 @@ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Erro
73
75
  declare function isRunningOnServer(): boolean;
74
76
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
75
77
  declare function isNonEmptyString(str?: string): boolean;
78
+ declare function lazyValue<T = unknown>(function_: () => T): () => T;
76
79
 
77
- export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
80
+ export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.js';
2
+
1
3
  type Options = {
2
4
  maxAttempts: number;
3
5
  retryDelay: number;
@@ -73,5 +75,6 @@ declare function doSafe(safe: () => Promise<void> | void, onError?: (error: Erro
73
75
  declare function isRunningOnServer(): boolean;
74
76
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
75
77
  declare function isNonEmptyString(str?: string): boolean;
78
+ declare function lazyValue<T = unknown>(function_: () => T): () => T;
76
79
 
77
- export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
80
+ export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPost, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, lazyValue, promiseRetry, promiseWithTimeout, sleep, useServer };
package/lib/common-env.js CHANGED
@@ -16,6 +16,9 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
18
 
19
+ // src/index.ts
20
+ var VERSION = "1";
21
+
19
22
  // src/promise-retry.ts
20
23
  var defaultOptions = {
21
24
  maxAttempts: 10,
@@ -220,9 +223,21 @@ function isPromise(value) {
220
223
  function isNonEmptyString(str) {
221
224
  return typeof str == "string" && str.trim().length > 0;
222
225
  }
226
+ function lazyValue(function_) {
227
+ let isCalled = false;
228
+ let result = void 0;
229
+ return () => {
230
+ if (!isCalled) {
231
+ isCalled = true;
232
+ result = function_();
233
+ }
234
+ return result;
235
+ };
236
+ }
223
237
  export {
224
238
  Optional,
225
239
  StringBuilder,
240
+ VERSION,
226
241
  catchInline,
227
242
  doSafe,
228
243
  fetchHelperJSON,
@@ -231,6 +246,7 @@ export {
231
246
  isNonEmptyString,
232
247
  isNumber,
233
248
  isRunningOnServer,
249
+ lazyValue,
234
250
  promiseRetry,
235
251
  promiseWithTimeout,
236
252
  sleep,
@@ -6182,12 +6182,16 @@ var init_src = __esm({
6182
6182
  // src/node-download.ts
6183
6183
  var node_download_exports = {};
6184
6184
  __export(node_download_exports, {
6185
+ VERSION: () => VERSION,
6185
6186
  downloadFile: () => downloadFile
6186
6187
  });
6187
6188
  module.exports = __toCommonJS(node_download_exports);
6188
6189
  var fs2 = __toESM(require("fs"), 1);
6189
6190
  var import_stream = require("stream");
6190
6191
 
6192
+ // src/index.ts
6193
+ var VERSION = "1";
6194
+
6191
6195
  // src/common-env.ts
6192
6196
  async function catchInline(cb) {
6193
6197
  try {
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.cjs';
2
+
1
3
  declare function downloadFile(url: string, destination: string, headers?: Record<string, any>): Promise<string>;
2
4
 
3
5
  export { downloadFile };
@@ -1,3 +1,5 @@
1
+ export { VERSION } from './index.js';
2
+
1
3
  declare function downloadFile(url: string, destination: string, headers?: Record<string, any>): Promise<string>;
2
4
 
3
5
  export { downloadFile };
@@ -6188,6 +6188,9 @@ var init_src = __esm({
6188
6188
  import * as fs2 from "fs";
6189
6189
  import { Readable } from "stream";
6190
6190
 
6191
+ // src/index.ts
6192
+ var VERSION = "1";
6193
+
6191
6194
  // src/common-env.ts
6192
6195
  async function catchInline(cb) {
6193
6196
  try {
@@ -6237,6 +6240,7 @@ function downloadFile(url, destination, headers) {
6237
6240
  );
6238
6241
  }
6239
6242
  export {
6243
+ VERSION,
6240
6244
  downloadFile
6241
6245
  };
6242
6246
  /*! Bundled license information:
package/lib/node-env.cjs CHANGED
@@ -51,7 +51,7 @@ var require_command_exists = __commonJS({
51
51
  var exec = require("child_process").exec;
52
52
  var execSync = require("child_process").execSync;
53
53
  var fs2 = require("fs");
54
- var path2 = require("path");
54
+ var path3 = require("path");
55
55
  var access = fs2.access;
56
56
  var accessSync = fs2.accessSync;
57
57
  var constants = fs2.constants || fs2;
@@ -155,8 +155,8 @@ var require_command_exists = __commonJS({
155
155
  cleanInput = function(s) {
156
156
  var isPathName = /[\\]/.test(s);
157
157
  if (isPathName) {
158
- var dirname = '"' + path2.dirname(s) + '"';
159
- var basename = '"' + path2.basename(s) + '"';
158
+ var dirname = '"' + path3.dirname(s) + '"';
159
+ var basename = '"' + path3.basename(s) + '"';
160
160
  return dirname + ":" + basename;
161
161
  }
162
162
  return '"' + s + '"';
@@ -204,12 +204,14 @@ var node_env_exports = {};
204
204
  __export(node_env_exports, {
205
205
  SSEClient: () => SSEClient,
206
206
  SSEResponse: () => SSEResponse,
207
+ VERSION: () => VERSION,
207
208
  checkCommandExistsOrThrow: () => checkCommandExistsOrThrow,
208
209
  checkIfDirExistsOrThrow: () => checkIfDirExistsOrThrow,
209
210
  checkIfFileExistsOrThrow: () => checkIfFileExistsOrThrow,
210
211
  chmodPlusX: () => chmodPlusX,
211
212
  createTempDir: () => createTempDir,
212
213
  createTempFilePath: () => createTempFilePath,
214
+ getEnvPaths: () => getEnvPaths,
213
215
  isWindows: () => isWindows,
214
216
  throwIfDirNotEmpty: () => throwIfDirNotEmpty,
215
217
  typedSystemArch: () => typedSystemArch
@@ -338,7 +340,69 @@ var SSEClient = class extends import_events.EventEmitter {
338
340
  }
339
341
  };
340
342
 
343
+ // src/index.ts
344
+ var VERSION = "1";
345
+
346
+ // node_modules/env-paths/index.js
347
+ var import_node_path = __toESM(require("path"), 1);
348
+ var import_node_os = __toESM(require("os"), 1);
349
+ var import_node_process = __toESM(require("process"), 1);
350
+ var homedir = import_node_os.default.homedir();
351
+ var tmpdir = import_node_os.default.tmpdir();
352
+ var { env } = import_node_process.default;
353
+ var macos = (name) => {
354
+ const library = import_node_path.default.join(homedir, "Library");
355
+ return {
356
+ data: import_node_path.default.join(library, "Application Support", name),
357
+ config: import_node_path.default.join(library, "Preferences", name),
358
+ cache: import_node_path.default.join(library, "Caches", name),
359
+ log: import_node_path.default.join(library, "Logs", name),
360
+ temp: import_node_path.default.join(tmpdir, name)
361
+ };
362
+ };
363
+ var windows = (name) => {
364
+ const appData = env.APPDATA || import_node_path.default.join(homedir, "AppData", "Roaming");
365
+ const localAppData = env.LOCALAPPDATA || import_node_path.default.join(homedir, "AppData", "Local");
366
+ return {
367
+ // Data/config/cache/log are invented by me as Windows isn't opinionated about this
368
+ data: import_node_path.default.join(localAppData, name, "Data"),
369
+ config: import_node_path.default.join(appData, name, "Config"),
370
+ cache: import_node_path.default.join(localAppData, name, "Cache"),
371
+ log: import_node_path.default.join(localAppData, name, "Log"),
372
+ temp: import_node_path.default.join(tmpdir, name)
373
+ };
374
+ };
375
+ var linux = (name) => {
376
+ const username = import_node_path.default.basename(homedir);
377
+ return {
378
+ data: import_node_path.default.join(env.XDG_DATA_HOME || import_node_path.default.join(homedir, ".local", "share"), name),
379
+ config: import_node_path.default.join(env.XDG_CONFIG_HOME || import_node_path.default.join(homedir, ".config"), name),
380
+ cache: import_node_path.default.join(env.XDG_CACHE_HOME || import_node_path.default.join(homedir, ".cache"), name),
381
+ // https://wiki.debian.org/XDGBaseDirectorySpecification#state
382
+ log: import_node_path.default.join(env.XDG_STATE_HOME || import_node_path.default.join(homedir, ".local", "state"), name),
383
+ temp: import_node_path.default.join(tmpdir, username, name)
384
+ };
385
+ };
386
+ function envPaths(name, { suffix = "nodejs" } = {}) {
387
+ if (typeof name !== "string") {
388
+ throw new TypeError(`Expected a string, got ${typeof name}`);
389
+ }
390
+ if (suffix) {
391
+ name += `-${suffix}`;
392
+ }
393
+ if (import_node_process.default.platform === "darwin") {
394
+ return macos(name);
395
+ }
396
+ if (import_node_process.default.platform === "win32") {
397
+ return windows(name);
398
+ }
399
+ return linux(name);
400
+ }
401
+
341
402
  // src/node-env.ts
403
+ function getEnvPaths(name, options) {
404
+ return envPaths(name, options);
405
+ }
342
406
  function isWindows() {
343
407
  return import_os.default.platform() === "win32";
344
408
  }
@@ -358,14 +422,14 @@ function chmodPlusX(filePath) {
358
422
  console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
359
423
  }
360
424
  }
361
- async function checkIfDirExistsOrThrow(path2) {
362
- if (!path2) throw "path is empty";
363
- path2 = removeQuotes(path2);
364
- if (!await fs.pathExists(path2)) {
365
- throw new Error(`path ${path2} not exists`);
425
+ async function checkIfDirExistsOrThrow(path3) {
426
+ if (!path3) throw "path is empty";
427
+ path3 = removeQuotes(path3);
428
+ if (!await fs.pathExists(path3)) {
429
+ throw new Error(`path ${path3} not exists`);
366
430
  }
367
- if (!(await fs.stat(path2)).isDirectory()) {
368
- throw new Error(`${path2} is a file, require dir`);
431
+ if (!(await fs.stat(path3)).isDirectory()) {
432
+ throw new Error(`${path3} is a file, require dir`);
369
433
  }
370
434
  }
371
435
  function createTempDir() {
@@ -1,5 +1,6 @@
1
1
  import { Response } from 'express';
2
2
  import { EventEmitter } from 'events';
3
+ export { VERSION } from './index.cjs';
3
4
 
4
5
  declare class SSEResponse<Events extends string = 'message'> {
5
6
  private res;
@@ -27,6 +28,75 @@ declare class SSEClient extends EventEmitter {
27
28
  close(): void;
28
29
  }
29
30
 
31
+ interface Options {
32
+ /**
33
+ __Don't use this option unless you really have to!__
34
+
35
+ Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
36
+
37
+ @default 'nodejs'
38
+ */
39
+ readonly suffix?: string;
40
+ }
41
+
42
+ interface Paths {
43
+ /**
44
+ Directory for data files.
45
+
46
+ Example locations (with the default `nodejs` suffix):
47
+
48
+ - macOS: `~/Library/Application Support/MyApp-nodejs`
49
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
50
+ - Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
51
+ */
52
+ readonly data: string;
53
+
54
+ /**
55
+ Directory for data files.
56
+
57
+ Example locations (with the default `nodejs` suffix):
58
+
59
+ - macOS: `~/Library/Preferences/MyApp-nodejs`
60
+ - Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
61
+ - Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
62
+ */
63
+ readonly config: string;
64
+
65
+ /**
66
+ Directory for non-essential data files.
67
+
68
+ Example locations (with the default `nodejs` suffix):
69
+
70
+ - macOS: `~/Library/Caches/MyApp-nodejs`
71
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
72
+ - Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
73
+ */
74
+ readonly cache: string;
75
+
76
+ /**
77
+ Directory for log files.
78
+
79
+ Example locations (with the default `nodejs` suffix):
80
+
81
+ - macOS: `~/Library/Logs/MyApp-nodejs`
82
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
83
+ - Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
84
+ */
85
+ readonly log: string;
86
+
87
+ /**
88
+ Directory for temporary files.
89
+
90
+ Example locations (with the default `nodejs` suffix):
91
+
92
+ - macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
93
+ - Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
94
+ - Linux: `/tmp/USERNAME/MyApp-nodejs`
95
+ */
96
+ readonly temp: string;
97
+ }
98
+
99
+ declare function getEnvPaths(name: string, options?: Options): Paths;
30
100
  declare function isWindows(): boolean;
31
101
  type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
32
102
  declare function typedSystemArch(): SystemArch;
@@ -41,4 +111,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
41
111
  declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
42
112
  declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
43
113
 
44
- export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
114
+ export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };
package/lib/node-env.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Response } from 'express';
2
2
  import { EventEmitter } from 'events';
3
+ export { VERSION } from './index.js';
3
4
 
4
5
  declare class SSEResponse<Events extends string = 'message'> {
5
6
  private res;
@@ -27,6 +28,75 @@ declare class SSEClient extends EventEmitter {
27
28
  close(): void;
28
29
  }
29
30
 
31
+ interface Options {
32
+ /**
33
+ __Don't use this option unless you really have to!__
34
+
35
+ Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
36
+
37
+ @default 'nodejs'
38
+ */
39
+ readonly suffix?: string;
40
+ }
41
+
42
+ interface Paths {
43
+ /**
44
+ Directory for data files.
45
+
46
+ Example locations (with the default `nodejs` suffix):
47
+
48
+ - macOS: `~/Library/Application Support/MyApp-nodejs`
49
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
50
+ - Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
51
+ */
52
+ readonly data: string;
53
+
54
+ /**
55
+ Directory for data files.
56
+
57
+ Example locations (with the default `nodejs` suffix):
58
+
59
+ - macOS: `~/Library/Preferences/MyApp-nodejs`
60
+ - Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
61
+ - Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
62
+ */
63
+ readonly config: string;
64
+
65
+ /**
66
+ Directory for non-essential data files.
67
+
68
+ Example locations (with the default `nodejs` suffix):
69
+
70
+ - macOS: `~/Library/Caches/MyApp-nodejs`
71
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
72
+ - Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
73
+ */
74
+ readonly cache: string;
75
+
76
+ /**
77
+ Directory for log files.
78
+
79
+ Example locations (with the default `nodejs` suffix):
80
+
81
+ - macOS: `~/Library/Logs/MyApp-nodejs`
82
+ - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
83
+ - Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
84
+ */
85
+ readonly log: string;
86
+
87
+ /**
88
+ Directory for temporary files.
89
+
90
+ Example locations (with the default `nodejs` suffix):
91
+
92
+ - macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
93
+ - Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
94
+ - Linux: `/tmp/USERNAME/MyApp-nodejs`
95
+ */
96
+ readonly temp: string;
97
+ }
98
+
99
+ declare function getEnvPaths(name: string, options?: Options): Paths;
30
100
  declare function isWindows(): boolean;
31
101
  type SystemArch = "x64" | "arm64" | "arm" | "ia32" | "ppc64" | "s390x" | "loong64" | "riscv64";
32
102
  declare function typedSystemArch(): SystemArch;
@@ -41,4 +111,4 @@ declare function throwIfDirNotEmpty(dirPath: string): Promise<void>;
41
111
  declare function checkCommandExistsOrThrow(cmd: string): Promise<void>;
42
112
  declare function checkIfFileExistsOrThrow(thePath: string): Promise<void>;
43
113
 
44
- export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, isWindows, throwIfDirNotEmpty, typedSystemArch };
114
+ export { SSEClient, SSEResponse, type SystemArch, checkCommandExistsOrThrow, checkIfDirExistsOrThrow, checkIfFileExistsOrThrow, chmodPlusX, createTempDir, createTempFilePath, getEnvPaths, isWindows, throwIfDirNotEmpty, typedSystemArch };
package/lib/node-env.js CHANGED
@@ -52,7 +52,7 @@ var require_command_exists = __commonJS({
52
52
  var exec = __require("child_process").exec;
53
53
  var execSync = __require("child_process").execSync;
54
54
  var fs2 = __require("fs");
55
- var path2 = __require("path");
55
+ var path3 = __require("path");
56
56
  var access = fs2.access;
57
57
  var accessSync = fs2.accessSync;
58
58
  var constants = fs2.constants || fs2;
@@ -156,8 +156,8 @@ var require_command_exists = __commonJS({
156
156
  cleanInput = function(s) {
157
157
  var isPathName = /[\\]/.test(s);
158
158
  if (isPathName) {
159
- var dirname = '"' + path2.dirname(s) + '"';
160
- var basename = '"' + path2.basename(s) + '"';
159
+ var dirname = '"' + path3.dirname(s) + '"';
160
+ var basename = '"' + path3.basename(s) + '"';
161
161
  return dirname + ":" + basename;
162
162
  }
163
163
  return '"' + s + '"';
@@ -203,8 +203,8 @@ var require_command_exists2 = __commonJS({
203
203
  // src/node-env.ts
204
204
  var import_command_exists = __toESM(require_command_exists2(), 1);
205
205
  import * as fs from "fs-extra";
206
- import os from "os";
207
- import path from "path";
206
+ import os2 from "os";
207
+ import path2 from "path";
208
208
 
209
209
  // src/SSEResponse.ts
210
210
  var SSEResponse = class {
@@ -324,19 +324,81 @@ var SSEClient = class extends EventEmitter {
324
324
  }
325
325
  };
326
326
 
327
+ // src/index.ts
328
+ var VERSION = "1";
329
+
330
+ // node_modules/env-paths/index.js
331
+ import path from "path";
332
+ import os from "os";
333
+ import process2 from "process";
334
+ var homedir = os.homedir();
335
+ var tmpdir = os.tmpdir();
336
+ var { env } = process2;
337
+ var macos = (name) => {
338
+ const library = path.join(homedir, "Library");
339
+ return {
340
+ data: path.join(library, "Application Support", name),
341
+ config: path.join(library, "Preferences", name),
342
+ cache: path.join(library, "Caches", name),
343
+ log: path.join(library, "Logs", name),
344
+ temp: path.join(tmpdir, name)
345
+ };
346
+ };
347
+ var windows = (name) => {
348
+ const appData = env.APPDATA || path.join(homedir, "AppData", "Roaming");
349
+ const localAppData = env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
350
+ return {
351
+ // Data/config/cache/log are invented by me as Windows isn't opinionated about this
352
+ data: path.join(localAppData, name, "Data"),
353
+ config: path.join(appData, name, "Config"),
354
+ cache: path.join(localAppData, name, "Cache"),
355
+ log: path.join(localAppData, name, "Log"),
356
+ temp: path.join(tmpdir, name)
357
+ };
358
+ };
359
+ var linux = (name) => {
360
+ const username = path.basename(homedir);
361
+ return {
362
+ data: path.join(env.XDG_DATA_HOME || path.join(homedir, ".local", "share"), name),
363
+ config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, ".config"), name),
364
+ cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, ".cache"), name),
365
+ // https://wiki.debian.org/XDGBaseDirectorySpecification#state
366
+ log: path.join(env.XDG_STATE_HOME || path.join(homedir, ".local", "state"), name),
367
+ temp: path.join(tmpdir, username, name)
368
+ };
369
+ };
370
+ function envPaths(name, { suffix = "nodejs" } = {}) {
371
+ if (typeof name !== "string") {
372
+ throw new TypeError(`Expected a string, got ${typeof name}`);
373
+ }
374
+ if (suffix) {
375
+ name += `-${suffix}`;
376
+ }
377
+ if (process2.platform === "darwin") {
378
+ return macos(name);
379
+ }
380
+ if (process2.platform === "win32") {
381
+ return windows(name);
382
+ }
383
+ return linux(name);
384
+ }
385
+
327
386
  // src/node-env.ts
387
+ function getEnvPaths(name, options) {
388
+ return envPaths(name, options);
389
+ }
328
390
  function isWindows() {
329
- return os.platform() === "win32";
391
+ return os2.platform() === "win32";
330
392
  }
331
393
  function typedSystemArch() {
332
- return os.arch();
394
+ return os2.arch();
333
395
  }
334
396
  function chmodPlusX(filePath) {
335
- if (os.platform() === "win32") {
397
+ if (os2.platform() === "win32") {
336
398
  return;
337
399
  }
338
400
  try {
339
- const resolvedPath = path.resolve(filePath);
401
+ const resolvedPath = path2.resolve(filePath);
340
402
  const stats = fs.statSync(resolvedPath);
341
403
  const newMode = stats.mode | 73;
342
404
  fs.chmodSync(resolvedPath, newMode);
@@ -344,21 +406,21 @@ function chmodPlusX(filePath) {
344
406
  console.error(`Failed to chmod +x ${filePath}:`, String((e == null ? void 0 : e.message) || e));
345
407
  }
346
408
  }
347
- async function checkIfDirExistsOrThrow(path2) {
348
- if (!path2) throw "path is empty";
349
- path2 = removeQuotes(path2);
350
- if (!await fs.pathExists(path2)) {
351
- throw new Error(`path ${path2} not exists`);
409
+ async function checkIfDirExistsOrThrow(path3) {
410
+ if (!path3) throw "path is empty";
411
+ path3 = removeQuotes(path3);
412
+ if (!await fs.pathExists(path3)) {
413
+ throw new Error(`path ${path3} not exists`);
352
414
  }
353
- if (!(await fs.stat(path2)).isDirectory()) {
354
- throw new Error(`${path2} is a file, require dir`);
415
+ if (!(await fs.stat(path3)).isDirectory()) {
416
+ throw new Error(`${path3} is a file, require dir`);
355
417
  }
356
418
  }
357
419
  function createTempDir() {
358
- const tmpDir = os.tmpdir();
420
+ const tmpDir = os2.tmpdir();
359
421
  const timestamp = Date.now();
360
422
  const tempDirName = `temp_dir_${timestamp}_${Math.random().toString(36).slice(2)}`;
361
- const tempDirPath = path.join(tmpDir, tempDirName);
423
+ const tempDirPath = path2.join(tmpDir, tempDirName);
362
424
  console.log("tempDir", tempDirPath);
363
425
  fs.mkdirSync(tempDirPath);
364
426
  return tempDirPath;
@@ -372,7 +434,7 @@ function createTempFilePath(ext) {
372
434
  ext = void 0;
373
435
  }
374
436
  const name = `temp_file_${process.pid}_${Date.now()}_${Math.random().toString(36).slice(2)}${ext ? `.${ext}` : ""}`;
375
- const fullPath = path.join(os.tmpdir(), name);
437
+ const fullPath = path2.join(os2.tmpdir(), name);
376
438
  return {
377
439
  getName: () => fullPath,
378
440
  cleanUp: () => {
@@ -419,12 +481,14 @@ function removeQuotes(str) {
419
481
  export {
420
482
  SSEClient,
421
483
  SSEResponse,
484
+ VERSION,
422
485
  checkCommandExistsOrThrow,
423
486
  checkIfDirExistsOrThrow,
424
487
  checkIfFileExistsOrThrow,
425
488
  chmodPlusX,
426
489
  createTempDir,
427
490
  createTempFilePath,
491
+ getEnvPaths,
428
492
  isWindows,
429
493
  throwIfDirNotEmpty,
430
494
  typedSystemArch
@@ -46,12 +46,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
46
46
  // src/trpc-helpers.ts
47
47
  var trpc_helpers_exports = {};
48
48
  __export(trpc_helpers_exports, {
49
- TrpcServerHelpers: () => TrpcServerHelpers
49
+ TrpcServerHelpers: () => TrpcServerHelpers,
50
+ VERSION: () => VERSION
50
51
  });
51
52
  module.exports = __toCommonJS(trpc_helpers_exports);
52
53
  var import_server = require("@trpc/server");
53
54
  var trpcExpress = __toESM(require("@trpc/server/adapters/express"), 1);
54
55
  var import_superjson = __toESM(require("superjson"), 1);
56
+
57
+ // src/index.ts
58
+ var VERSION = "1";
59
+
60
+ // src/trpc-helpers.ts
55
61
  var TrpcServerHelpers = class {
56
62
  static createExpressTrpcServer() {
57
63
  if (globalThis.Headers == void 0) {
@@ -1,6 +1,7 @@
1
1
  import { initTRPC } from '@trpc/server';
2
2
  import * as trpcExpress from '@trpc/server/adapters/express';
3
3
  import { Handler } from 'express';
4
+ export { VERSION } from './index.cjs';
4
5
 
5
6
  type TrpcExpressRootType = ReturnType<ReturnType<typeof initTRPC.context<trpcExpress.CreateExpressContextOptions>>['create']>;
6
7
  declare class TrpcServerHelpers {
@@ -1,6 +1,7 @@
1
1
  import { initTRPC } from '@trpc/server';
2
2
  import * as trpcExpress from '@trpc/server/adapters/express';
3
3
  import { Handler } from 'express';
4
+ export { VERSION } from './index.js';
4
5
 
5
6
  type TrpcExpressRootType = ReturnType<ReturnType<typeof initTRPC.context<trpcExpress.CreateExpressContextOptions>>['create']>;
6
7
  declare class TrpcServerHelpers {
@@ -22,6 +22,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  import { initTRPC } from "@trpc/server";
23
23
  import * as trpcExpress from "@trpc/server/adapters/express";
24
24
  import superjson from "superjson";
25
+
26
+ // src/index.ts
27
+ var VERSION = "1";
28
+
29
+ // src/trpc-helpers.ts
25
30
  var TrpcServerHelpers = class {
26
31
  static createExpressTrpcServer() {
27
32
  if (globalThis.Headers == void 0) {
@@ -39,5 +44,6 @@ var TrpcServerHelpers = class {
39
44
  }
40
45
  };
41
46
  export {
42
- TrpcServerHelpers
47
+ TrpcServerHelpers,
48
+ VERSION
43
49
  };
package/package.json CHANGED
@@ -1,48 +1,67 @@
1
1
  {
2
2
  "name": "@rg-dev/stdlib",
3
- "version": "1.0.52",
3
+ "version": "1.0.54",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
7
7
  "build": "tsup && node after-build.mjs",
8
- "ts":"tsdown"
8
+ "ts": "tsdown"
9
9
  },
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "files": [
13
13
  "lib"
14
14
  ],
15
-
15
+ "typesVersions": {
16
+ "*": {
17
+ "lib/trpc-helpers": [
18
+ "lib/trpc-helpers.d.ts"
19
+ ],
20
+ "lib/common-env": [
21
+ "lib/common-env.d.ts"
22
+ ],
23
+ "lib/browser-env": [
24
+ "lib/browser-env.d.ts"
25
+ ],
26
+ "lib/node-env": [
27
+ "lib/node-env.d.ts"
28
+ ],
29
+ "lib/node-download": [
30
+ "lib/node-download.d.ts"
31
+ ]
32
+ }
33
+ },
16
34
  "types": "./lib/index.d.ts",
17
35
  "type": "module",
18
36
  "exports": {
19
-
20
- ".":{
37
+ ".": {
21
38
  "import": "./lib/index.js",
22
- "require": "./lib/index.cjs"
39
+ "require": "./lib/index.cjs",
40
+ "types": "./lib/index.d.ts"
23
41
  },
24
-
25
-
26
42
  "./lib/trpc-helpers": {
27
43
  "import": "./lib/trpc-helpers.js",
28
- "require": "./lib/trpc-helpers.cjs"
44
+ "require": "./lib/trpc-helpers.cjs",
45
+ "types": "./lib/trpc-helpers.d.ts"
29
46
  },
30
47
  "./lib/node-env": {
31
48
  "import": "./lib/node-env.js",
32
- "require": "./lib/node-env.cjs"
49
+ "require": "./lib/node-env.cjs",
50
+ "types": "./lib/node-env.d.ts"
33
51
  },
34
52
  "./lib/browser-env": {
35
- "import": "./lib/browser-env.js"
53
+ "import": "./lib/browser-env.js",
54
+ "types": "./lib/browser-env.d.ts"
36
55
  },
37
56
  "./lib/common-env": {
38
57
  "import": "./lib/common-env.js",
39
- "require": "./lib/common-env.cjs"
40
-
58
+ "require": "./lib/common-env.cjs",
59
+ "types": "./lib/common-env.d.ts"
41
60
  },
42
61
  "./lib/node-download": {
43
62
  "import": "./lib/node-download.js",
44
- "require": "./lib/node-download.cjs"
45
-
63
+ "require": "./lib/node-download.cjs",
64
+ "types": "./lib/node-download.d.ts"
46
65
  }
47
66
  },
48
67
  "dependencies": {
@@ -52,7 +71,7 @@
52
71
  "access": "public"
53
72
  },
54
73
  "devDependencies": {
55
- "tsdown": "^0.19.0",
74
+ "env-paths": "^3.0.0",
56
75
  "@trpc/server": "^11.1.1",
57
76
  "@types/command-exists": "^1.2.3",
58
77
  "@types/express": "^5.0.6",
@@ -63,6 +82,7 @@
63
82
  "express": "^5.1.0",
64
83
  "node-fetch": "^3.3.2",
65
84
  "superjson": "^2.2.6",
85
+ "tsdown": "^0.19.0",
66
86
  "tsup": "^8.0.1",
67
87
  "typescript": "^5.9.3"
68
88
  }