Skip to content

Commit

Permalink
feat(util): add parseJson
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Feb 11, 2023
1 parent 68ef633 commit 543da2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"url": "https://github.com/AliMD/alwatr/issues"
},
"dependencies": {
"tslib": "^2.5.0"
"tslib": "^2.5.0",
"@alwatr/math": "^0.29.0",
"@alwatr/type": "^0.29.0"
}
}
3 changes: 3 additions & 0 deletions core/util/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export * from './delay.js';
export * from './json.js';
export * from './local-storage.js';
export * from './client-id.js';
11 changes: 11 additions & 0 deletions core/util/src/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type {Stringifyable} from '@alwatr/type';

export const parseJson = <T extends Stringifyable>(str: string): T | null => {
try {
return JSON.parse(str) as T;
}
catch (err) {
console.error(err);
return null;
}
};
5 changes: 4 additions & 1 deletion core/util/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@

"include": ["src/**/*.ts"],
"exclude": [],
"references": [{"path": "../math"}]
"references": [
{"path": "../type"},
{"path": "../math"},
]
}

0 comments on commit 543da2c

Please sign in to comment.