mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-16 20:49:23 +00:00
perf: reduce bundle size of some pages
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import * as O from "fp-ts/lib/Option";
|
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
|
||||||
import { toolGroups } from "@/config/tools";
|
import { toolGroups } from "@/config/tools";
|
||||||
@@ -45,7 +44,7 @@ export default function Page() {
|
|||||||
setForm(prev => ({
|
setForm(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
json: text,
|
json: text,
|
||||||
yaml: O.isNone(parsed)
|
yaml: parsed.isErr()
|
||||||
? ""
|
? ""
|
||||||
: yaml.dump(parsed.value, { indent: prev.indentation.length, quotingType: '"' }),
|
: yaml.dump(parsed.value, { indent: prev.indentation.length, quotingType: '"' }),
|
||||||
}));
|
}));
|
||||||
@@ -57,7 +56,7 @@ export default function Page() {
|
|||||||
setForm(prev => ({
|
setForm(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
yaml: text,
|
yaml: text,
|
||||||
json: O.isNone(parsed) ? "" : JSON.stringify(parsed.value, null, prev.indentation),
|
json: parsed.isErr() ? "" : JSON.stringify(parsed.value, null, prev.indentation),
|
||||||
}));
|
}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ export default function Page() {
|
|||||||
const onIndentationChange: SelectProps["onValueChange"] = value => {
|
const onIndentationChange: SelectProps["onValueChange"] = value => {
|
||||||
const parsed = safeJsonParse(form.json);
|
const parsed = safeJsonParse(form.json);
|
||||||
|
|
||||||
const jsonYaml = O.isNone(parsed)
|
const jsonYaml = parsed.isErr()
|
||||||
? { json: "", yaml: "" }
|
? { json: "", yaml: "" }
|
||||||
: {
|
: {
|
||||||
json: JSON.stringify(parsed.value, null, value),
|
json: JSON.stringify(parsed.value, null, value),
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import * as O from "fp-ts/lib/Option";
|
|
||||||
|
|
||||||
import { toolGroups } from "@/config/tools";
|
import { toolGroups } from "@/config/tools";
|
||||||
import { decode } from "@/lib/jwt";
|
import { decode } from "@/lib/jwt";
|
||||||
@@ -21,8 +20,8 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { header: h, payload: p } = decode(jwt);
|
const { header: h, payload: p } = decode(jwt);
|
||||||
const header = O.isNone(h) ? "" : JSON.stringify(h.value, null, 2);
|
const header = h.isErr() ? "" : JSON.stringify(h.value, null, 2);
|
||||||
const payload = O.isNone(p) ? "" : JSON.stringify(p.value, null, 2);
|
const payload = p.isErr() ? "" : JSON.stringify(p.value, null, 2);
|
||||||
|
|
||||||
const clearJwt = useCallback(() => setJwt(""), []);
|
const clearJwt = useCallback(() => setJwt(""), []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import { constant } from "fp-ts/lib/function";
|
|
||||||
import * as O from "fp-ts/lib/Option";
|
|
||||||
|
|
||||||
import { toolGroups } from "@/config/tools";
|
import { toolGroups } from "@/config/tools";
|
||||||
import { safeDecodeURIComponent, safeEncodeURIComponent } from "@/lib/uri";
|
import { safeDecodeURIComponent, safeEncodeURIComponent } from "@/lib/uri";
|
||||||
@@ -24,14 +22,14 @@ export default function Page() {
|
|||||||
const setDecodedReactively = useCallback((text: string) => {
|
const setDecodedReactively = useCallback((text: string) => {
|
||||||
setForm({
|
setForm({
|
||||||
decoded: text,
|
decoded: text,
|
||||||
encoded: O.getOrElse(constant(""))(safeEncodeURIComponent(text)),
|
encoded: safeEncodeURIComponent(text).unwrapOr(""),
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setEncodedReactively = useCallback((text: string) => {
|
const setEncodedReactively = useCallback((text: string) => {
|
||||||
setForm({
|
setForm({
|
||||||
encoded: text,
|
encoded: text,
|
||||||
decoded: O.getOrElse(constant(""))(safeDecodeURIComponent(text)),
|
decoded: safeDecodeURIComponent(text).unwrapOr(""),
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import * as O from "fp-ts/lib/Option";
|
|
||||||
|
|
||||||
import { toolGroups } from "@/config/tools";
|
import { toolGroups } from "@/config/tools";
|
||||||
import { safeJsonParse } from "@/lib/json";
|
import { safeJsonParse } from "@/lib/json";
|
||||||
@@ -36,7 +35,7 @@ export default function Page() {
|
|||||||
const [input, setInput] = useState('{\n"foo":"bar"\n}');
|
const [input, setInput] = useState('{\n"foo":"bar"\n}');
|
||||||
|
|
||||||
const parsed = safeJsonParse(input);
|
const parsed = safeJsonParse(input);
|
||||||
const output = O.isNone(parsed) ? "" : JSON.stringify(parsed.value, null, indentation);
|
const output = parsed.isErr() ? "" : JSON.stringify(parsed.value, null, indentation);
|
||||||
|
|
||||||
const clearInput = useCallback(() => setInput(""), []);
|
const clearInput = useCallback(() => setInput(""), []);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import * as O from "fp-ts/lib/Option";
|
|
||||||
import jwt_decode from "jwt-decode";
|
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) => {
|
export const decode = (token: string) => {
|
||||||
let header: O.Option<Record<string, unknown>> = O.none;
|
let header: Result<unknown, unknown> = err("");
|
||||||
let payload: O.Option<unknown> = O.none;
|
let payload: Result<unknown, unknown> = err("");
|
||||||
|
|
||||||
if (token.split(".").length === 3) {
|
if (token.split(".").length === 3) {
|
||||||
header = safeJwtDecode(token, { header: true });
|
header = safeJwtDecode(token, { header: true });
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { tryCatchK } from "fp-ts/lib/Option";
|
import { fromThrowable } from "neverthrow";
|
||||||
|
|
||||||
export const safeEncodeURIComponent = tryCatchK(encodeURIComponent);
|
export const safeEncodeURIComponent = fromThrowable(encodeURIComponent);
|
||||||
export const safeDecodeURIComponent = tryCatchK(decodeURIComponent);
|
export const safeDecodeURIComponent = fromThrowable(decodeURIComponent);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { tryCatchK } from "fp-ts/lib/Option";
|
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
|
import { fromThrowable } from "neverthrow";
|
||||||
|
|
||||||
export const safeYamlParse = tryCatchK(yaml.load);
|
export const safeYamlParse = fromThrowable(yaml.load);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"lucide-react": "^0.221.0",
|
"lucide-react": "^0.221.0",
|
||||||
|
"neverthrow": "^6.0.0",
|
||||||
"next": "13.4.4",
|
"next": "13.4.4",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
|
|||||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@@ -61,6 +61,9 @@ dependencies:
|
|||||||
lucide-react:
|
lucide-react:
|
||||||
specifier: ^0.221.0
|
specifier: ^0.221.0
|
||||||
version: 0.221.0(react@18.2.0)
|
version: 0.221.0(react@18.2.0)
|
||||||
|
neverthrow:
|
||||||
|
specifier: ^6.0.0
|
||||||
|
version: 6.0.0
|
||||||
next:
|
next:
|
||||||
specifier: 13.4.4
|
specifier: 13.4.4
|
||||||
version: 13.4.4(@babel/core@7.22.1)(react-dom@18.2.0)(react@18.2.0)
|
version: 13.4.4(@babel/core@7.22.1)(react-dom@18.2.0)(react@18.2.0)
|
||||||
@@ -3476,6 +3479,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/neverthrow@6.0.0:
|
||||||
|
resolution: {integrity: sha512-kPZKRs4VkdloCGQXPoP84q4sT/1Z+lYM61AXyV8wWa2hnuo5KpPBF2S3crSFnMrOgUISmEBP8Vo/ngGZX60NhA==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/next-themes@0.2.1(next@13.4.4)(react-dom@18.2.0)(react@18.2.0):
|
/next-themes@0.2.1(next@13.4.4)(react-dom@18.2.0)(react@18.2.0):
|
||||||
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
|
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user