atob/btoa only supports ASCII string which makes playground fails to save unicode source. This patch add unicode support by combining escape/encodeURIComponent. `escape` is chosen for backward compatibility.
20 lines
525 B
TypeScript
20 lines
525 B
TypeScript
export function debounce(fn: Function, n = 100) {
|
|
let handle: any
|
|
return (...args: any[]) => {
|
|
if (handle) clearTimeout(handle)
|
|
handle = setTimeout(() => {
|
|
fn(...args)
|
|
}, n)
|
|
}
|
|
}
|
|
|
|
// prefer old unicode hacks for backward compatibility
|
|
// https://base64.guru/developers/javascript/examples/unicode-strings
|
|
export function utoa(data: string): string {
|
|
return btoa(unescape(encodeURIComponent(data)))
|
|
}
|
|
|
|
export function atou(base64: string): string {
|
|
return decodeURIComponent(escape(atob(base64)))
|
|
}
|