@kwiz/common 1.0.77 → 1.0.79

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.
Files changed (117) hide show
  1. package/.github/workflows/npm-publish.yml +24 -0
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/helpers/sharepoint.js +6 -6
  6. package/lib/cjs/helpers/sharepoint.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/utils/sharepoint.rest/list.js +1 -1
  9. package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
  10. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +5 -5
  11. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
  12. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  13. package/lib/esm/helpers/sharepoint.js +4 -5
  14. package/lib/esm/helpers/sharepoint.js.map +1 -1
  15. package/lib/esm/types/libs/msal.types.js +26 -26
  16. package/lib/esm/utils/sharepoint.rest/list.js +2 -2
  17. package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
  18. package/lib/esm/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +5 -5
  19. package/lib/esm/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
  20. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  21. package/lib/types/helpers/sharepoint.d.ts +1 -0
  22. package/package.json +77 -77
  23. package/readme.md +17 -17
  24. package/src/_dependencies.ts +12 -12
  25. package/src/config.ts +17 -17
  26. package/src/helpers/Guid.ts +181 -181
  27. package/src/helpers/base64.ts +173 -173
  28. package/src/helpers/browser.test.js +13 -13
  29. package/src/helpers/browser.ts +1348 -1348
  30. package/src/helpers/browserinfo.ts +292 -292
  31. package/src/helpers/collections.base.test.js +25 -25
  32. package/src/helpers/collections.base.ts +437 -437
  33. package/src/helpers/collections.ts +107 -107
  34. package/src/helpers/color.ts +54 -54
  35. package/src/helpers/cookies.ts +59 -59
  36. package/src/helpers/date.test.js +119 -119
  37. package/src/helpers/date.ts +188 -188
  38. package/src/helpers/debug.ts +186 -186
  39. package/src/helpers/emails.ts +6 -6
  40. package/src/helpers/eval.ts +5 -5
  41. package/src/helpers/file.test.js +50 -50
  42. package/src/helpers/file.ts +58 -58
  43. package/src/helpers/flatted.ts +149 -149
  44. package/src/helpers/functions.ts +16 -16
  45. package/src/helpers/graph/calendar.types.ts +10 -10
  46. package/src/helpers/http.ts +69 -69
  47. package/src/helpers/images.ts +22 -22
  48. package/src/helpers/json.ts +38 -38
  49. package/src/helpers/md5.ts +189 -189
  50. package/src/helpers/objects.test.js +33 -33
  51. package/src/helpers/objects.ts +270 -270
  52. package/src/helpers/promises.test.js +37 -37
  53. package/src/helpers/promises.ts +165 -165
  54. package/src/helpers/random.ts +27 -27
  55. package/src/helpers/scheduler/scheduler.test.js +103 -103
  56. package/src/helpers/scheduler/scheduler.ts +131 -131
  57. package/src/helpers/sharepoint.ts +776 -776
  58. package/src/helpers/strings.test.js +101 -101
  59. package/src/helpers/strings.ts +317 -317
  60. package/src/helpers/typecheckers.test.js +34 -34
  61. package/src/helpers/typecheckers.ts +262 -262
  62. package/src/helpers/url.test.js +43 -43
  63. package/src/helpers/url.ts +207 -207
  64. package/src/helpers/urlhelper.ts +111 -111
  65. package/src/index.ts +6 -6
  66. package/src/types/auth.ts +54 -54
  67. package/src/types/common.types.ts +15 -15
  68. package/src/types/flatted.types.ts +59 -59
  69. package/src/types/globals.types.ts +6 -6
  70. package/src/types/graph/calendar.types.ts +80 -80
  71. package/src/types/knownscript.types.ts +18 -18
  72. package/src/types/libs/datajs.types.ts +28 -28
  73. package/src/types/libs/ics.types.ts +30 -30
  74. package/src/types/libs/msal.types.ts +49 -49
  75. package/src/types/locales.ts +124 -124
  76. package/src/types/localstoragecache.types.ts +8 -8
  77. package/src/types/location.types.ts +27 -27
  78. package/src/types/moment.ts +11 -11
  79. package/src/types/regex.types.ts +16 -16
  80. package/src/types/rest.types.ts +95 -95
  81. package/src/types/sharepoint.types.ts +1465 -1465
  82. package/src/types/sharepoint.utils.types.ts +287 -287
  83. package/src/utils/auth/common.ts +74 -74
  84. package/src/utils/auth/discovery.test.js +12 -12
  85. package/src/utils/auth/discovery.ts +132 -132
  86. package/src/utils/base64.ts +27 -27
  87. package/src/utils/consolelogger.ts +320 -320
  88. package/src/utils/date.ts +35 -35
  89. package/src/utils/emails.ts +24 -24
  90. package/src/utils/knownscript.ts +286 -286
  91. package/src/utils/localstoragecache.ts +441 -441
  92. package/src/utils/rest.ts +501 -501
  93. package/src/utils/script.ts +170 -170
  94. package/src/utils/sharepoint.rest/common.ts +154 -154
  95. package/src/utils/sharepoint.rest/date.ts +62 -62
  96. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  97. package/src/utils/sharepoint.rest/item.ts +547 -547
  98. package/src/utils/sharepoint.rest/list.ts +1388 -1388
  99. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  100. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  101. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  102. package/src/utils/sharepoint.rest/location.ts +141 -141
  103. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  104. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  105. package/src/utils/sharepoint.rest/user.ts +491 -491
  106. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  107. package/src/utils/sod.ts +194 -194
  108. package/lib/cjs/helpers/_dependencies.js +0 -21
  109. package/lib/cjs/helpers/_dependencies.js.map +0 -1
  110. package/lib/cjs/utils/_dependencies.js +0 -24
  111. package/lib/cjs/utils/_dependencies.js.map +0 -1
  112. package/lib/esm/helpers/_dependencies.js +0 -3
  113. package/lib/esm/helpers/_dependencies.js.map +0 -1
  114. package/lib/esm/utils/_dependencies.js +0 -4
  115. package/lib/esm/utils/_dependencies.js.map +0 -1
  116. package/lib/types/helpers/_dependencies.d.ts +0 -2
  117. package/lib/types/utils/_dependencies.d.ts +0 -3
@@ -1,174 +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 });
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
174
  }
@@ -1,13 +1,13 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { DisableAnchorInterceptInHtml, HTMLDecode } 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
- });
10
-
11
- test('HTMLDecode', async t => {
12
- assert.strictEqual(HTMLDecode(`hello &lt; &#58;`), `hello < :`);
13
- });
1
+ import assert from 'assert/strict';
2
+ import test from 'node:test';
3
+ import { DisableAnchorInterceptInHtml, HTMLDecode } 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
+ });
10
+
11
+ test('HTMLDecode', async t => {
12
+ assert.strictEqual(HTMLDecode(`hello &lt; &#58;`), `hello < :`);
13
+ });