@settlemint/sdk-utils 2.3.2-pr6cb5dd2e → 2.3.2-pr74f654b5

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.
Files changed (89) hide show
  1. package/README.md +51 -7
  2. package/dist/environment.cjs +25 -408
  3. package/dist/environment.d.cts +3 -176
  4. package/dist/environment.d.ts +3 -176
  5. package/dist/environment.js +4 -0
  6. package/dist/filesystem.cjs +39 -123
  7. package/dist/filesystem.d.cts +4 -59
  8. package/dist/filesystem.d.ts +4 -59
  9. package/dist/filesystem.js +5 -0
  10. package/dist/http.cjs +35 -147
  11. package/dist/http.d.cts +4 -50
  12. package/dist/http.d.ts +4 -50
  13. package/dist/http.js +5 -0
  14. package/dist/index.cjs +27 -184
  15. package/dist/index.d.cts +4 -122
  16. package/dist/index.d.ts +4 -122
  17. package/dist/index.js +7 -0
  18. package/dist/json.cjs +83 -0
  19. package/dist/json.cjs.map +1 -0
  20. package/dist/json.d.cts +56 -0
  21. package/dist/json.d.ts +56 -0
  22. package/dist/json.js +80 -0
  23. package/dist/json.js.map +1 -0
  24. package/dist/logging.cjs +34 -141
  25. package/dist/logging.d.cts +4 -70
  26. package/dist/logging.d.ts +4 -70
  27. package/dist/logging.js +5 -0
  28. package/dist/package-manager.cjs +51 -196
  29. package/dist/package-manager.d.cts +7 -114
  30. package/dist/package-manager.d.ts +7 -114
  31. package/dist/package-manager.js +9 -0
  32. package/dist/retry.cjs +69 -0
  33. package/dist/retry.cjs.map +1 -0
  34. package/dist/retry.d.cts +19 -0
  35. package/dist/retry.d.ts +19 -0
  36. package/dist/retry.js +46 -0
  37. package/dist/retry.js.map +1 -0
  38. package/dist/runtime.cjs +38 -42
  39. package/dist/runtime.d.cts +2 -32
  40. package/dist/runtime.d.ts +2 -32
  41. package/dist/runtime.js +3 -0
  42. package/dist/string.cjs +76 -0
  43. package/dist/string.cjs.map +1 -0
  44. package/dist/string.d.cts +58 -0
  45. package/dist/string.d.ts +58 -0
  46. package/dist/string.js +72 -0
  47. package/dist/string.js.map +1 -0
  48. package/dist/terminal.cjs +91 -258
  49. package/dist/terminal.d.cts +11 -219
  50. package/dist/terminal.d.ts +11 -219
  51. package/dist/terminal.js +12 -0
  52. package/dist/url.cjs +25 -0
  53. package/dist/url.cjs.map +1 -0
  54. package/dist/url.d.cts +20 -0
  55. package/dist/url.d.ts +20 -0
  56. package/dist/url.js +24 -0
  57. package/dist/url.js.map +1 -0
  58. package/dist/validation.cjs +89 -183
  59. package/dist/validation.d.cts +7 -239
  60. package/dist/validation.d.ts +7 -239
  61. package/dist/validation.js +8 -0
  62. package/package.json +6 -6
  63. package/dist/environment.cjs.map +0 -1
  64. package/dist/environment.mjs +0 -383
  65. package/dist/environment.mjs.map +0 -1
  66. package/dist/filesystem.cjs.map +0 -1
  67. package/dist/filesystem.mjs +0 -105
  68. package/dist/filesystem.mjs.map +0 -1
  69. package/dist/http.cjs.map +0 -1
  70. package/dist/http.mjs +0 -129
  71. package/dist/http.mjs.map +0 -1
  72. package/dist/index.cjs.map +0 -1
  73. package/dist/index.mjs +0 -156
  74. package/dist/index.mjs.map +0 -1
  75. package/dist/logging.cjs.map +0 -1
  76. package/dist/logging.mjs +0 -123
  77. package/dist/logging.mjs.map +0 -1
  78. package/dist/package-manager.cjs.map +0 -1
  79. package/dist/package-manager.mjs +0 -167
  80. package/dist/package-manager.mjs.map +0 -1
  81. package/dist/runtime.cjs.map +0 -1
  82. package/dist/runtime.mjs +0 -23
  83. package/dist/runtime.mjs.map +0 -1
  84. package/dist/terminal.cjs.map +0 -1
  85. package/dist/terminal.mjs +0 -230
  86. package/dist/terminal.mjs.map +0 -1
  87. package/dist/validation.cjs.map +0 -1
  88. package/dist/validation.mjs +0 -159
  89. package/dist/validation.mjs.map +0 -1
