@ucdjs/utils 0.0.0 → 0.1.0
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/index.d.ts +10 -3
- package/dist/index.js +16 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Safely parses a JSON string into an object of type T.
|
|
4
|
+
* Returns null if the parsing fails.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The expected type of the parsed JSON
|
|
7
|
+
* @param {string} content - The JSON string to parse
|
|
8
|
+
* @returns {T | null} The parsed object of type T or null if parsing fails
|
|
9
|
+
*/
|
|
10
|
+
declare function safeJsonParse<T>(content: string): T | null;
|
|
4
11
|
//#endregion
|
|
5
|
-
export {
|
|
12
|
+
export { safeJsonParse };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Safely parses a JSON string into an object of type T.
|
|
4
|
+
* Returns null if the parsing fails.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The expected type of the parsed JSON
|
|
7
|
+
* @param {string} content - The JSON string to parse
|
|
8
|
+
* @returns {T | null} The parsed object of type T or null if parsing fails
|
|
9
|
+
*/
|
|
10
|
+
function safeJsonParse(content) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(content);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("[safeJsonParse] Failed to parse JSON:", err);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
4
17
|
}
|
|
5
18
|
|
|
6
19
|
//#endregion
|
|
7
|
-
export {
|
|
20
|
+
export { safeJsonParse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucdjs/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Lucas Nørgård",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@luxass/eslint-config": "^4.18.1",
|
|
32
|
-
"eslint": "^9.
|
|
32
|
+
"eslint": "^9.27.0",
|
|
33
33
|
"publint": "^0.3.12",
|
|
34
|
-
"tsdown": "
|
|
35
|
-
"typescript": "^5.8.
|
|
36
|
-
"vitest-testdirs": "^
|
|
34
|
+
"tsdown": "^0.12.5",
|
|
35
|
+
"typescript": "^5.8.3",
|
|
36
|
+
"vitest-testdirs": "^4.0.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|