use messagepack to make it even smaller!!!!
This commit is contained in:
parent
a5457c6cc6
commit
b6e24c517b
4 changed files with 28 additions and 10 deletions
|
@ -1,11 +1,13 @@
|
|||
import m from "msgpack-lite";
|
||||
|
||||
// i actually love this
|
||||
export const b64encode = (obj: object): string => {
|
||||
return Buffer.from(JSON.stringify(obj)).toString("base64url");
|
||||
return Buffer.from(m.encode(obj)).toString("base64url");
|
||||
}
|
||||
|
||||
export const b64decode = <T>(str: string): T => {
|
||||
try {
|
||||
return JSON.parse(Buffer.from(str, "base64url").toString());
|
||||
return m.decode(Buffer.from(str, "base64url"));
|
||||
} catch {
|
||||
throw new Error("invalid base64-encoded object string: " + str);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue