@settlemint/sdk-utils 2.3.2-pr708c218f → 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 -409
  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 +34 -98
  11. package/dist/http.d.cts +4 -55
  12. package/dist/http.d.ts +4 -55
  13. package/dist/http.js +5 -0
  14. package/dist/index.cjs +27 -118
  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 -186
  59. package/dist/validation.d.cts +7 -243
  60. package/dist/validation.d.ts +7 -243
  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 -384
  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 -80
  71. package/dist/http.mjs.map +0 -1
  72. package/dist/index.cjs.map +0 -1
  73. package/dist/index.mjs +0 -90
  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 -161
  89. package/dist/validation.mjs.map +0 -1
@@ -0,0 +1,5 @@
1
+ import { projectRoot } from "./filesystem/project-root.js";
2
+ import { exists } from "./filesystem/exists.js";
3
+ import { findMonoRepoPackages, findMonoRepoRoot } from "./filesystem/mono-repo.js";
4
+
5
+ export { exists, findMonoRepoPackages, findMonoRepoRoot, projectRoot };
package/dist/http.cjs CHANGED
@@ -1,109 +1,45 @@
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/http.ts
21
- var http_exports = {};
22
- __export(http_exports, {
23
- appendHeaders: () => appendHeaders,
24
- fetchWithRetry: () => fetchWithRetry,
25
- graphqlFetchWithRetry: () => graphqlFetchWithRetry
26
- });
27
- module.exports = __toCommonJS(http_exports);
23
+ //#endregion
24
+ const src_http_fetch_with_retry_js = __toESM(require("./http/fetch-with-retry.js"));
25
+ const src_http_graphql_fetch_with_retry_js = __toESM(require("./http/graphql-fetch-with-retry.js"));
26
+ const src_http_headers_js = __toESM(require("./http/headers.js"));
28
27
 
29
- // src/retry.ts
30
- async function retryWhenFailed(fn, maxRetries = 5, initialSleepTime = 1e3, stopOnError) {
31
- let attempt = 0;
32
- while (attempt < maxRetries) {
33
- try {
34
- return await fn();
35
- } catch (e) {
36
- if (typeof stopOnError === "function") {
37
- const error = e;
38
- if (stopOnError(error)) {
39
- throw error;
40
- }
41
- }
42
- attempt += 1;
43
- if (attempt >= maxRetries) {
44
- throw e;
45
- }
46
- const jitter = Math.random();
47
- const delay = 2 ** attempt * initialSleepTime * jitter;
48
- await new Promise((resolve) => setTimeout(resolve, delay));
49
- }
28
+ Object.defineProperty(exports, 'appendHeaders', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return src_http_headers_js.appendHeaders;
50
32
  }
51
- throw new Error("Retry failed");
52
- }
53
-
54
- // src/http/fetch-with-retry.ts
55
- async function fetchWithRetry(input, init, maxRetries = 5, initialSleepTime = 3e3) {
56
- return retryWhenFailed(
57
- async () => {
58
- const response = await fetch(input, init);
59
- if (response.ok) {
60
- return response;
61
- }
62
- if (response.status < 500 && response.status !== 429 && response.status !== 408 && response.status !== 0) {
63
- return response;
64
- }
65
- throw new Error(`HTTP error! status: ${response.status} ${response.statusText}`);
66
- },
67
- maxRetries,
68
- initialSleepTime
69
- );
70
- }
71
-
72
- // src/http/graphql-fetch-with-retry.ts
73
- async function graphqlFetchWithRetry(input, init, maxRetries = 5, initialSleepTime = 3e3) {
74
- return retryWhenFailed(
75
- async () => {
76
- const response = await fetchWithRetry(input, init);
77
- const json = await response.json();
78
- if (json.errors) {
79
- throw new Error(`GraphQL errors in response: ${json.errors.map((error) => error.message).join(", ")}`);
80
- }
81
- return json.data;
82
- },
83
- maxRetries,
84
- initialSleepTime
85
- );
86
- }
87
-
88
- // src/http/headers.ts
89
- function appendHeaders(headers, additionalHeaders) {
90
- const defaultHeaders = typeof headers === "function" ? headers() : headers;
91
- const filteredAdditionalHeaders = Object.entries(additionalHeaders).filter(([_, value]) => value !== void 0);
92
- if (Array.isArray(defaultHeaders)) {
93
- return [...defaultHeaders, ...filteredAdditionalHeaders];
94
- }
95
- if (defaultHeaders instanceof Headers) {
96
- return new Headers([...defaultHeaders, ...filteredAdditionalHeaders]);
33
+ });
34
+ Object.defineProperty(exports, 'fetchWithRetry', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return src_http_fetch_with_retry_js.fetchWithRetry;
97
38
  }
98
- return {
99
- ...defaultHeaders,
100
- ...Object.fromEntries(filteredAdditionalHeaders)
101
- };
102
- }
103
- // Annotate the CommonJS export names for ESM import in node:
104
- 0 && (module.exports = {
105
- appendHeaders,
106
- fetchWithRetry,
107
- graphqlFetchWithRetry
108
39
  });
