Herrington Darkholme 9a5bdb15df
chore(playground): support unicode in sfc playground (#3662)
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.
2021-06-08 10:12:15 -04:00

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)))
}