perf(bundle): drop js-base64

This commit is contained in:
rusconn
2024-09-19 02:59:34 +09:00
parent 90ba9f4f8e
commit f12adfa296
4 changed files with 17 additions and 11 deletions

View File

@@ -1,9 +1,9 @@
"use client"; "use client";
import { useCallback, useState } from "react"; import { useCallback, useState } from "react";
import { decode, encode, isValid } from "js-base64";
import { toolGroups } from "@/config/tools"; import { toolGroups } from "@/config/tools";
import { decode, encode } from "@/lib/base64";
import { Textarea, TextareaProps } from "@/components/ui/textarea"; import { Textarea, TextareaProps } from "@/components/ui/textarea";
import * as Button from "@/components/buttons"; import * as Button from "@/components/buttons";
import { ControlMenu } from "@/components/control-menu"; import { ControlMenu } from "@/components/control-menu";
@@ -24,10 +24,10 @@ export default function Page() {
}, []); }, []);
const setFormByEncoded = useCallback((text: string) => { const setFormByEncoded = useCallback((text: string) => {
const newDecoded = decode(text); const newDecoded = decode(text) ?? "";
setForm({ setForm({
decoded: isValid(text) && !newDecoded.includes("<22>") ? newDecoded : "", decoded: newDecoded.includes("<22>") ? "" : newDecoded,
encoded: text, encoded: text,
}); });
}, []); }, []);

14
lib/base64.ts Normal file
View File

@@ -0,0 +1,14 @@
export const encode = (s: string) => {
const bytes = new TextEncoder().encode(s);
return btoa(String.fromCharCode(...bytes));
};
export const decode = (base64: string) => {
try {
const binString = atob(base64);
const bytes = Uint8Array.from(binString, c => c.charCodeAt(0));
return new TextDecoder().decode(bytes);
} catch {
return undefined;
}
};

View File

@@ -39,7 +39,6 @@
"fp-ts": "^2.16.0", "fp-ts": "^2.16.0",
"fuse.js": "^6.6.2", "fuse.js": "^6.6.2",
"html-escaper": "^3.0.3", "html-escaper": "^3.0.3",
"js-base64": "^3.7.5",
"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",

7
pnpm-lock.yaml generated
View File

@@ -43,9 +43,6 @@ dependencies:
html-escaper: html-escaper:
specifier: ^3.0.3 specifier: ^3.0.3
version: 3.0.3 version: 3.0.3
js-base64:
specifier: ^3.7.5
version: 3.7.5
js-yaml: js-yaml:
specifier: ^4.1.0 specifier: ^4.1.0
version: 4.1.0 version: 4.1.0
@@ -3645,10 +3642,6 @@ packages:
resolution: {integrity: sha512-QAdOptna2NYiSSpv0O/BwoHBSmz4YhpzJHyi+fnMRTXFjp7B8i/YG5Z8IfusxB1ufjcD2Sre1F3R+nX3fvy7gg==} resolution: {integrity: sha512-QAdOptna2NYiSSpv0O/BwoHBSmz4YhpzJHyi+fnMRTXFjp7B8i/YG5Z8IfusxB1ufjcD2Sre1F3R+nX3fvy7gg==}
hasBin: true hasBin: true
/js-base64@3.7.5:
resolution: {integrity: sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==}
dev: false
/js-tokens@4.0.0: /js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}