109
- //# sourceMappingURL=http.cjs.map
40
+ Object.defineProperty(exports, 'graphqlFetchWithRetry', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return src_http_graphql_fetch_with_retry_js.graphqlFetchWithRetry;
44
+ }
45
+ });
package/dist/http.d.cts CHANGED
@@ -1,55 +1,4 @@
1
- /**
2
- * Retry an HTTP request with exponential backoff and jitter.
3
- * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors.
4
- *
5
- * @param input - The URL or Request object to fetch
6
- * @param init - The fetch init options
7
- * @param maxRetries - Maximum number of retry attempts
8
- * @param initialSleepTime - Initial sleep time between retries in ms
9
- * @returns The fetch Response
10
- * @throws Error if all retries fail
11
- * @example
12
- * import { fetchWithRetry } from "@settlemint/sdk-utils/http";
13
- *
14
- * const response = await fetchWithRetry("https://api.example.com/data");
15
- */
16
- declare function fetchWithRetry(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Response>;
17
-
18
- /**
19
- * Executes a GraphQL request with automatic retries using exponential backoff and jitter.
20
- * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors.
21
- * Will also retry if the GraphQL response contains errors.
22
- *
23
- * @param input - The URL or Request object for the GraphQL endpoint
24
- * @param init - Optional fetch configuration options
25
- * @param maxRetries - Maximum retry attempts before failing (default: 5)
26
- * @param initialSleepTime - Initial delay between retries in milliseconds (default: 3000)
27
- * @returns The parsed GraphQL response data
28
- * @throws Error if all retries fail or if GraphQL response contains errors
29
- * @example
30
- * import { graphqlFetchWithRetry } from "@settlemint/sdk-utils/http";
31
- *
32
- * const data = await graphqlFetchWithRetry<{ user: { id: string } }>(
33
- * "https://api.example.com/graphql",
34
- * {
35
- * method: "POST",
36
- * headers: { "Content-Type": "application/json" },
37
- * body: JSON.stringify({
38
- * query: `query GetUser($id: ID!) {
39
- * user(id: $id) {
40
- * id
41
- * }
42
- * }`,
43
- * variables: { id: "123" }
44
- * })
45
- * }
46
- * );
47
- */
48
- declare function graphqlFetchWithRetry<Data>(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Data>;
49
-
50
- type MaybeLazy<T> = T | (() => T);
51
- declare function appendHeaders(headers: MaybeLazy<HeadersInit> | undefined, additionalHeaders: Record<string, string | undefined>): [string, string][] | Headers | {
52
- [x: string]: string;
53
- };
54
-
55
- export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry };
1
+ import { fetchWithRetry } from "./http/fetch-with-retry.js";
2
+ import { graphqlFetchWithRetry } from "./http/graphql-fetch-with-retry.js";
3
+ import { appendHeaders } from "./http/headers.js";
4
+ export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry };
package/dist/http.d.ts CHANGED
@@ -1,55 +1,4 @@
1
- /**
2
- * Retry an HTTP request with exponential backoff and jitter.
3
- * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors.
4
- *
5
- * @param input - The URL or Request object to fetch
6
- * @param init - The fetch init options
7
- * @param maxRetries - Maximum number of retry attempts
8
- * @param initialSleepTime - Initial sleep time between retries in ms
9
- * @returns The fetch Response
10
- * @throws Error if all retries fail
11
- * @example
12
- * import { fetchWithRetry } from "@settlemint/sdk-utils/http";
13
- *
14
- * const response = await fetchWithRetry("https://api.example.com/data");
15
- */
16
- declare function fetchWithRetry(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Response>;
17
-
18
- /**
19
- * Executes a GraphQL request with automatic retries using exponential backoff and jitter.
20
- * Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors.
21
- * Will also retry if the GraphQL response contains errors.
22
- *
23
- * @param input - The URL or Request object for the GraphQL endpoint
24
- * @param init - Optional fetch configuration options
25
- * @param maxRetries - Maximum retry attempts before failing (default: 5)
26
- * @param initialSleepTime - Initial delay between retries in milliseconds (default: 3000)
27
- * @returns The parsed GraphQL response data
28
- * @throws Error if all retries fail or if GraphQL response contains errors
29
- * @example
30
- * import { graphqlFetchWithRetry } from "@settlemint/sdk-utils/http";
31
- *
32
- * const data = await graphqlFetchWithRetry<{ user: { id: string } }>(
33
- * "https://api.example.com/graphql",
34
- * {
35
- * method: "POST",
36
- * headers: { "Content-Type": "application/json" },
37
- * body: JSON.stringify({
38
- * query: `query GetUser($id: ID!) {
39
- * user(id: $id) {
40
- * id
41
- * }
42
- * }`,
43
- * variables: { id: "123" }
44
- * })
45
- * }
46
- * );
47
- */
48
- declare function graphqlFetchWithRetry<Data>(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Data>;
49
-
50
- type MaybeLazy<T> = T | (() => T);
51
- declare function appendHeaders(headers: MaybeLazy<HeadersInit> | undefined, additionalHeaders: Record<string, string | undefined>): [string, string][] | Headers | {
52
- [x: string]: string;
53
- };
54
-
55
- export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry };
1
+ import { fetchWithRetry } from "./http/fetch-with-retry.js";
2
+ import { graphqlFetchWithRetry } from "./http/graphql-fetch-with-retry.js";
3
+ import { appendHeaders } from "./http/headers.js";
4
+ export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry };
package/dist/http.js ADDED
@@ -0,0 +1,5 @@
1
+ import { fetchWithRetry } from "./http/fetch-with-retry.js";
2
+ import { graphqlFetchWithRetry } from "./http/graphql-fetch-with-retry.js";
3
+ import { appendHeaders } from "./http/headers.js";
4
+
5
+ export { appendHeaders, fetchWithRetry, graphqlFetchWithRetry };
package/dist/index.cjs CHANGED
@@ -1,124 +1,33 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- 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
- 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;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
1
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- camelCaseToWords: () => camelCaseToWords,
24
- capitalizeFirstLetter: () => capitalizeFirstLetter,
25
- extractJsonObject: () => extractJsonObject,
26
- makeJsonStringifiable: () => makeJsonStringifiable,
27
- replaceUnderscoresAndHyphensWithSpaces: () => replaceUnderscoresAndHyphensWithSpaces,
28
- retryWhenFailed: () => retryWhenFailed,
29
- truncate: () => truncate,
30
- tryParseJson: () => tryParseJson
2
+
3
+ var src_json_js = require("./json.js");
4
+ Object.keys(src_json_js).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return src_json_js[k]; }
8
+ });
31
9
  });