@@ -0,0 +1,9 @@
1
+ import { getPackageManager } from "./package-manager/get-package-manager.js";
2
+ import { getPackageManagerExecutable } from "./package-manager/get-package-manager-executable.js";
3
+ import { installDependencies } from "./package-manager/install-dependencies.js";
4
+ import { isPackageInstalled } from "./package-manager/is-package-installed.js";
5
+ import { setName } from "./package-manager/set-name.js";
6
+
7
+ export * from "./package-manager/download-and-extract.js"
8
+
9
+ export { getPackageManager, getPackageManagerExecutable, installDependencies, isPackageInstalled, setName };
package/dist/retry.cjs ADDED
@@ -0,0 +1,69 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const src_logging_logger_js = __toESM(require("./logging/logger.js"));
25
+
26
+ //#region src/retry.ts
27
+ /**
28
+ * Retry a function when it fails.
29
+ * @param fn - The function to retry.
30
+ * @param maxRetries - The maximum number of retries.
31
+ * @param initialSleepTime - The initial time to sleep between exponential backoff retries.
32
+ * @param stopOnError - The function to stop on error.
33
+ * @returns The result of the function or undefined if it fails.
34
+ * @example
35
+ * import { retryWhenFailed } from "@settlemint/sdk-utils";
36
+ * import { readFile } from "node:fs/promises";
37
+ *
38
+ * const result = await retryWhenFailed(() => readFile("/path/to/file.txt"), 3, 1_000);
39
+ */
40
+ async function retryWhenFailed(fn, maxRetries = 5, initialSleepTime = 1e3, stopOnError) {
41
+ let retries = 0;
42
+ const maxAttempts = maxRetries + 1;
43
+ while (retries < maxAttempts) {
44
+ try {
45
+ return await fn();
46
+ } catch (e) {
47
+ const error = e;
48
+ if (typeof stopOnError === "function") {
49
+ if (stopOnError(error)) {
50
+ throw error;
51
+ }
52
+ }
53
+ if (retries >= maxRetries) {
54
+ throw e;
55
+ }
56
+ const baseDelay = 2 ** retries * initialSleepTime;
57
+ const jitterAmount = initialSleepTime * (Math.random() / 10);
58
+ const delay = baseDelay + jitterAmount;
59
+ retries += 1;
60
+ src_logging_logger_js.logger.warn(`An error occurred ${error.message}, retrying in ${delay.toFixed(0)}ms (retry ${retries} of ${maxRetries})...`);
61
+ await new Promise((resolve) => setTimeout(resolve, delay));
62
+ }
63
+ }
64
+ throw new Error("Retry failed");
65
+ }
66
+
67
+ //#endregion
68
+ exports.retryWhenFailed = retryWhenFailed;
69
+ //# sourceMappingURL=retry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.cjs","names":["fn: () => Promise<T>","stopOnError?: (error: Error) => boolean"],"sources":["../src/retry.ts"],"sourcesContent":["import { logger } from \"./logging/logger.js\";\n\n/**\n * Retry a function when it fails.\n * @param fn - The function to retry.\n * @param maxRetries - The maximum number of retries.\n * @param initialSleepTime - The initial time to sleep between exponential backoff retries.\n * @param stopOnError - The function to stop on error.\n * @returns The result of the function or undefined if it fails.\n * @example\n * import { retryWhenFailed } from \"@settlemint/sdk-utils\";\n * import { readFile } from \"node:fs/promises\";\n *\n * const result = await retryWhenFailed(() => readFile(\"/path/to/file.txt\"), 3, 1_000);\n */\nexport async function retryWhenFailed<T>(\n fn: () => Promise<T>,\n maxRetries = 5,\n initialSleepTime = 1_000,\n stopOnError?: (error: Error) => boolean,\n): Promise<T> {\n let retries = 0;\n const maxAttempts = maxRetries + 1;\n\n while (retries < maxAttempts) {\n try {\n return await fn();\n } catch (e) {\n const error = e as Error;\n if (typeof stopOnError === \"function\") {\n if (stopOnError(error)) {\n throw error;\n }\n }\n if (retries >= maxRetries) {\n throw e;\n }\n // Exponential backoff with jitter to prevent thundering herd\n // Jitter: Random value between 0-10% of initialSleepTime\n const baseDelay = 2 ** retries * initialSleepTime;\n const jitterAmount = initialSleepTime * (Math.random() / 10);\n const delay = baseDelay + jitterAmount;\n retries += 1;\n logger.warn(\n `An error occurred ${error.message}, retrying in ${delay.toFixed(0)}ms (retry ${retries} of ${maxRetries})...`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw new Error(\"Retry failed\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,eAAsB,gBACpBA,IACA,aAAa,GACb,mBAAmB,KACnBC,aACY;CACZ,IAAI,UAAU;CACd,MAAM,cAAc,aAAa;AAEjC,QAAO,UAAU,aAAa;AAC5B,MAAI;AACF,UAAO,MAAM,IAAI;EAClB,SAAQ,GAAG;GACV,MAAM,QAAQ;AACd,cAAW,gBAAgB,YAAY;AACrC,QAAI,YAAY,MAAM,EAAE;AACtB,WAAM;IACP;GACF;AACD,OAAI,WAAW,YAAY;AACzB,UAAM;GACP;GAGD,MAAM,YAAY,KAAK,UAAU;GACjC,MAAM,eAAe,oBAAoB,KAAK,QAAQ,GAAG;GACzD,MAAM,QAAQ,YAAY;AAC1B,cAAW;AACX,gCAAO,MACJ,oBAAoB,MAAM,QAAQ,gBAAgB,MAAM,QAAQ,EAAE,CAAC,YAAY,QAAQ,MAAM,WAAW,MAC1G;AACD,SAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,MAAM;EAC1D;CACF;AAED,OAAM,IAAI,MAAM;AACjB"}
@@ -0,0 +1,19 @@
1
+ //#region src/retry.d.ts
2
+ /**
3
+ * Retry a function when it fails.
4
+ * @param fn - The function to retry.
5
+ * @param maxRetries - The maximum number of retries.
6
+ * @param initialSleepTime - The initial time to sleep between exponential backoff retries.
7
+ * @param stopOnError - The function to stop on error.
8
+ * @returns The result of the function or undefined if it fails.
9
+ * @example
10
+ * import { retryWhenFailed } from "@settlemint/sdk-utils";
11
+ * import { readFile } from "node:fs/promises";
12
+ *
13
+ * const result = await retryWhenFailed(() => readFile("/path/to/file.txt"), 3, 1_000);
14
+ */
15
+ declare function retryWhenFailed<T>(fn: () => Promise<T>, maxRetries?: number, initialSleepTime?: number, stopOnError?: (error: Error) => boolean): Promise<T>;
16
+
17
+ //#endregion
18
+ export { retryWhenFailed };
19
+ //# sourceMappingURL=retry.d.cts.map
@@ -0,0 +1,19 @@
1
+ //#region src/retry.d.ts
2
+ /**
3
+ * Retry a function when it fails.
4
+ * @param fn - The function to retry.
5
+ * @param maxRetries - The maximum number of retries.
6
+ * @param initialSleepTime - The initial time to sleep between exponential backoff retries.
7
+ * @param stopOnError - The function to stop on error.
8
+ * @returns The result of the function or undefined if it fails.
9
+ * @example
10
+ * import { retryWhenFailed } from "@settlemint/sdk-utils";
11
+ * import { readFile } from "node:fs/promises";
12
+ *
13
+ * const result = await retryWhenFailed(() => readFile("/path/to/file.txt"), 3, 1_000);
14
+ */
15
+ declare function retryWhenFailed<T>(fn: () => Promise<T>, maxRetries?: number, initialSleepTime?: number, stopOnError?: (error: Error) => boolean): Promise<T>;
16
+
17
+ //#endregion
18
+ export { retryWhenFailed };
19
+ //# sourceMappingURL=retry.d.ts.map
package/dist/retry.js ADDED
@@ -0,0 +1,46 @@
1
+ import { logger } from "./logging/logger.js";
2
+
3
+ //#region src/retry.ts
4
+ /**
5
+ * Retry a function when it fails.
6
+ * @param fn - The function to retry.
7
+ * @param maxRetries - The maximum number of retries.
8
+ * @param initialSleepTime - The initial time to sleep between exponential backoff retries.
9
+ * @param stopOnError - The function to stop on error.
10
+ * @returns The result of the function or undefined if it fails.
11
+ * @example
12
+ * import { retryWhenFailed } from "@settlemint/sdk-utils";
13
+ * import { readFile } from "node:fs/promises";
14
+ *
15
+ * const result = await retryWhenFailed(() => readFile("/path/to/file.txt"), 3, 1_000);
16
+ */
17
+ async function retryWhenFailed(fn, maxRetries = 5, initialSleepTime = 1e3, stopOnError) {
18
+ let retries = 0;
19
+ const maxAttempts = maxRetries + 1;
20
+ while (retries < maxAttempts) {
21
+ try {
22
+ return await fn();
23
+ } catch (e) {
24
+ const error = e;
25
+ if (typeof stopOnError === "function") {
26
+ if (stopOnError(error)) {
27
+ throw error;
28
+ }
29
+ }
30
+ if (retries >= maxRetries) {
31
+ throw e;
32
+ }
33
+ const baseDelay = 2 ** retries * initialSleepTime;
34
+ const jitterAmount = initialSleepTime * (Math.random() / 10);
35
+ const delay = baseDelay + jitterAmount;
36
+ retries += 1;
37
+ logger.warn(`An error occurred ${error.message}, retrying in ${delay.toFixed(0)}ms (retry ${retries} of ${maxRetries})...`);
38
+ await new Promise((resolve) => setTimeout(resolve, delay));
39
+ }
40
+ }
41
+ throw new Error("Retry failed");
42
+ }
43
+
44
+ //#endregion
45
+ export { retryWhenFailed };
46
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.js","names":["fn: () => Promise<T>","stopOnError?: (error: Error) => boolean"],"sources":["../src/retry.ts"],"sourcesContent":["import { logger } from \"./logging/logger.js\";\n\n/**\n * Retry a function when it fails.\n * @param fn - The function to retry.\n * @param maxRetries - The maximum number of retries.\n * @param initialSleepTime - The initial time to sleep between exponential backoff retries.\n * @param stopOnError - The function to stop on error.\n * @returns The result of the function or undefined if it fails.\n * @example\n * import { retryWhenFailed } from \"@settlemint/sdk-utils\";\n * import { readFile } from \"node:fs/promises\";\n *\n * const result = await retryWhenFailed(() => readFile(\"/path/to/file.txt\"), 3, 1_000);\n */\nexport async function retryWhenFailed<T>(\n fn: () => Promise<T>,\n maxRetries = 5,\n initialSleepTime = 1_000,\n stopOnError?: (error: Error) => boolean,\n): Promise<T> {\n let retries = 0;\n const maxAttempts = maxRetries + 1;\n\n while (retries < maxAttempts) {\n try {\n return await fn();\n } catch (e) {\n const error = e as Error;\n if (typeof stopOnError === \"function\") {\n if (stopOnError(error)) {\n throw error;\n }\n }\n if (retries >= maxRetries) {\n throw e;\n }\n // Exponential backoff with jitter to prevent thundering herd\n // Jitter: Random value between 0-10% of initialSleepTime\n const baseDelay = 2 ** retries * initialSleepTime;\n const jitterAmount = initialSleepTime * (Math.random() / 10);\n const delay = baseDelay + jitterAmount;\n retries += 1;\n logger.warn(\n `An error occurred ${error.message}, retrying in ${delay.toFixed(0)}ms (retry ${retries} of ${maxRetries})...`,\n );\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw new Error(\"Retry failed\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,eAAsB,gBACpBA,IACA,aAAa,GACb,mBAAmB,KACnBC,aACY;CACZ,IAAI,UAAU;CACd,MAAM,cAAc,aAAa;AAEjC,QAAO,UAAU,aAAa;AAC5B,MAAI;AACF,UAAO,MAAM,IAAI;EAClB,SAAQ,GAAG;GACV,MAAM,QAAQ;AACd,cAAW,gBAAgB,YAAY;AACrC,QAAI,YAAY,MAAM,EAAE;AACtB,WAAM;IACP;GACF;AACD,OAAI,WAAW,YAAY;AACzB,UAAM;GACP;GAGD,MAAM,YAAY,KAAK,UAAU;GACjC,MAAM,eAAe,oBAAoB,KAAK,QAAQ,GAAG;GACzD,MAAM,QAAQ,YAAY;AAC1B,cAAW;AACX,UAAO,MACJ,oBAAoB,MAAM,QAAQ,gBAAgB,MAAM,QAAQ,EAAE,CAAC,YAAY,QAAQ,MAAM,WAAW,MAC1G;AACD,SAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,MAAM;EAC1D;CACF;AAED,OAAM,IAAI,MAAM;AACjB"}
package/dist/runtime.cjs CHANGED
@@ -1,53 +1,49 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
8
  var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
