@kwiz/common 1.0.78 → 1.0.80
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/.github/workflows/npm-publish.yml +24 -0
- package/.madgerc +2 -2
- package/LICENSE +21 -21
- package/fix-folder-imports.js +26 -26
- package/lib/cjs/helpers/sharepoint.js +5 -1
- package/lib/cjs/helpers/sharepoint.js.map +1 -1
- package/lib/cjs/helpers/typecheckers.js +5 -1
- package/lib/cjs/helpers/typecheckers.js.map +1 -1
- package/lib/cjs/types/libs/msal.types.js +26 -26
- package/lib/cjs/utils/sharepoint.rest/list.js +1 -1
- package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
- package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
- package/lib/esm/helpers/sharepoint.js +3 -0
- package/lib/esm/helpers/sharepoint.js.map +1 -1
- package/lib/esm/helpers/typecheckers.js +3 -0
- package/lib/esm/helpers/typecheckers.js.map +1 -1
- package/lib/esm/types/libs/msal.types.js +26 -26
- package/lib/esm/utils/sharepoint.rest/list.js +2 -2
- package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
- package/lib/esm/utils/sharepoint.rest/user.js +11 -11
- package/lib/types/helpers/sharepoint.d.ts +1 -0
- package/lib/types/helpers/typecheckers.d.ts +1 -0
- package/package.json +77 -77
- package/readme.md +17 -17
- package/src/_dependencies.ts +12 -12
- package/src/config.ts +17 -17
- package/src/helpers/Guid.ts +181 -181
- package/src/helpers/base64.ts +173 -173
- package/src/helpers/browser.test.js +13 -13
- package/src/helpers/browser.ts +1348 -1348
- package/src/helpers/browserinfo.ts +292 -292
- package/src/helpers/collections.base.test.js +25 -25
- package/src/helpers/collections.base.ts +437 -437
- package/src/helpers/collections.ts +107 -107
- package/src/helpers/color.ts +54 -54
- package/src/helpers/cookies.ts +59 -59
- package/src/helpers/date.test.js +119 -119
- package/src/helpers/date.ts +188 -188
- package/src/helpers/debug.ts +186 -186
- package/src/helpers/emails.ts +6 -6
- package/src/helpers/eval.ts +5 -5
- package/src/helpers/file.test.js +50 -50
- package/src/helpers/file.ts +58 -58
- package/src/helpers/flatted.ts +149 -149
- package/src/helpers/functions.ts +16 -16
- package/src/helpers/graph/calendar.types.ts +10 -10
- package/src/helpers/http.ts +69 -69
- package/src/helpers/images.ts +22 -22
- package/src/helpers/json.ts +38 -38
- package/src/helpers/md5.ts +189 -189
- package/src/helpers/objects.test.js +33 -33
- package/src/helpers/objects.ts +270 -270
- package/src/helpers/promises.test.js +37 -37
- package/src/helpers/promises.ts +165 -165
- package/src/helpers/random.ts +27 -27
- package/src/helpers/scheduler/scheduler.test.js +103 -103
- package/src/helpers/scheduler/scheduler.ts +131 -131
- package/src/helpers/sharepoint.ts +776 -772
- package/src/helpers/strings.test.js +101 -101
- package/src/helpers/strings.ts +317 -317
- package/src/helpers/typecheckers.test.js +34 -34
- package/src/helpers/typecheckers.ts +266 -262
- package/src/helpers/url.test.js +43 -43
- package/src/helpers/url.ts +207 -207
- package/src/helpers/urlhelper.ts +111 -111
- package/src/index.ts +6 -6
- package/src/types/auth.ts +54 -54
- package/src/types/common.types.ts +15 -15
- package/src/types/flatted.types.ts +59 -59
- package/src/types/globals.types.ts +6 -6
- package/src/types/graph/calendar.types.ts +80 -80
- package/src/types/knownscript.types.ts +18 -18
- package/src/types/libs/datajs.types.ts +28 -28
- package/src/types/libs/ics.types.ts +30 -30
- package/src/types/libs/msal.types.ts +49 -49
- package/src/types/locales.ts +124 -124
- package/src/types/localstoragecache.types.ts +8 -8
- package/src/types/location.types.ts +27 -27
- package/src/types/moment.ts +11 -11
- package/src/types/regex.types.ts +16 -16
- package/src/types/rest.types.ts +95 -95
- package/src/types/sharepoint.types.ts +1465 -1465
- package/src/types/sharepoint.utils.types.ts +287 -287
- package/src/utils/auth/common.ts +74 -74
- package/src/utils/auth/discovery.test.js +12 -12
- package/src/utils/auth/discovery.ts +132 -132
- package/src/utils/base64.ts +27 -27
- package/src/utils/consolelogger.ts +320 -320
- package/src/utils/date.ts +35 -35
- package/src/utils/emails.ts +24 -24
- package/src/utils/knownscript.ts +286 -286
- package/src/utils/localstoragecache.ts +441 -441
- package/src/utils/rest.ts +501 -501
- package/src/utils/script.ts +170 -170
- package/src/utils/sharepoint.rest/common.ts +154 -154
- package/src/utils/sharepoint.rest/date.ts +62 -62
- package/src/utils/sharepoint.rest/file.folder.ts +598 -598
- package/src/utils/sharepoint.rest/item.ts +547 -547
- package/src/utils/sharepoint.rest/list.ts +1388 -1388
- package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
- package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
- package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
- package/src/utils/sharepoint.rest/location.ts +141 -141
- package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
- package/src/utils/sharepoint.rest/user-search.ts +252 -252
- package/src/utils/sharepoint.rest/user.ts +491 -491
- package/src/utils/sharepoint.rest/web.ts +1384 -1384
- package/src/utils/sod.ts +194 -194
- package/lib/cjs/helpers/_dependencies.js +0 -21
- package/lib/cjs/helpers/_dependencies.js.map +0 -1
- package/lib/cjs/utils/_dependencies.js +0 -24
- package/lib/cjs/utils/_dependencies.js.map +0 -1
- package/lib/esm/helpers/_dependencies.js +0 -3
- package/lib/esm/helpers/_dependencies.js.map +0 -1
- package/lib/esm/utils/_dependencies.js +0 -4
- package/lib/esm/utils/_dependencies.js.map +0 -1
- package/lib/types/helpers/_dependencies.d.ts +0 -2
- package/lib/types/utils/_dependencies.d.ts +0 -3
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import assert from 'assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { ReplaceTokensInDictionary, capitalizeFirstLetter, escapeXml, maskString, replaceAll, replaceRegex } from './strings';
|
|
4
|
-
|
|
5
|
-
test('replaceAll', t => {
|
|
6
|
-
assert.strictEqual(replaceAll("hello old#@! world old#@! !", "old#@!", "new!@$"), "hello new!@$ world new!@$ !");
|
|
7
|
-
|
|
8
|
-
//this failed since the input find included protected regex characters.
|
|
9
|
-
//escapeRegExp needs to fix that
|
|
10
|
-
let string = "string with special regex[:(s:) chars";
|
|
11
|
-
let find = "regex[:(s:)";
|
|
12
|
-
let replace = "regex[~~(s~~)";
|
|
13
|
-
let result = "string with special regex[~~(s~~) chars";
|
|
14
|
-
assert.strictEqual(replaceAll(string, find, replace), result);
|
|
15
|
-
|
|
16
|
-
string = `To activate the KWIZ Forms feature in your list you should click the "KWIZ Forms Display Mode" button:
|
|
17
|
-
|
|
18
|
-

|
|
19
|
-
|
|
20
|
-
Now select one "Side Panel" or "Full Page" for the display mode:`;
|
|
21
|
-
find = "https://kwizcom.sharepoint.com/sites/Docs/CMSResources/CMS365/Screenshot 2024-06-18 123120.jpg";
|
|
22
|
-
replace = "/sites/Docs/CMSResources/CMS365/Screenshot 2024-06-18 123120.jpg";
|
|
23
|
-
result = `To activate the KWIZ Forms feature in your list you should click the "KWIZ Forms Display Mode" button:
|
|
24
|
-
|
|
25
|
-

|
|
26
|
-
|
|
27
|
-
Now select one "Side Panel" or "Full Page" for the display mode:`;
|
|
28
|
-
assert.strictEqual(replaceAll(string, find, replace, true), result);
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('capitalizeFirstLetter', async t => {
|
|
33
|
-
assert.strictEqual(capitalizeFirstLetter(), "");
|
|
34
|
-
assert.strictEqual(capitalizeFirstLetter("a"), "A");
|
|
35
|
-
assert.strictEqual(capitalizeFirstLetter("hello"), "Hello");
|
|
36
|
-
assert.strictEqual(capitalizeFirstLetter("hello world!"), "Hello world!");
|
|
37
|
-
assert.strictEqual(capitalizeFirstLetter("helloworld"), "Helloworld");
|
|
38
|
-
assert.strictEqual(capitalizeFirstLetter(""), "");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('escapeXml', async t => {
|
|
42
|
-
assert.strictEqual(escapeXml(), "");
|
|
43
|
-
assert.strictEqual(escapeXml(""), "");
|
|
44
|
-
assert.strictEqual(escapeXml(" "), " ");
|
|
45
|
-
assert.strictEqual(escapeXml("<test />"), "<test />");
|
|
46
|
-
assert.strictEqual(escapeXml(`full scope: <>&'"`), `full scope: <>&'"`);
|
|
47
|
-
assert.strictEqual(escapeXml(undefined, true), "");
|
|
48
|
-
assert.strictEqual(escapeXml("", true), "");
|
|
49
|
-
assert.strictEqual(escapeXml(" ", true), " ");
|
|
50
|
-
assert.strictEqual(escapeXml("<test />", true), "<test />");
|
|
51
|
-
assert.strictEqual(escapeXml(`full scope: <>&'"`, true), `full scope: <>&'"`);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('replaceRegex', t => {
|
|
55
|
-
/** Match anything between {zone:*} */
|
|
56
|
-
var match = /{zone:\w+}/gi;
|
|
57
|
-
|
|
58
|
-
var source = `text {zone:one} {zone:two}
|
|
59
|
-
more text
|
|
60
|
-
{zone:three}`;
|
|
61
|
-
var result = `text ONE TWO
|
|
62
|
-
more text
|
|
63
|
-
THREE`;
|
|
64
|
-
|
|
65
|
-
assert.strictEqual(replaceRegex(source, match, m => m.slice(1, m.length - 1).split(':')[1].toLocaleUpperCase()), result);
|
|
66
|
-
|
|
67
|
-
/** match: "](______)" */
|
|
68
|
-
match = /]\(.+\)/gi;
|
|
69
|
-
source = '[name:root](https://kwizcom.sharepoint.com/:fl:/g/contentstorage)';
|
|
70
|
-
result = '[name:root](https~~~~//kwizcom.sharepoint.com/~~~~fl~~~~/g/contentstorage)';
|
|
71
|
-
assert.strictEqual(replaceRegex(source, match, m => m.replace(/:/gi, "~~~~")), result);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('maskString', async t => {
|
|
75
|
-
assert.strictEqual(maskString("abcdefg"), "ab*****fg");
|
|
76
|
-
assert.strictEqual(maskString("ab"), "ab*****ab");
|
|
77
|
-
assert.strictEqual(maskString(""), "*****");
|
|
78
|
-
assert.strictEqual(maskString("abcdefg", { mask: "..." }), "ab...fg");
|
|
79
|
-
assert.strictEqual(maskString("abcdefg", { mask: "...", start: 0, end: 0 }), "...");
|
|
80
|
-
assert.strictEqual(maskString("abcdefg", { mask: "...", start: 1, end: 1 }), "a...g");
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('ReplaceTokensInDictionary', async t => {
|
|
84
|
-
const tokens = { "t1": "token1", "t2": "token 2" };
|
|
85
|
-
let dic = {};
|
|
86
|
-
let expected = {};
|
|
87
|
-
|
|
88
|
-
dic = { a: "hello" };
|
|
89
|
-
expected = { a: "hello" };
|
|
90
|
-
ReplaceTokensInDictionary(dic, tokens);
|
|
91
|
-
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
92
|
-
|
|
93
|
-
dic = { a: "hello", b: "hello [t1]" };
|
|
94
|
-
expected = { a: "hello", b: "hello token1" };
|
|
95
|
-
ReplaceTokensInDictionary(dic, tokens);
|
|
96
|
-
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
97
|
-
|
|
98
|
-
dic = { a: "hello", b: "hello [t1] [t2]", c: "[t2]" };
|
|
99
|
-
expected = { a: "hello", b: "hello token1 token 2", c: "token 2" };
|
|
100
|
-
ReplaceTokensInDictionary(dic, tokens);
|
|
101
|
-
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
1
|
+
import assert from 'assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import { ReplaceTokensInDictionary, capitalizeFirstLetter, escapeXml, maskString, replaceAll, replaceRegex } from './strings';
|
|
4
|
+
|
|
5
|
+
test('replaceAll', t => {
|
|
6
|
+
assert.strictEqual(replaceAll("hello old#@! world old#@! !", "old#@!", "new!@$"), "hello new!@$ world new!@$ !");
|
|
7
|
+
|
|
8
|
+
//this failed since the input find included protected regex characters.
|
|
9
|
+
//escapeRegExp needs to fix that
|
|
10
|
+
let string = "string with special regex[:(s:) chars";
|
|
11
|
+
let find = "regex[:(s:)";
|
|
12
|
+
let replace = "regex[~~(s~~)";
|
|
13
|
+
let result = "string with special regex[~~(s~~) chars";
|
|
14
|
+
assert.strictEqual(replaceAll(string, find, replace), result);
|
|
15
|
+
|
|
16
|
+
string = `To activate the KWIZ Forms feature in your list you should click the "KWIZ Forms Display Mode" button:
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
Now select one "Side Panel" or "Full Page" for the display mode:`;
|
|
21
|
+
find = "https://kwizcom.sharepoint.com/sites/Docs/CMSResources/CMS365/Screenshot 2024-06-18 123120.jpg";
|
|
22
|
+
replace = "/sites/Docs/CMSResources/CMS365/Screenshot 2024-06-18 123120.jpg";
|
|
23
|
+
result = `To activate the KWIZ Forms feature in your list you should click the "KWIZ Forms Display Mode" button:
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
Now select one "Side Panel" or "Full Page" for the display mode:`;
|
|
28
|
+
assert.strictEqual(replaceAll(string, find, replace, true), result);
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('capitalizeFirstLetter', async t => {
|
|
33
|
+
assert.strictEqual(capitalizeFirstLetter(), "");
|
|
34
|
+
assert.strictEqual(capitalizeFirstLetter("a"), "A");
|
|
35
|
+
assert.strictEqual(capitalizeFirstLetter("hello"), "Hello");
|
|
36
|
+
assert.strictEqual(capitalizeFirstLetter("hello world!"), "Hello world!");
|
|
37
|
+
assert.strictEqual(capitalizeFirstLetter("helloworld"), "Helloworld");
|
|
38
|
+
assert.strictEqual(capitalizeFirstLetter(""), "");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('escapeXml', async t => {
|
|
42
|
+
assert.strictEqual(escapeXml(), "");
|
|
43
|
+
assert.strictEqual(escapeXml(""), "");
|
|
44
|
+
assert.strictEqual(escapeXml(" "), " ");
|
|
45
|
+
assert.strictEqual(escapeXml("<test />"), "<test />");
|
|
46
|
+
assert.strictEqual(escapeXml(`full scope: <>&'"`), `full scope: <>&'"`);
|
|
47
|
+
assert.strictEqual(escapeXml(undefined, true), "");
|
|
48
|
+
assert.strictEqual(escapeXml("", true), "");
|
|
49
|
+
assert.strictEqual(escapeXml(" ", true), " ");
|
|
50
|
+
assert.strictEqual(escapeXml("<test />", true), "<test />");
|
|
51
|
+
assert.strictEqual(escapeXml(`full scope: <>&'"`, true), `full scope: <>&'"`);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('replaceRegex', t => {
|
|
55
|
+
/** Match anything between {zone:*} */
|
|
56
|
+
var match = /{zone:\w+}/gi;
|
|
57
|
+
|
|
58
|
+
var source = `text {zone:one} {zone:two}
|
|
59
|
+
more text
|
|
60
|
+
{zone:three}`;
|
|
61
|
+
var result = `text ONE TWO
|
|
62
|
+
more text
|
|
63
|
+
THREE`;
|
|
64
|
+
|
|
65
|
+
assert.strictEqual(replaceRegex(source, match, m => m.slice(1, m.length - 1).split(':')[1].toLocaleUpperCase()), result);
|
|
66
|
+
|
|
67
|
+
/** match: "](______)" */
|
|
68
|
+
match = /]\(.+\)/gi;
|
|
69
|
+
source = '[name:root](https://kwizcom.sharepoint.com/:fl:/g/contentstorage)';
|
|
70
|
+
result = '[name:root](https~~~~//kwizcom.sharepoint.com/~~~~fl~~~~/g/contentstorage)';
|
|
71
|
+
assert.strictEqual(replaceRegex(source, match, m => m.replace(/:/gi, "~~~~")), result);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('maskString', async t => {
|
|
75
|
+
assert.strictEqual(maskString("abcdefg"), "ab*****fg");
|
|
76
|
+
assert.strictEqual(maskString("ab"), "ab*****ab");
|
|
77
|
+
assert.strictEqual(maskString(""), "*****");
|
|
78
|
+
assert.strictEqual(maskString("abcdefg", { mask: "..." }), "ab...fg");
|
|
79
|
+
assert.strictEqual(maskString("abcdefg", { mask: "...", start: 0, end: 0 }), "...");
|
|
80
|
+
assert.strictEqual(maskString("abcdefg", { mask: "...", start: 1, end: 1 }), "a...g");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('ReplaceTokensInDictionary', async t => {
|
|
84
|
+
const tokens = { "t1": "token1", "t2": "token 2" };
|
|
85
|
+
let dic = {};
|
|
86
|
+
let expected = {};
|
|
87
|
+
|
|
88
|
+
dic = { a: "hello" };
|
|
89
|
+
expected = { a: "hello" };
|
|
90
|
+
ReplaceTokensInDictionary(dic, tokens);
|
|
91
|
+
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
92
|
+
|
|
93
|
+
dic = { a: "hello", b: "hello [t1]" };
|
|
94
|
+
expected = { a: "hello", b: "hello token1" };
|
|
95
|
+
ReplaceTokensInDictionary(dic, tokens);
|
|
96
|
+
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
97
|
+
|
|
98
|
+
dic = { a: "hello", b: "hello [t1] [t2]", c: "[t2]" };
|
|
99
|
+
expected = { a: "hello", b: "hello token1 token 2", c: "token 2" };
|
|
100
|
+
ReplaceTokensInDictionary(dic, tokens);
|
|
101
|
+
assert.strictEqual(JSON.stringify(dic), JSON.stringify(expected));
|
|
102
102
|
});
|