12 lines
No EOL
369 B
TypeScript
12 lines
No EOL
369 B
TypeScript
// i actually love this
|
|
export const b64encode = (obj: object): string => {
|
|
return Buffer.from(JSON.stringify(obj)).toString("base64url");
|
|
}
|
|
|
|
export const b64decode = <T>(str: string): T => {
|
|
try {
|
|
return JSON.parse(Buffer.from(str, "base64url").toString());
|
|
} catch {
|
|
throw new Error("invalid base64-encoded object string: " + str);
|
|
}
|
|
} |