32
- module.exports = __toCommonJS(index_exports);
33
10
 
34
- // src/json.ts
35
- function tryParseJson(value, defaultValue = null) {
36
- try {
37
- const parsed = JSON.parse(value);
38
- if (parsed === void 0 || parsed === null) {
39
- return defaultValue;
40
- }
41
- return parsed;
42
- } catch (err) {
43
- return defaultValue;
44
- }
45
- }
46
- function extractJsonObject(value) {
47
- if (value.length > 5e3) {
48
- throw new Error("Input too long");
49
- }
50
- const result = /\{([\s\S]*)\}/.exec(value);
51
- if (!result) {
52
- return null;
53
- }
54
- return tryParseJson(result[0]);
55
- }
56
- function makeJsonStringifiable(value) {
57
- if (value === void 0 || value === null) {
58
- return value;
59
- }
60
- return tryParseJson(
61
- JSON.stringify(
62
- value,
63
- (_, value2) => typeof value2 === "bigint" ? value2.toString() : value2
64
- // return everything else unchanged
65
- )
66
- );
67
- }
11
+ var src_retry_js = require("./retry.js");
12
+ Object.keys(src_retry_js).forEach(function (k) {
13
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
14
+ enumerable: true,
15
+ get: function () { return src_retry_js[k]; }
16
+ });
17
+ });
68
18
 
