@kwiz/common 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_dependencies.d.ts +1 -0
- package/dist/_dependencies.js +8 -0
- package/dist/_dependencies.js.map +1 -0
- package/dist/helpers/Guid.d.ts +119 -0
- package/dist/helpers/Guid.js +183 -0
- package/dist/helpers/Guid.js.map +1 -0
- package/dist/helpers/_dependencies.d.ts +2 -0
- package/dist/helpers/_dependencies.js +21 -0
- package/dist/helpers/_dependencies.js.map +1 -0
- package/dist/helpers/base64.d.ts +8 -0
- package/dist/helpers/base64.js +178 -0
- package/dist/helpers/base64.js.map +1 -0
- package/dist/helpers/browser.d.ts +144 -0
- package/dist/helpers/browser.js +1200 -0
- package/dist/helpers/browser.js.map +1 -0
- package/dist/helpers/browserinfo.d.ts +23 -0
- package/dist/helpers/browserinfo.js +215 -0
- package/dist/helpers/browserinfo.js.map +1 -0
- package/dist/helpers/collections.base.d.ts +128 -0
- package/dist/helpers/collections.base.js +430 -0
- package/dist/helpers/collections.base.js.map +1 -0
- package/dist/helpers/collections.d.ts +18 -0
- package/dist/helpers/collections.js +99 -0
- package/dist/helpers/collections.js.map +1 -0
- package/dist/helpers/color.d.ts +11 -0
- package/dist/helpers/color.js +57 -0
- package/dist/helpers/color.js.map +1 -0
- package/dist/helpers/cookies.d.ts +6 -0
- package/dist/helpers/cookies.js +56 -0
- package/dist/helpers/cookies.js.map +1 -0
- package/dist/helpers/date.d.ts +43 -0
- package/dist/helpers/date.js +158 -0
- package/dist/helpers/date.js.map +1 -0
- package/dist/helpers/debug.d.ts +33 -0
- package/dist/helpers/debug.js +177 -0
- package/dist/helpers/debug.js.map +1 -0
- package/dist/helpers/emails.d.ts +2 -0
- package/dist/helpers/emails.js +10 -0
- package/dist/helpers/emails.js.map +1 -0
- package/dist/helpers/eval.d.ts +1 -0
- package/dist/helpers/eval.js +10 -0
- package/dist/helpers/eval.js.map +1 -0
- package/dist/helpers/file.d.ts +11 -0
- package/dist/helpers/file.js +55 -0
- package/dist/helpers/file.js.map +1 -0
- package/dist/helpers/flatted.d.ts +20 -0
- package/dist/helpers/flatted.js +135 -0
- package/dist/helpers/flatted.js.map +1 -0
- package/dist/helpers/functions.d.ts +4 -0
- package/dist/helpers/functions.js +17 -0
- package/dist/helpers/functions.js.map +1 -0
- package/dist/helpers/graph/calendar.types.d.ts +3 -0
- package/dist/helpers/graph/calendar.types.js +15 -0
- package/dist/helpers/graph/calendar.types.js.map +1 -0
- package/dist/helpers/http.d.ts +25 -0
- package/dist/helpers/http.js +70 -0
- package/dist/helpers/http.js.map +1 -0
- package/dist/helpers/images.d.ts +16 -0
- package/dist/helpers/images.js +21 -0
- package/dist/helpers/images.js.map +1 -0
- package/dist/helpers/index.d.ts +29 -0
- package/dist/helpers/index.js +46 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/json.d.ts +3 -0
- package/dist/helpers/json.js +44 -0
- package/dist/helpers/json.js.map +1 -0
- package/dist/helpers/md5.d.ts +5 -0
- package/dist/helpers/md5.js +172 -0
- package/dist/helpers/md5.js.map +1 -0
- package/dist/helpers/objects.d.ts +49 -0
- package/dist/helpers/objects.js +271 -0
- package/dist/helpers/objects.js.map +1 -0
- package/dist/helpers/promises.d.ts +14 -0
- package/dist/helpers/promises.js +112 -0
- package/dist/helpers/promises.js.map +1 -0
- package/dist/helpers/random.d.ts +2 -0
- package/dist/helpers/random.js +32 -0
- package/dist/helpers/random.js.map +1 -0
- package/dist/helpers/scheduler/scheduler.d.ts +39 -0
- package/dist/helpers/scheduler/scheduler.js +109 -0
- package/dist/helpers/scheduler/scheduler.js.map +1 -0
- package/dist/helpers/sharepoint.d.ts +112 -0
- package/dist/helpers/sharepoint.js +629 -0
- package/dist/helpers/sharepoint.js.map +1 -0
- package/dist/helpers/strings.d.ts +56 -0
- package/dist/helpers/strings.js +282 -0
- package/dist/helpers/strings.js.map +1 -0
- package/dist/helpers/typecheckers.d.ts +56 -0
- package/dist/helpers/typecheckers.js +274 -0
- package/dist/helpers/typecheckers.js.map +1 -0
- package/dist/helpers/url.d.ts +46 -0
- package/dist/helpers/url.js +199 -0
- package/dist/helpers/url.js.map +1 -0
- package/dist/helpers/urlhelper.d.ts +16 -0
- package/dist/helpers/urlhelper.js +96 -0
- package/dist/helpers/urlhelper.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/types/common.types.d.ts +19 -0
- package/dist/types/common.types.js +4 -0
- package/dist/types/common.types.js.map +1 -0
- package/dist/types/flatted.types.d.ts +49 -0
- package/dist/types/flatted.types.js +3 -0
- package/dist/types/flatted.types.js.map +1 -0
- package/dist/types/globals.types.d.ts +6 -0
- package/dist/types/globals.types.js +3 -0
- package/dist/types/globals.types.js.map +1 -0
- package/dist/types/graph/calendar.types.d.ts +79 -0
- package/dist/types/graph/calendar.types.js +3 -0
- package/dist/types/graph/calendar.types.js.map +1 -0
- package/dist/types/graph/index.d.ts +1 -0
- package/dist/types/graph/index.js +18 -0
- package/dist/types/graph/index.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +28 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/knownscript.types.d.ts +22 -0
- package/dist/types/knownscript.types.js +3 -0
- package/dist/types/knownscript.types.js.map +1 -0
- package/dist/types/libs/datajs.types.d.ts +29 -0
- package/dist/types/libs/datajs.types.js +3 -0
- package/dist/types/libs/datajs.types.js.map +1 -0
- package/dist/types/libs/ics.types.d.ts +29 -0
- package/dist/types/libs/ics.types.js +3 -0
- package/dist/types/libs/ics.types.js.map +1 -0
- package/dist/types/libs/index.d.ts +3 -0
- package/dist/types/libs/index.js +20 -0
- package/dist/types/libs/index.js.map +1 -0
- package/dist/types/libs/msal.types.d.ts +33 -0
- package/dist/types/libs/msal.types.js +63 -0
- package/dist/types/libs/msal.types.js.map +1 -0
- package/dist/types/locales.d.ts +122 -0
- package/dist/types/locales.js +1 -0
- package/dist/types/locales.js.map +1 -0
- package/dist/types/localstoragecache.types.d.ts +8 -0
- package/dist/types/localstoragecache.types.js +3 -0
- package/dist/types/localstoragecache.types.js.map +1 -0
- package/dist/types/moment.d.ts +6 -0
- package/dist/types/moment.js +1 -0
- package/dist/types/moment.js.map +1 -0
- package/dist/types/regex.types.d.ts +14 -0
- package/dist/types/regex.types.js +3 -0
- package/dist/types/regex.types.js.map +1 -0
- package/dist/types/rest.types.d.ts +81 -0
- package/dist/types/rest.types.js +24 -0
- package/dist/types/rest.types.js.map +1 -0
- package/dist/types/sharepoint.types.d.ts +1432 -0
- package/dist/types/sharepoint.types.js +629 -0
- package/dist/types/sharepoint.types.js.map +1 -0
- package/dist/types/sharepoint.utils.types.d.ts +246 -0
- package/dist/types/sharepoint.utils.types.js +26 -0
- package/dist/types/sharepoint.utils.types.js.map +1 -0
- package/dist/utils/_dependencies.d.ts +3 -0
- package/dist/utils/_dependencies.js +24 -0
- package/dist/utils/_dependencies.js.map +1 -0
- package/dist/utils/base64.d.ts +2 -0
- package/dist/utils/base64.js +41 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/consolelogger.d.ts +73 -0
- package/dist/utils/consolelogger.js +281 -0
- package/dist/utils/consolelogger.js.map +1 -0
- package/dist/utils/date.d.ts +10 -0
- package/dist/utils/date.js +30 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/emails.d.ts +2 -0
- package/dist/utils/emails.js +24 -0
- package/dist/utils/emails.js.map +1 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/knownscript.d.ts +99 -0
- package/dist/utils/knownscript.js +261 -0
- package/dist/utils/knownscript.js.map +1 -0
- package/dist/utils/localstoragecache.d.ts +19 -0
- package/dist/utils/localstoragecache.js +372 -0
- package/dist/utils/localstoragecache.js.map +1 -0
- package/dist/utils/rest.d.ts +17 -0
- package/dist/utils/rest.js +402 -0
- package/dist/utils/rest.js.map +1 -0
- package/dist/utils/script.d.ts +33 -0
- package/dist/utils/script.js +169 -0
- package/dist/utils/script.js.map +1 -0
- package/dist/utils/sharepoint.rest/common.d.ts +32 -0
- package/dist/utils/sharepoint.rest/common.js +146 -0
- package/dist/utils/sharepoint.rest/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/date.d.ts +2 -0
- package/dist/utils/sharepoint.rest/date.js +57 -0
- package/dist/utils/sharepoint.rest/date.js.map +1 -0
- package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
- package/dist/utils/sharepoint.rest/file.folder.js +305 -0
- package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
- package/dist/utils/sharepoint.rest/index.d.ts +11 -0
- package/dist/utils/sharepoint.rest/index.js +28 -0
- package/dist/utils/sharepoint.rest/index.js.map +1 -0
- package/dist/utils/sharepoint.rest/item.d.ts +81 -0
- package/dist/utils/sharepoint.rest/item.js +444 -0
- package/dist/utils/sharepoint.rest/item.js.map +1 -0
- package/dist/utils/sharepoint.rest/list.d.ts +228 -0
- package/dist/utils/sharepoint.rest/list.js +868 -0
- package/dist/utils/sharepoint.rest/list.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
- package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
- package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
- package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
- package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
- package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
- package/dist/utils/sharepoint.rest/user-search.js +239 -0
- package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
- package/dist/utils/sharepoint.rest/user.d.ts +71 -0
- package/dist/utils/sharepoint.rest/user.js +404 -0
- package/dist/utils/sharepoint.rest/user.js.map +1 -0
- package/dist/utils/sharepoint.rest/web.d.ts +107 -0
- package/dist/utils/sharepoint.rest/web.js +929 -0
- package/dist/utils/sharepoint.rest/web.js.map +1 -0
- package/dist/utils/sod.d.ts +29 -0
- package/dist/utils/sod.js +177 -0
- package/dist/utils/sod.js.map +1 -0
- package/package.json +60 -0
- package/readme.md +13 -0
- package/src/_dependencies.ts +2 -0
- package/src/helpers/Guid.ts +182 -0
- package/src/helpers/_dependencies.ts +3 -0
- package/src/helpers/base64.ts +174 -0
- package/src/helpers/browser.test.js +9 -0
- package/src/helpers/browser.ts +1299 -0
- package/src/helpers/browserinfo.ts +293 -0
- package/src/helpers/collections.base.test.js +26 -0
- package/src/helpers/collections.base.ts +439 -0
- package/src/helpers/collections.ts +108 -0
- package/src/helpers/color.ts +55 -0
- package/src/helpers/cookies.ts +55 -0
- package/src/helpers/date.test.js +97 -0
- package/src/helpers/date.ts +163 -0
- package/src/helpers/debug.ts +187 -0
- package/src/helpers/emails.ts +7 -0
- package/src/helpers/eval.ts +5 -0
- package/src/helpers/file.test.js +51 -0
- package/src/helpers/file.ts +59 -0
- package/src/helpers/flatted.ts +150 -0
- package/src/helpers/functions.ts +17 -0
- package/src/helpers/graph/calendar.types.ts +11 -0
- package/src/helpers/http.ts +70 -0
- package/src/helpers/images.ts +23 -0
- package/src/helpers/index.ts +29 -0
- package/src/helpers/json.ts +39 -0
- package/src/helpers/md5.ts +190 -0
- package/src/helpers/objects.test.js +27 -0
- package/src/helpers/objects.ts +256 -0
- package/src/helpers/promises.test.js +18 -0
- package/src/helpers/promises.ts +102 -0
- package/src/helpers/random.ts +27 -0
- package/src/helpers/scheduler/scheduler.test.js +104 -0
- package/src/helpers/scheduler/scheduler.ts +132 -0
- package/src/helpers/sharepoint.ts +681 -0
- package/src/helpers/strings.test.js +43 -0
- package/src/helpers/strings.ts +288 -0
- package/src/helpers/typecheckers.test.js +35 -0
- package/src/helpers/typecheckers.ts +263 -0
- package/src/helpers/url.test.js +18 -0
- package/src/helpers/url.ts +202 -0
- package/src/helpers/urlhelper.ts +104 -0
- package/src/index.ts +24 -0
- package/src/types/common.types.ts +16 -0
- package/src/types/flatted.types.ts +60 -0
- package/src/types/globals.types.ts +7 -0
- package/src/types/graph/calendar.types.ts +81 -0
- package/src/types/graph/index.ts +1 -0
- package/src/types/index.ts +12 -0
- package/src/types/knownscript.types.ts +19 -0
- package/src/types/libs/datajs.types.ts +29 -0
- package/src/types/libs/ics.types.ts +31 -0
- package/src/types/libs/index.ts +4 -0
- package/src/types/libs/msal.types.ts +79 -0
- package/src/types/locales.ts +125 -0
- package/src/types/localstoragecache.types.ts +9 -0
- package/src/types/moment.ts +7 -0
- package/src/types/regex.types.ts +17 -0
- package/src/types/rest.types.ts +94 -0
- package/src/types/sharepoint.types.ts +1413 -0
- package/src/types/sharepoint.utils.types.ts +246 -0
- package/src/utils/_dependencies.ts +4 -0
- package/src/utils/base64.ts +27 -0
- package/src/utils/consolelogger.ts +315 -0
- package/src/utils/date.ts +36 -0
- package/src/utils/emails.ts +25 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/knownscript.ts +280 -0
- package/src/utils/localstoragecache.ts +419 -0
- package/src/utils/rest.ts +465 -0
- package/src/utils/script.ts +168 -0
- package/src/utils/sharepoint.rest/common.ts +149 -0
- package/src/utils/sharepoint.rest/date.ts +61 -0
- package/src/utils/sharepoint.rest/file.folder.ts +368 -0
- package/src/utils/sharepoint.rest/index.ts +11 -0
- package/src/utils/sharepoint.rest/item.ts +456 -0
- package/src/utils/sharepoint.rest/list.ts +1144 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
- package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
- package/src/utils/sharepoint.rest/user-search.ts +254 -0
- package/src/utils/sharepoint.rest/user.ts +447 -0
- package/src/utils/sharepoint.rest/web.ts +1031 -0
- package/src/utils/sod.ts +193 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
|
|
2
|
+
export async function blobToBase64(data: Blob): Promise<string> {
|
|
3
|
+
return new Promise<string>((resolve, reject) => {
|
|
4
|
+
var fileReader = new FileReader();
|
|
5
|
+
fileReader.onloadend = () => {
|
|
6
|
+
resolve(fileReader.result as string);
|
|
7
|
+
};
|
|
8
|
+
fileReader.onerror = () => {
|
|
9
|
+
reject();
|
|
10
|
+
};
|
|
11
|
+
fileReader.readAsDataURL(data);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** returns true of the string is a data: with base64 content */
|
|
16
|
+
export function isBase64ImageData(str: string): boolean {
|
|
17
|
+
return str.startsWith("data") && str.indexOf("base64") > 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const alphabet = [
|
|
21
|
+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
|
22
|
+
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
|
23
|
+
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
|
24
|
+
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
|
25
|
+
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
|
26
|
+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
|
27
|
+
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
|
28
|
+
'4', '5', '6', '7', '8', '9', '+', '/'
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const values = {};
|
|
32
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
|
33
|
+
values[alphabet[i]] = i;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function encode(bytes: ArrayBuffer): string {
|
|
37
|
+
const array = new Uint8Array(bytes);
|
|
38
|
+
const base64 = [];
|
|
39
|
+
let index = 0;
|
|
40
|
+
let quantum;
|
|
41
|
+
let value;
|
|
42
|
+
|
|
43
|
+
// Grab as many sets of 3 bytes as we can, that form 24 bits.
|
|
44
|
+
while (index + 2 < array.byteLength) {
|
|
45
|
+
quantum = (array[index] << 16) | (array[index + 1] << 8) | array[index + 2];
|
|
46
|
+
// 24 bits will become 4 base64 chars.
|
|
47
|
+
value = (quantum >> 18) & 0x3f;
|
|
48
|
+
base64.push(alphabet[value]);
|
|
49
|
+
value = (quantum >> 12) & 0x3f;
|
|
50
|
+
base64.push(alphabet[value]);
|
|
51
|
+
value = (quantum >> 6) & 0x3f;
|
|
52
|
+
base64.push(alphabet[value]);
|
|
53
|
+
value = quantum & 0x3f;
|
|
54
|
+
base64.push(alphabet[value]);
|
|
55
|
+
index += 3;
|
|
56
|
+
}
|
|
57
|
+
// At this point, there are 0, 1 or 2 bytes left.
|
|
58
|
+
if (index + 1 === array.byteLength) {
|
|
59
|
+
// 8 bits; shift by 4 to pad on the right with 0s to make 12 bits total.
|
|
60
|
+
quantum = array[index] << 4;
|
|
61
|
+
value = (quantum >> 6) & 0x3f;
|
|
62
|
+
base64.push(alphabet[value]);
|
|
63
|
+
value = quantum & 0x3f;
|
|
64
|
+
base64.push(alphabet[value]);
|
|
65
|
+
base64.push('==');
|
|
66
|
+
} else if (index + 2 === array.byteLength) {
|
|
67
|
+
// 16 bits; shift by 2 to pad on the right with 0s to make 18 bits total.
|
|
68
|
+
quantum = (array[index] << 10) | (array[index + 1] << 2);
|
|
69
|
+
value = (quantum >> 12) & 0x3f;
|
|
70
|
+
base64.push(alphabet[value]);
|
|
71
|
+
value = (quantum >> 6) & 0x3f;
|
|
72
|
+
base64.push(alphabet[value]);
|
|
73
|
+
value = quantum & 0x3f;
|
|
74
|
+
base64.push(alphabet[value]);
|
|
75
|
+
base64.push('=');
|
|
76
|
+
}
|
|
77
|
+
return base64.join('');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function decode(string: string): Uint8Array {
|
|
81
|
+
let size = string.length;
|
|
82
|
+
if (size === 0) {
|
|
83
|
+
return new Uint8Array(new ArrayBuffer(0));
|
|
84
|
+
}
|
|
85
|
+
if (size % 4 !== 0) {
|
|
86
|
+
throw new Error('Bad length: ' + size);
|
|
87
|
+
}
|
|
88
|
+
if (!string.match(/^[a-zA-Z0-9+/]+={0,2}$/)) {
|
|
89
|
+
throw new Error('Invalid base64 encoded value');
|
|
90
|
+
}
|
|
91
|
+
// Every 4 base64 chars = 24 bits = 3 bytes. But, we also need to figure out
|
|
92
|
+
// padding, if any.
|
|
93
|
+
let bytes = 3 * (size / 4);
|
|
94
|
+
let numPad = 0;
|
|
95
|
+
if (string.charAt(size - 1) === '=') {
|
|
96
|
+
numPad++;
|
|
97
|
+
bytes--;
|
|
98
|
+
}
|
|
99
|
+
if (string.charAt(size - 2) === '=') {
|
|
100
|
+
numPad++;
|
|
101
|
+
bytes--;
|
|
102
|
+
}
|
|
103
|
+
const buffer = new Uint8Array(new ArrayBuffer(bytes));
|
|
104
|
+
let index = 0;
|
|
105
|
+
let bufferIndex = 0;
|
|
106
|
+
let quantum;
|
|
107
|
+
if (numPad > 0) {
|
|
108
|
+
size -= 4; // handle the last one specially
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
while (index < size) {
|
|
112
|
+
quantum = 0;
|
|
113
|
+
for (let i = 0; i < 4; ++i) {
|
|
114
|
+
quantum = (quantum << 6) | values[string.charAt(index + i)];
|
|
115
|
+
}
|
|
116
|
+
// quantum is now a 24-bit value.
|
|
117
|
+
buffer[bufferIndex++] = (quantum >> 16) & 0xff;
|
|
118
|
+
buffer[bufferIndex++] = (quantum >> 8) & 0xff;
|
|
119
|
+
buffer[bufferIndex++] = quantum & 0xff;
|
|
120
|
+
index += 4;
|
|
121
|
+
}
|
|
122
|
+
if (numPad > 0) {
|
|
123
|
+
// if numPad === 1, there is one =, and we have 18 bits with 2 0s at end.
|
|
124
|
+
// if numPad === 2, there is two ==, and we have 12 bits with 4 0s at end.
|
|
125
|
+
// First, grab my quantum.
|
|
126
|
+
quantum = 0;
|
|
127
|
+
for (let i = 0; i < 4 - numPad; ++i) {
|
|
128
|
+
quantum = (quantum << 6) | values[string.charAt(index + i)];
|
|
129
|
+
}
|
|
130
|
+
if (numPad === 1) {
|
|
131
|
+
// quantum is 18 bits, but really represents two bytes.
|
|
132
|
+
quantum = quantum >> 2;
|
|
133
|
+
buffer[bufferIndex++] = (quantum >> 8) & 0xff;
|
|
134
|
+
buffer[bufferIndex++] = quantum & 0xff;
|
|
135
|
+
} else {
|
|
136
|
+
// quantum is 12 bits, but really represents only one byte.
|
|
137
|
+
quantum = quantum >> 4;
|
|
138
|
+
buffer[bufferIndex++] = quantum & 0xff;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return buffer;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function toArrayBuffer(base64: string): ArrayBuffer {
|
|
145
|
+
var uint8Array = decode(base64);
|
|
146
|
+
return uint8Array.buffer;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function toUint8Array(base64: string): Uint8Array {
|
|
150
|
+
return decode(base64);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function fromArrayBuffer(arraybuffer: ArrayBuffer) {
|
|
154
|
+
return encode(arraybuffer);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function fromUint8Array(uint8Array: Uint8Array) {
|
|
158
|
+
return encode(uint8Array.buffer);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function dataURLtoFile(dataurl, filename): File {
|
|
162
|
+
|
|
163
|
+
var arr = dataurl.split(','),
|
|
164
|
+
mime = arr[0].match(/:(.*?);/)[1],
|
|
165
|
+
bstr = atob(arr[1]),
|
|
166
|
+
n = bstr.length,
|
|
167
|
+
u8arr = new Uint8Array(n);
|
|
168
|
+
|
|
169
|
+
while (n--) {
|
|
170
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return new File([u8arr], filename, { type: mime });
|
|
174
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import assert from 'assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { DisableAnchorInterceptInHtml } from "./browser";
|
|
4
|
+
|
|
5
|
+
test('DisableAnchorInterceptInHtml', async t => {
|
|
6
|
+
assert.strictEqual(DisableAnchorInterceptInHtml(`<a href="blah">test</a>`), `<a data-interception="off" href="blah">test</a>`);
|
|
7
|
+
assert.strictEqual(DisableAnchorInterceptInHtml(`<div><a href="blah">test</a><a href="blah">test</a></div>`), `<div><a data-interception="off" href="blah">test</a><a data-interception="off" href="blah">test</a></div>`);
|
|
8
|
+
assert.strictEqual(DisableAnchorInterceptInHtml(`<p href="blah">test</p>`), `<p href="blah">test</p>`);
|
|
9
|
+
});
|