@settlemint/sdk-utils 2.4.0-prcf43b3a1 → 2.4.0-prd61aaa2c

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.
@@ -93,84 +93,6 @@ async function exists(path$1) {
93
93
  }
94
94
  }
95
95
 
96
- //#endregion
97
- //#region src/json.ts
98
- /**
99
- * Attempts to parse a JSON string into a typed value, returning a default value if parsing fails.
100
- *
101
- * @param value - The JSON string to parse
102
- * @param defaultValue - The value to return if parsing fails or results in null/undefined
103
- * @returns The parsed JSON value as type T, or the default value if parsing fails
104
- *
105
- * @example
106
- * import { tryParseJson } from "@settlemint/sdk-utils";
107
- *
108
- * const config = tryParseJson<{ port: number }>(
109
- * '{"port": 3000}',
110
- * { port: 8080 }
111
- * );
112
- * // Returns: { port: 3000 }
113
- *
114
- * const invalid = tryParseJson<string[]>(
115
- * 'invalid json',
116
- * []
117
- * );
118
- * // Returns: []
119
- */
120
- function tryParseJson(value, defaultValue = null) {
121
- try {
122
- const parsed = JSON.parse(value);
123
- if (parsed === undefined || parsed === null) {
124
- return defaultValue;
125
- }
126
- return parsed;
127
- } catch (err) {
128
- return defaultValue;
129
- }
130
- }
131
- /**
132
- * Extracts a JSON object from a string.
133
- *
134
- * @param value - The string to extract the JSON object from
135
- * @returns The parsed JSON object, or null if no JSON object is found
136
- * @throws {Error} If the input string is too long (longer than 5000 characters)
137
- * @example
138
- * import { extractJsonObject } from "@settlemint/sdk-utils";
139
- *
140
- * const json = extractJsonObject<{ port: number }>(
141
- * 'port info: {"port": 3000}',
142
- * );
143
- * // Returns: { port: 3000 }
144
- */
145
- function extractJsonObject(value) {
146
- if (value.length > 5e3) {
147
- throw new Error("Input too long");
148
- }
149
- const result = /\{([\s\S]*)\}/.exec(value);
150
- if (!result) {
151
- return null;
152
- }
153
- return tryParseJson(result[0]);
154
- }
155
- /**
156
- * Converts a value to a JSON stringifiable format.
157
- *
158
- * @param value - The value to convert
159
- * @returns The JSON stringifiable value
160
- *
161
- * @example
162
- * import { makeJsonStringifiable } from "@settlemint/sdk-utils";
163
- *
164
- * const json = makeJsonStringifiable<{ amount: bigint }>({ amount: BigInt(1000) });
165
- * // Returns: '{"amount":"1000"}'
166
- */
167
- function makeJsonStringifiable(value) {
168
- if (value === undefined || value === null) {
169
- return value;
170
- }
171
- return tryParseJson(JSON.stringify(value, (_, value$1) => typeof value$1 === "bigint" ? value$1.toString() : value$1));
172
- }
173
-
174
96
  //#endregion
175
97
  //#region ../../node_modules/balanced-match/index.js
176
98
  var require_balanced_match = __commonJS({ "../../node_modules/balanced-match/index.js"(exports, module) {
@@ -6689,6 +6611,84 @@ const glob = Object.assign(glob_, {
6689
6611
  });
6690
6612
  glob.glob = glob;
6691
6613
 
6614
+ //#endregion
6615
+ //#region src/json.ts
6616
+ /**
6617
+ * Attempts to parse a JSON string into a typed value, returning a default value if parsing fails.
6618
+ *
6619
+ * @param value - The JSON string to parse
6620
+ * @param defaultValue - The value to return if parsing fails or results in null/undefined
6621
+ * @returns The parsed JSON value as type T, or the default value if parsing fails
6622
+ *
6623
+ * @example
6624
+ * import { tryParseJson } from "@settlemint/sdk-utils";
6625
+ *
6626
+ * const config = tryParseJson<{ port: number }>(
6627
+ * '{"port": 3000}',
6628
+ * { port: 8080 }
6629
+ * );
6630
+ * // Returns: { port: 3000 }
6631
+ *
6632
+ * const invalid = tryParseJson<string[]>(
6633
+ * 'invalid json',
6634
+ * []
6635
+ * );
6636
+ * // Returns: []
6637
+ */
6638
+ function tryParseJson(value, defaultValue = null) {
6639
+ try {
6640
+ const parsed = JSON.parse(value);
6641
+ if (parsed === undefined || parsed === null) {
6642
+ return defaultValue;
6643
+ }
6644
+ return parsed;
6645
+ } catch (_err) {
6646
+ return defaultValue;
6647
+ }
6648
+ }
6649
+ /**
6650
+ * Extracts a JSON object from a string.
6651
+ *
6652
+ * @param value - The string to extract the JSON object from
6653
+ * @returns The parsed JSON object, or null if no JSON object is found
6654
+ * @throws {Error} If the input string is too long (longer than 5000 characters)
6655
+ * @example
6656
+ * import { extractJsonObject } from "@settlemint/sdk-utils";
6657
+ *
6658
+ * const json = extractJsonObject<{ port: number }>(
6659
+ * 'port info: {"port": 3000}',
6660
+ * );
6661
+ * // Returns: { port: 3000 }
6662
+ */
6663
+ function extractJsonObject(value) {
6664
+ if (value.length > 5e3) {
6665
+ throw new Error("Input too long");
6666
+ }
6667
+ const result = /\{([\s\S]*)\}/.exec(value);
6668
+ if (!result) {
6669
+ return null;
6670
+ }
6671
+ return tryParseJson(result[0]);
6672
+ }
6673
+ /**
6674
+ * Converts a value to a JSON stringifiable format.
6675
+ *
6676
+ * @param value - The value to convert
6677
+ * @returns The JSON stringifiable value
6678
+ *
6679
+ * @example
6680
+ * import { makeJsonStringifiable } from "@settlemint/sdk-utils";
6681
+ *
6682
+ * const json = makeJsonStringifiable<{ amount: bigint }>({ amount: BigInt(1000) });
6683
+ * // Returns: '{"amount":"1000"}'
6684
+ */
6685
+ function makeJsonStringifiable(value) {
6686
+ if (value === undefined || value === null) {
6687
+ return value;
6688
+ }
6689
+ return tryParseJson(JSON.stringify(value, (_, value$1) => typeof value$1 === "bigint" ? value$1.toString() : value$1));
6690
+ }
6691
+
6692
6692
  //#endregion
6693
6693
  //#region src/filesystem/mono-repo.ts
6694
6694
  /**
@@ -6755,7 +6755,7 @@ async function findMonoRepoPackages(projectDir) {
6755
6755
  }));
6756
6756
  const allPaths = packagePaths.flat();
6757
6757
  return allPaths.length === 0 ? [projectDir] : [monoRepoRoot, ...allPaths];
6758
- } catch (error) {
6758
+ } catch (_error) {
6759
6759
  return [projectDir];
6760
6760
  }
6761
6761
  }