17
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
19
22
 
20
- // src/runtime.ts
21
- var runtime_exports = {};
22
- __export(runtime_exports, {
23
- ensureBrowser: () => ensureBrowser,
24
- ensureServer: () => ensureServer,
25
- runsInBrowser: () => runsInBrowser,
26
- runsOnServer: () => runsOnServer
27
- });
28
- module.exports = __toCommonJS(runtime_exports);
23
+ //#endregion
24
+ const src_runtime_ensure_server_js = __toESM(require("./runtime/ensure-server.js"));
29
25
 
30
- // src/runtime/ensure-server.ts
31
- var import_environment = require("environment");
32
- function ensureServer() {
33
- if (import_environment.isBrowser) {
34
- throw new Error(
35
- "This function can only be used on the server as including it in the browser will expose your access token."
36
- );
26
+ Object.defineProperty(exports, 'ensureBrowser', {
27
+ enumerable: true,
28
+ get: function () {
29
+ return src_runtime_ensure_server_js.ensureBrowser;
37
30
  }
38
- }
39
- function ensureBrowser() {
40
- if (!import_environment.isBrowser) {
41
- throw new Error("This function can only be used on the browser as it is missing the access token.");
31
+ });
32
+ Object.defineProperty(exports, 'ensureServer', {
33
+ enumerable: true,
34
+ get: function () {
35
+ return src_runtime_ensure_server_js.ensureServer;
42
36
  }
43
- }
44
- var runsInBrowser = import_environment.isBrowser;
45
- var runsOnServer = !import_environment.isBrowser;
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- ensureBrowser,
49
- ensureServer,
50
- runsInBrowser,
51
- runsOnServer
52
37
  });
53
- //# sourceMappingURL=runtime.cjs.map
38
+ Object.defineProperty(exports, 'runsInBrowser', {
39
+ enumerable: true,
40
+ get: function () {
41
+ return src_runtime_ensure_server_js.runsInBrowser;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, 'runsOnServer', {
45
+ enumerable: true,
46
+ get: function () {
47
+ return src_runtime_ensure_server_js.runsOnServer;
48
+ }
49
+ });
@@ -1,32 +1,2 @@
1
- /**
2
- * Ensures that code is running on the server and not in a browser environment.
3
- *
4
- * @throws {Error} If called from a browser environment
5
- * @example
6
- * import { ensureServer } from "@settlemint/sdk-utils/runtime";
7
- *
8
- * // Will throw if running in browser
9
- * ensureServer();
10
- */
11
- declare function ensureServer(): void;
12
- /**
13
- * Ensures that code is running in a browser environment and not on the server.
14
- *
15
- * @throws {Error} If called from a server environment
16
- * @example
17
- * import { ensureBrowser } from "@settlemint/sdk-utils/runtime";
18
- *
19
- * // Will throw if running on server
20
- * ensureBrowser();
21
- */
22
- declare function ensureBrowser(): void;
23
- /**
24
- * Boolean indicating if code is currently running in a browser environment
25
- */
26
- declare const runsInBrowser: boolean;
27
- /**
28
- * Boolean indicating if code is currently running in a server environment
29
- */
30
- declare const runsOnServer: boolean;
31
-
32
- export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
1
+ import { ensureBrowser, ensureServer, runsInBrowser, runsOnServer } from "./runtime/ensure-server.js";
2
+ export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
package/dist/runtime.d.ts CHANGED
@@ -1,32 +1,2 @@
1
- /**
2
- * Ensures that code is running on the server and not in a browser environment.
3
- *
4
- * @throws {Error} If called from a browser environment
5
- * @example
6
- * import { ensureServer } from "@settlemint/sdk-utils/runtime";
7
- *
8
- * // Will throw if running in browser
9
- * ensureServer();
10
- */
11
- declare function ensureServer(): void;
12
- /**
13
- * Ensures that code is running in a browser environment and not on the server.
14
- *
15
- * @throws {Error} If called from a server environment
16
- * @example
17
- * import { ensureBrowser } from "@settlemint/sdk-utils/runtime";
18
- *
19
- * // Will throw if running on server
20
- * ensureBrowser();
21
- */
22
- declare function ensureBrowser(): void;
23
- /**
24
- * Boolean indicating if code is currently running in a browser environment
25
- */
26
- declare const runsInBrowser: boolean;
27
- /**
28
- * Boolean indicating if code is currently running in a server environment
29
- */
30
- declare const runsOnServer: boolean;
31
-
32
- export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
1
+ import { ensureBrowser, ensureServer, runsInBrowser, runsOnServer } from "./runtime/ensure-server.js";
2
+ export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
@@ -0,0 +1,3 @@
1
+ import { ensureBrowser, ensureServer, runsInBrowser, runsOnServer } from "./runtime/ensure-server.js";
2
+
3
+ export { ensureBrowser, ensureServer, runsInBrowser, runsOnServer };
@@ -0,0 +1,76 @@
1
+
2
+ //#region src/string.ts
3
+ /**
4
+ * Capitalizes the first letter of a string.
5
+ *
6
+ * @param val - The string to capitalize
7
+ * @returns The input string with its first letter capitalized
8
+ *
9
+ * @example
10
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
11
+ *
12
+ * const capitalized = capitalizeFirstLetter("hello");
13
+ * // Returns: "Hello"
14
+ */
15
+ function capitalizeFirstLetter(val) {
16
+ return String(val).charAt(0).toUpperCase() + String(val).slice(1);
17
+ }
18
+ /**
19
+ * Converts a camelCase string to a human-readable string.
20
+ *
21
+ * @param s - The camelCase string to convert
22
+ * @returns The human-readable string
23
+ *
24
+ * @example
25
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
26
+ *
27
+ * const words = camelCaseToWords("camelCaseString");
28
+ * // Returns: "Camel Case String"
29
+ */
30
+ function camelCaseToWords(s) {
31
+ const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
32
+ const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
33
+ const capitalized = capitalizeFirstLetter(withSpaces);
34
+ return capitalized.replace(/\s+/g, " ").trim();
35
+ }
36
+ /**
37
+ * Replaces underscores and hyphens with spaces.
38
+ *
39
+ * @param s - The string to replace underscores and hyphens with spaces
40
+ * @returns The input string with underscores and hyphens replaced with spaces
41
+ *
42
+ * @example
43
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
44
+ *
45
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
46
+ * // Returns: "Already Spaced Second"
47
+ */
48
+ function replaceUnderscoresAndHyphensWithSpaces(s) {
49
+ return s.replace(/[-_]/g, " ");
50
+ }
51
+ /**
52
+ * Truncates a string to a maximum length and appends "..." if it is longer.
53
+ *
54
+ * @param value - The string to truncate
55
+ * @param maxLength - The maximum length of the string
56
+ * @returns The truncated string or the original string if it is shorter than the maximum length
57
+ *
58
+ * @example
59
+ * import { truncate } from "@settlemint/sdk-utils";
60
+ *
61
+ * const truncated = truncate("Hello, world!", 10);
62
+ * // Returns: "Hello, wor..."
63
+ */
64
+ function truncate(value, maxLength) {
65
+ if (value.length <= maxLength) {
66
+ return value;
67
+ }
68
+ return `${value.slice(0, maxLength)}...`;
69
+ }
70
+
71
+ //#endregion
72
+ exports.camelCaseToWords = camelCaseToWords;
73
+ exports.capitalizeFirstLetter = capitalizeFirstLetter;
74
+ exports.replaceUnderscoresAndHyphensWithSpaces = replaceUnderscoresAndHyphensWithSpaces;
75
+ exports.truncate = truncate;
76
+ //# sourceMappingURL=string.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.cjs","names":["val: string","s: string","value: string","maxLength: number"],"sources":["../src/string.ts"],"sourcesContent":["/**\n * Capitalizes the first letter of a string.\n *\n * @param val - The string to capitalize\n * @returns The input string with its first letter capitalized\n *\n * @example\n * import { capitalizeFirstLetter } from \"@settlemint/sdk-utils\";\n *\n * const capitalized = capitalizeFirstLetter(\"hello\");\n * // Returns: \"Hello\"\n */\nexport function capitalizeFirstLetter(val: string) {\n return String(val).charAt(0).toUpperCase() + String(val).slice(1);\n}\n\n/**\n * Converts a camelCase string to a human-readable string.\n *\n * @param s - The camelCase string to convert\n * @returns The human-readable string\n *\n * @example\n * import { camelCaseToWords } from \"@settlemint/sdk-utils\";\n *\n * const words = camelCaseToWords(\"camelCaseString\");\n * // Returns: \"Camel Case String\"\n */\nexport function camelCaseToWords(s: string) {\n const result = s.replace(/([a-z])([A-Z])/g, \"$1 $2\");\n const withSpaces = result.replace(/([A-Z])([a-z])/g, \" $1$2\");\n const capitalized = capitalizeFirstLetter(withSpaces);\n return capitalized.replace(/\\s+/g, \" \").trim();\n}\n\n/**\n * Replaces underscores and hyphens with spaces.\n *\n * @param s - The string to replace underscores and hyphens with spaces\n * @returns The input string with underscores and hyphens replaced with spaces\n *\n * @example\n * import { replaceUnderscoresAndHyphensWithSpaces } from \"@settlemint/sdk-utils\";\n *\n * const result = replaceUnderscoresAndHyphensWithSpaces(\"Already_Spaced-Second\");\n * // Returns: \"Already Spaced Second\"\n */\nexport function replaceUnderscoresAndHyphensWithSpaces(s: string) {\n return s.replace(/[-_]/g, \" \");\n}\n\n/**\n * Truncates a string to a maximum length and appends \"...\" if it is longer.\n *\n * @param value - The string to truncate\n * @param maxLength - The maximum length of the string\n * @returns The truncated string or the original string if it is shorter than the maximum length\n *\n * @example\n * import { truncate } from \"@settlemint/sdk-utils\";\n *\n * const truncated = truncate(\"Hello, world!\", 10);\n * // Returns: \"Hello, wor...\"\n */\nexport function truncate(value: string, maxLength: number) {\n if (value.length <= maxLength) {\n return value;\n }\n return `${value.slice(0, maxLength)}...`;\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,sBAAsBA,KAAa;AACjD,QAAO,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE;AAClE;;;;;;;;;;;;;AAcD,SAAgB,iBAAiBC,GAAW;CAC1C,MAAM,SAAS,EAAE,QAAQ,mBAAmB,QAAQ;CACpD,MAAM,aAAa,OAAO,QAAQ,mBAAmB,QAAQ;CAC7D,MAAM,cAAc,sBAAsB,WAAW;AACrD,QAAO,YAAY,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC/C;;;;;;;;;;;;;AAcD,SAAgB,uCAAuCA,GAAW;AAChE,QAAO,EAAE,QAAQ,SAAS,IAAI;AAC/B;;;;;;;;;;;;;;AAeD,SAAgB,SAASC,OAAeC,WAAmB;AACzD,KAAI,MAAM,UAAU,WAAW;AAC7B,SAAO;CACR;AACD,SAAQ,EAAE,MAAM,MAAM,GAAG,UAAU,CAAC;AACrC"}
@@ -0,0 +1,58 @@
1
+ //#region src/string.d.ts
2
+ /**
3
+ * Capitalizes the first letter of a string.
4
+ *
5
+ * @param val - The string to capitalize
6
+ * @returns The input string with its first letter capitalized
7
+ *
8
+ * @example
9
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
10
+ *
11
+ * const capitalized = capitalizeFirstLetter("hello");
12
+ * // Returns: "Hello"
13
+ */
14
+ declare function capitalizeFirstLetter(val: string): string;
15
+ /**
16
+ * Converts a camelCase string to a human-readable string.
17
+ *
18
+ * @param s - The camelCase string to convert
19
+ * @returns The human-readable string
20
+ *
21
+ * @example
22
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
23
+ *
24
+ * const words = camelCaseToWords("camelCaseString");
25
+ * // Returns: "Camel Case String"
26
+ */
27
+ declare function camelCaseToWords(s: string): string;
28
+ /**
29
+ * Replaces underscores and hyphens with spaces.
30
+ *
31
+ * @param s - The string to replace underscores and hyphens with spaces
32
+ * @returns The input string with underscores and hyphens replaced with spaces
33
+ *
34
+ * @example
35
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
36
+ *
37
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
38
+ * // Returns: "Already Spaced Second"
39
+ */
40
+ declare function replaceUnderscoresAndHyphensWithSpaces(s: string): string;
41
+ /**
42
+ * Truncates a string to a maximum length and appends "..." if it is longer.
43
+ *
44
+ * @param value - The string to truncate
45
+ * @param maxLength - The maximum length of the string
46
+ * @returns The truncated string or the original string if it is shorter than the maximum length
47
+ *
48
+ * @example
49
+ * import { truncate } from "@settlemint/sdk-utils";
50
+ *
51
+ * const truncated = truncate("Hello, world!", 10);
52
+ * // Returns: "Hello, wor..."
53
+ */
54
+ declare function truncate(value: string, maxLength: number): string;
55
+
56
+ //#endregion
57
+ export { camelCaseToWords, capitalizeFirstLetter, replaceUnderscoresAndHyphensWithSpaces, truncate };
58
+ //# sourceMappingURL=string.d.cts.map
@@ -0,0 +1,58 @@
1
+ //#region src/string.d.ts
2
+ /**
3
+ * Capitalizes the first letter of a string.
4
+ *
5
+ * @param val - The string to capitalize
6
+ * @returns The input string with its first letter capitalized
7
+ *
8
+ * @example
9
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
10
+ *
11
+ * const capitalized = capitalizeFirstLetter("hello");
12
+ * // Returns: "Hello"
13
+ */
14
+ declare function capitalizeFirstLetter(val: string): string;
15
+ /**
16
+ * Converts a camelCase string to a human-readable string.
17
+ *
18
+ * @param s - The camelCase string to convert
19
+ * @returns The human-readable string
20
+ *
21
+ * @example
22
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
23
+ *
24
+ * const words = camelCaseToWords("camelCaseString");
25
+ * // Returns: "Camel Case String"
26
+ */
27
+ declare function camelCaseToWords(s: string): string;
28
+ /**
29
+ * Replaces underscores and hyphens with spaces.
30
+ *
31
+ * @param s - The string to replace underscores and hyphens with spaces
32
+ * @returns The input string with underscores and hyphens replaced with spaces
33
+ *
34
+ * @example
35
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
36
+ *
37
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
38
+ * // Returns: "Already Spaced Second"
39
+ */
40
+ declare function replaceUnderscoresAndHyphensWithSpaces(s: string): string;
41
+ /**
42
+ * Truncates a string to a maximum length and appends "..." if it is longer.
43
+ *
44
+ * @param value - The string to truncate
45
+ * @param maxLength - The maximum length of the string
46
+ * @returns The truncated string or the original string if it is shorter than the maximum length
47
+ *
48
+ * @example
49
+ * import { truncate } from "@settlemint/sdk-utils";
50
+ *
51
+ * const truncated = truncate("Hello, world!", 10);
52
+ * // Returns: "Hello, wor..."
53
+ */
54
+ declare function truncate(value: string, maxLength: number): string;
55
+
56
+ //#endregion
57
+ export { camelCaseToWords, capitalizeFirstLetter, replaceUnderscoresAndHyphensWithSpaces, truncate };
58
+ //# sourceMappingURL=string.d.ts.map
package/dist/string.js ADDED
@@ -0,0 +1,72 @@
1
+ //#region src/string.ts
2
+ /**
3
+ * Capitalizes the first letter of a string.
4
+ *
5
+ * @param val - The string to capitalize
6
+ * @returns The input string with its first letter capitalized
7
+ *
8
+ * @example
9
+ * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
10
+ *
11
+ * const capitalized = capitalizeFirstLetter("hello");
12
+ * // Returns: "Hello"
13
+ */
14
+ function capitalizeFirstLetter(val) {
15
+ return String(val).charAt(0).toUpperCase() + String(val).slice(1);
16
+ }
17
+ /**
18
+ * Converts a camelCase string to a human-readable string.
19
+ *
20
+ * @param s - The camelCase string to convert
21
+ * @returns The human-readable string
22
+ *
23
+ * @example
24
+ * import { camelCaseToWords } from "@settlemint/sdk-utils";
25
+ *
26
+ * const words = camelCaseToWords("camelCaseString");
27
+ * // Returns: "Camel Case String"
28
+ */
29
+ function camelCaseToWords(s) {
30
+ const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
31
+ const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
32
+ const capitalized = capitalizeFirstLetter(withSpaces);
33
+ return capitalized.replace(/\s+/g, " ").trim();
34
+ }
35
+ /**
36
+ * Replaces underscores and hyphens with spaces.
37
+ *
38
+ * @param s - The string to replace underscores and hyphens with spaces
39
+ * @returns The input string with underscores and hyphens replaced with spaces
40
+ *
41
+ * @example
42
+ * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
43
+ *
44
+ * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
45
+ * // Returns: "Already Spaced Second"
46
+ */
47
+ function replaceUnderscoresAndHyphensWithSpaces(s) {
48
+ return s.replace(/[-_]/g, " ");
49
+ }
50
+ /**
51
+ * Truncates a string to a maximum length and appends "..." if it is longer.
52
+ *
53
+ * @param value - The string to truncate
54
+ * @param maxLength - The maximum length of the string
55
+ * @returns The truncated string or the original string if it is shorter than the maximum length
56
+ *
57
+ * @example
58
+ * import { truncate } from "@settlemint/sdk-utils";
59
+ *
60
+ * const truncated = truncate("Hello, world!", 10);
61
+ * // Returns: "Hello, wor..."
62
+ */
63
+ function truncate(value, maxLength) {
64
+ if (value.length <= maxLength) {
65
+ return value;
66
+ }
67
+ return `${value.slice(0, maxLength)}...`;
68
+ }
69
+
70
+ //#endregion
71
+ export { camelCaseToWords, capitalizeFirstLetter, replaceUnderscoresAndHyphensWithSpaces, truncate };
72
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","names":["val: string","s: string","value: string","maxLength: number"],"sources":["../src/string.ts"],"sourcesContent":["/**\n * Capitalizes the first letter of a string.\n *\n * @param val - The string to capitalize\n * @returns The input string with its first letter capitalized\n *\n * @example\n * import { capitalizeFirstLetter } from \"@settlemint/sdk-utils\";\n *\n * const capitalized = capitalizeFirstLetter(\"hello\");\n * // Returns: \"Hello\"\n */\nexport function capitalizeFirstLetter(val: string) {\n return String(val).charAt(0).toUpperCase() + String(val).slice(1);\n}\n\n/**\n * Converts a camelCase string to a human-readable string.\n *\n * @param s - The camelCase string to convert\n * @returns The human-readable string\n *\n * @example\n * import { camelCaseToWords } from \"@settlemint/sdk-utils\";\n *\n * const words = camelCaseToWords(\"camelCaseString\");\n * // Returns: \"Camel Case String\"\n */\nexport function camelCaseToWords(s: string) {\n const result = s.replace(/([a-z])([A-Z])/g, \"$1 $2\");\n const withSpaces = result.replace(/([A-Z])([a-z])/g, \" $1$2\");\n const capitalized = capitalizeFirstLetter(withSpaces);\n return capitalized.replace(/\\s+/g, \" \").trim();\n}\n\n/**\n * Replaces underscores and hyphens with spaces.\n *\n * @param s - The string to replace underscores and hyphens with spaces\n * @returns The input string with underscores and hyphens replaced with spaces\n *\n * @example\n * import { replaceUnderscoresAndHyphensWithSpaces } from \"@settlemint/sdk-utils\";\n *\n * const result = replaceUnderscoresAndHyphensWithSpaces(\"Already_Spaced-Second\");\n * // Returns: \"Already Spaced Second\"\n */\nexport function replaceUnderscoresAndHyphensWithSpaces(s: string) {\n return s.replace(/[-_]/g, \" \");\n}\n\n/**\n * Truncates a string to a maximum length and appends \"...\" if it is longer.\n *\n * @param value - The string to truncate\n * @param maxLength - The maximum length of the string\n * @returns The truncated string or the original string if it is shorter than the maximum length\n *\n * @example\n * import { truncate } from \"@settlemint/sdk-utils\";\n *\n * const truncated = truncate(\"Hello, world!\", 10);\n * // Returns: \"Hello, wor...\"\n */\nexport function truncate(value: string, maxLength: number) {\n if (value.length <= maxLength) {\n return value;\n }\n return `${value.slice(0, maxLength)}...`;\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,sBAAsBA,KAAa;AACjD,QAAO,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE;AAClE;;;;;;;;;;;;;AAcD,SAAgB,iBAAiBC,GAAW;CAC1C,MAAM,SAAS,EAAE,QAAQ,mBAAmB,QAAQ;CACpD,MAAM,aAAa,OAAO,QAAQ,mBAAmB,QAAQ;CAC7D,MAAM,cAAc,sBAAsB,WAAW;AACrD,QAAO,YAAY,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAC/C;;;;;;;;;;;;;AAcD,SAAgB,uCAAuCA,GAAW;AAChE,QAAO,EAAE,QAAQ,SAAS,IAAI;AAC/B;;;;;;;;;;;;;;AAeD,SAAgB,SAASC,OAAeC,WAAmB;AACzD,KAAI,MAAM,UAAU,WAAW;AAC7B,SAAO;CACR;AACD,SAAQ,EAAE,MAAM,MAAM,GAAG,UAAU,CAAC;AACrC"}