69
- // src/retry.ts
70
- async function retryWhenFailed(fn, maxRetries = 5, initialSleepTime = 1e3, stopOnError) {
71
- let attempt = 0;
72
- while (attempt < maxRetries) {
73
- try {
74
- return await fn();
75
- } catch (e) {
76
- if (typeof stopOnError === "function") {
77
- const error = e;
78
- if (stopOnError(error)) {
79
- throw error;
80
- }
81
- }
82
- attempt += 1;
83
- if (attempt >= maxRetries) {
84
- throw e;
85
- }
86
- const jitter = Math.random();
87
- const delay = 2 ** attempt * initialSleepTime * jitter;
88
- await new Promise((resolve) => setTimeout(resolve, delay));
89
- }
90
- }
91
- throw new Error("Retry failed");
92
- }
19
+ var src_string_js = require("./string.js");
20
+ Object.keys(src_string_js).forEach(function (k) {
21
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
22
+ enumerable: true,
23
+ get: function () { return src_string_js[k]; }
24
+ });
25
+ });
93
26
 
94
- // src/string.ts
95
- function capitalizeFirstLetter(val) {
96
- return String(val).charAt(0).toUpperCase() + String(val).slice(1);
97
- }
98
- function camelCaseToWords(s) {
99
- const result = s.replace(/([a-z])([A-Z])/g, "$1 $2");
100
- const withSpaces = result.replace(/([A-Z])([a-z])/g, " $1$2");
101
- const capitalized = capitalizeFirstLetter(withSpaces);
102
- return capitalized.replace(/\s+/g, " ").trim();
103
- }
104
- function replaceUnderscoresAndHyphensWithSpaces(s) {
105
- return s.replace(/[-_]/g, " ");
106
- }
107
- function truncate(value, maxLength) {
108
- if (value.length <= maxLength) {
109
- return value;
110
- }
111
- return `${value.slice(0, maxLength)}...`;
112
- }
113
- // Annotate the CommonJS export names for ESM import in node:
114
- 0 && (module.exports = {
115
- camelCaseToWords,
116
- capitalizeFirstLetter,
117
- extractJsonObject,
118
- makeJsonStringifiable,
119
- replaceUnderscoresAndHyphensWithSpaces,
120
- retryWhenFailed,
121
- truncate,
122
- tryParseJson
27
+ var src_url_js = require("./url.js");
28
+ Object.keys(src_url_js).forEach(function (k) {
29
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
30
+ enumerable: true,
31
+ get: function () { return src_url_js[k]; }
32
+ });
123
33
  });
