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