Update src/types/ext.ts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d689ceb511
commit
ecc9e83369
@ -56,27 +56,20 @@ Array.prototype.foldl = function <T, B>(f: (x: T, acc: B) => B, acc: B): B {
|
|||||||
// STRING EXTENTION
|
// STRING EXTENTION
|
||||||
declare global {
|
declare global {
|
||||||
interface String {
|
interface String {
|
||||||
btoa: () => String;
|
|
||||||
toEncoded: () => String;
|
toEncoded: () => String;
|
||||||
toDecoded: () => String;
|
toDecoded: () => String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String.prototype.btoa = function () {
|
|
||||||
return window.btoa(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
String.prototype.toEncoded = function () {
|
String.prototype.toEncoded = function () {
|
||||||
return window.btoa(
|
return window.btoa(encodeURIComponent(Array.from(this as string, (c) => c.charCodeAt(0)).foldl(
|
||||||
Array.from(this as string, (c) => c.charCodeAt(0)).foldl(
|
(e, v) => v + String.fromCharCode(e),
|
||||||
(e, v) => v + String.fromCharCode(e),
|
"",
|
||||||
"",
|
)))
|
||||||
),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
String.prototype.toDecoded = function () {
|
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),
|
(e, v) => v + String.fromCharCode(e),
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user