perf: reduce bundle size of some pages

This commit is contained in:
rusconn
2023-06-15 18:44:39 +09:00
parent 6612a3be2d
commit 4d198c5b96
10 changed files with 27 additions and 24 deletions

View File

@@ -1,3 +1,3 @@
import { tryCatchK } from "fp-ts/lib/Option";
import { fromThrowable } from "neverthrow";
export const safeJsonParse = tryCatchK(JSON.parse);
export const safeJsonParse = fromThrowable(JSON.parse);

View File

@@ -1,11 +1,11 @@
import * as O from "fp-ts/lib/Option";
import jwt_decode from "jwt-decode";
import { err, fromThrowable, Result } from "neverthrow";
const safeJwtDecode = O.tryCatchK(jwt_decode);
const safeJwtDecode = fromThrowable(jwt_decode);
export const decode = (token: string) => {
let header: O.Option<Record<string, unknown>> = O.none;
let payload: O.Option<unknown> = O.none;
let header: Result<unknown, unknown> = err("");
let payload: Result<unknown, unknown> = err("");
if (token.split(".").length === 3) {
header = safeJwtDecode(token, { header: true });

View File

@@ -1,4 +1,4 @@
import { tryCatchK } from "fp-ts/lib/Option";
import { fromThrowable } from "neverthrow";
export const safeEncodeURIComponent = tryCatchK(encodeURIComponent);
export const safeDecodeURIComponent = tryCatchK(decodeURIComponent);
export const safeEncodeURIComponent = fromThrowable(encodeURIComponent);
export const safeDecodeURIComponent = fromThrowable(decodeURIComponent);

View File

@@ -1,4 +1,4 @@
import { tryCatchK } from "fp-ts/lib/Option";
import yaml from "js-yaml";
import { fromThrowable } from "neverthrow";
export const safeYamlParse = tryCatchK(yaml.load);
export const safeYamlParse = fromThrowable(yaml.load);