mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import 'fast-text-encoding'
2import Graphemer from 'graphemer'
3export {}
4
5/**
6https://github.com/MaxArt2501/base64-js
7The MIT License (MIT)
8Copyright (c) 2014 MaxArt2501
9 */
10
11const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
12// Regular expression to check formal correctness of base64 encoded strings
13const b64re =
14 /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/
15
16globalThis.atob = (str: string): string => {
17 // atob can work with strings with whitespaces, even inside the encoded part,
18 // but only \t, \n, \f, \r and ' ', which can be stripped.
19 str = String(str).replace(/[\t\n\f\r ]+/g, '')
20 if (!b64re.test(str)) {
21 throw new TypeError(
22 "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
23 )
24 }
25
26 // Adding the padding if missing, for simplicity
27 str += '=='.slice(2 - (str.length & 3))
28 var bitmap,
29 result = '',
30 r1,
31 r2,
32 i = 0
33 for (; i < str.length; ) {
34 bitmap =
35 (b64.indexOf(str.charAt(i++)) << 18) |
36 (b64.indexOf(str.charAt(i++)) << 12) |
37 ((r1 = b64.indexOf(str.charAt(i++))) << 6) |
38 (r2 = b64.indexOf(str.charAt(i++)))
39
40 result +=
41 r1 === 64
42 ? String.fromCharCode((bitmap >> 16) & 255)
43 : r2 === 64
44 ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
45 : String.fromCharCode(
46 (bitmap >> 16) & 255,
47 (bitmap >> 8) & 255,
48 bitmap & 255,
49 )
50 }
51 return result
52}
53
54const splitter = new Graphemer()
55globalThis.Intl = globalThis.Intl || {}
56
57// @ts-ignore we're polyfilling -prf
58globalThis.Intl.Segmenter =
59 // @ts-ignore we're polyfilling -prf
60 globalThis.Intl.Segmenter ||
61 class Segmenter {
62 constructor() {}
63 // NOTE
64 // this is not a precisely correct polyfill but it's sufficient for our needs
65 // -prf
66 segment = splitter.iterateGraphemes
67 }