Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: migrate parse.js to typescript (#2162)

Abdulrehman-Jaferdd9c555bfff0
diff --git a/apps/web/src/utils/config.ts b/apps/web/src/utils/config.ts
index 74c7999a7..47cadf38c 100644
--- a/apps/web/src/utils/config.ts
+++ b/apps/web/src/utils/config.ts
@@ -26,8 +26,7 @@ function set<T>(key: string, value: T) {
function get<T>(key: string, def?: T): T {
const value = window.localStorage.getItem(key);
if (!value && def !== undefined) return def;
-
- return tryParse(value);
+ return value ? tryParse(value) : def;
}
function clear() {
diff --git a/apps/web/src/utils/parse.js b/apps/web/src/utils/parse.ts
similarity index 87%
rename from apps/web/src/utils/parse.js
rename to apps/web/src/utils/parse.ts
index 8f2650737..9e106a340 100644
--- a/apps/web/src/utils/parse.js
+++ b/apps/web/src/utils/parse.ts
@@ -17,12 +17,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-export function tryParse(val) {
- if (val === "undefined" || val === "null") return;
-
+export function tryParse(val: string) {
+ if (val == "null" || val == "undefined") return;
try {
return JSON.parse(val);
- } catch (e) {
+ } catch (error) {
return val;
}
}