From ecc9e8336988f5560869a63823cbb006346fb23f Mon Sep 17 00:00:00 2001 From: sora-ext Date: Mon, 24 Feb 2025 16:46:22 +0100 Subject: [PATCH] Update src/types/ext.ts --- src/types/ext.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/types/ext.ts b/src/types/ext.ts index c13aa39..0344b70 100644 --- a/src/types/ext.ts +++ b/src/types/ext.ts @@ -56,27 +56,20 @@ Array.prototype.foldl = function (f: (x: T, acc: B) => B, acc: B): B { // STRING EXTENTION declare global { interface String { - btoa: () => String; toEncoded: () => String; toDecoded: () => String; } } -String.prototype.btoa = function () { - return window.btoa(this); -}; - String.prototype.toEncoded = function () { - return window.btoa( - Array.from(this as string, (c) => c.charCodeAt(0)).foldl( - (e, v) => v + String.fromCharCode(e), - "", - ), - ); + return window.btoa(encodeURIComponent(Array.from(this as string, (c) => c.charCodeAt(0)).foldl( + (e, v) => v + String.fromCharCode(e), + "", + ))) }; String.prototype.toDecoded = function () { - return Array.from(window.atob(this), (c) => c.charCodeAt(0)).foldl( + return Array.from(decodeURIComponent(window.atob(this as string)), (c) => c.charCodeAt(0)).foldl( (e, v) => v + String.fromCharCode(e), "", );