124
- //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,122 +1,4 @@
1
- /**
2
- * Attempts to parse a JSON string into a typed value, returning a default value if parsing fails.
3
- *
4
- * @param value - The JSON string to parse
5
- * @param defaultValue - The value to return if parsing fails or results in null/undefined
6
- * @returns The parsed JSON value as type T, or the default value if parsing fails
7
- *
8
- * @example
9
- * import { tryParseJson } from "@settlemint/sdk-utils";
10
- *
11
- * const config = tryParseJson<{ port: number }>(
12
- * '{"port": 3000}',
13
- * { port: 8080 }
14
- * );
15
- * // Returns: { port: 3000 }
16
- *
17
- * const invalid = tryParseJson<string[]>(
18
- * 'invalid json',
19
- * []
20
- * );
21
- * // Returns: []
22
- */
23
- declare function tryParseJson<T>(value: string, defaultValue?: T | null): T | null;
24
- /**
25
- * Extracts a JSON object from a string.
26
- *
27
- * @param value - The string to extract the JSON object from
28
- * @returns The parsed JSON object, or null if no JSON object is found
29
- * @throws {Error} If the input string is too long (longer than 5000 characters)
30
- * @example
31
- * import { extractJsonObject } from "@settlemint/sdk-utils";
32
- *
33
- * const json = extractJsonObject<{ port: number }>(
34
- * 'port info: {"port": 3000}',
35
- * );
36
- * // Returns: { port: 3000 }
37
- */
38
- declare function extractJsonObject<T>(value: string): T | null;
39
- /**
40
- * Converts a value to a JSON stringifiable format.
41
- *
42
- * @param value - The value to convert
43
- * @returns The JSON stringifiable value
44
- *
45
- * @example
46
- * import { makeJsonStringifiable } from "@settlemint/sdk-utils";
47
- *
48
- * const json = makeJsonStringifiable<{ amount: bigint }>({ amount: BigInt(1000) });
49
- * // Returns: '{"amount":"1000"}'
50
- */
51
- declare function makeJsonStringifiable<T>(value: unknown): T;
52
-
53
- /**
54
- * Retry a function when it fails.
55
- * @param fn - The function to retry.
56
- * @param maxRetries - The maximum number of retries.
57
- * @param initialSleepTime - The initial time to sleep between exponential backoff retries.
58
- * @param stopOnError - The function to stop on error.
59
- * @returns The result of the function or undefined if it fails.
60
- * @example
61
- * import { retryWhenFailed } from "@settlemint/sdk-utils";
62
- * import { readFile } from "node:fs/promises";
63
- *
64
- * const result = await retryWhenFailed(() => readFile("/path/to/file.txt"), 3, 1_000);
65
- */
66
- declare function retryWhenFailed<T>(fn: () => Promise<T>, maxRetries?: number, initialSleepTime?: number, stopOnError?: (error: Error) => boolean): Promise<T>;
67
-
68
- /**
69
- * Capitalizes the first letter of a string.
70
- *
71
- * @param val - The string to capitalize
72
- * @returns The input string with its first letter capitalized
73
- *
74
- * @example
75
- * import { capitalizeFirstLetter } from "@settlemint/sdk-utils";
76
- *
77
- * const capitalized = capitalizeFirstLetter("hello");
78
- * // Returns: "Hello"
79
- */
80
- declare function capitalizeFirstLetter(val: string): string;
81
- /**
82
- * Converts a camelCase string to a human-readable string.
83
- *
84
- * @param s - The camelCase string to convert
85
- * @returns The human-readable string
86
- *
87
- * @example
88
- * import { camelCaseToWords } from "@settlemint/sdk-utils";
89
- *
90
- * const words = camelCaseToWords("camelCaseString");
91
- * // Returns: "Camel Case String"
92
- */
93
- declare function camelCaseToWords(s: string): string;
94
- /**
95
- * Replaces underscores and hyphens with spaces.
96
- *
97
- * @param s - The string to replace underscores and hyphens with spaces
98
- * @returns The input string with underscores and hyphens replaced with spaces
99
- *
100
- * @example
101
- * import { replaceUnderscoresAndHyphensWithSpaces } from "@settlemint/sdk-utils";
102
- *
103
- * const result = replaceUnderscoresAndHyphensWithSpaces("Already_Spaced-Second");
104
- * // Returns: "Already Spaced Second"
105
- */
106
- declare function replaceUnderscoresAndHyphensWithSpaces(s: string): string;
107
- /**
108
- * Truncates a string to a maximum length and appends "..." if it is longer.
109
- *
110
- * @param value - The string to truncate
111
- * @param maxLength - The maximum length of the string
112
- * @returns The truncated string or the original string if it is shorter than the maximum length
113
- *
114
- * @example
115
- * import { truncate } from "@settlemint/sdk-utils";
116
- *
117
- * const truncated = truncate("Hello, world!", 10);
118
- * // Returns: "Hello, wor..."
119
- */
120
- declare function truncate(value: string, maxLength: number): string;
121
-
122
- export { camelCaseToWords, capitalizeFirstLetter, extractJsonObject, makeJsonStringifiable, replaceUnderscoresAndHyphensWithSpaces, retryWhenFailed, truncate, tryParseJson };
1
+ export * from "./json.js";
2
+ export * from "./retry.js";
3
+ export * from "./string.js";
4
+ export * from "./url.js";