utils.ts 525 B

12345678910111213141516171819
  1. export function debounce(fn: Function, n = 100) {
  2. let handle: any
  3. return (...args: any[]) => {
  4. if (handle) clearTimeout(handle)
  5. handle = setTimeout(() => {
  6. fn(...args)
  7. }, n)
  8. }
  9. }
  10. // prefer old unicode hacks for backward compatibility
  11. // https://base64.guru/developers/javascript/examples/unicode-strings
  12. export function utoa(data: string): string {
  13. return btoa(unescape(encodeURIComponent(data)))
  14. }
  15. export function atou(base64: string): string {
  16. return decodeURIComponent(escape(atob(base64)))
  17. }