@kwiz/common 1.0.129 → 1.0.132

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 (100) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/LICENSE +21 -21
  3. package/lib/cjs/config.js +2 -0
  4. package/lib/cjs/config.js.map +1 -1
  5. package/lib/cjs/types/libs/msal.types.js +26 -26
  6. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  7. package/lib/esm/config.js +2 -0
  8. package/lib/esm/config.js.map +1 -1
  9. package/lib/esm/types/libs/msal.types.js +26 -26
  10. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  11. package/lib/types/config.d.ts +2 -0
  12. package/package.json +81 -81
  13. package/readme.md +17 -17
  14. package/src/_dependencies.ts +12 -12
  15. package/src/config.ts +19 -17
  16. package/src/helpers/Guid.ts +181 -181
  17. package/src/helpers/base64.ts +173 -173
  18. package/src/helpers/browser.test.js +13 -13
  19. package/src/helpers/browser.ts +1504 -1504
  20. package/src/helpers/browserinfo.ts +292 -292
  21. package/src/helpers/collections.base.test.js +25 -25
  22. package/src/helpers/collections.base.ts +437 -437
  23. package/src/helpers/collections.ts +107 -107
  24. package/src/helpers/color.ts +54 -54
  25. package/src/helpers/cookies.ts +59 -59
  26. package/src/helpers/date.test.js +119 -119
  27. package/src/helpers/date.ts +188 -188
  28. package/src/helpers/debug.ts +186 -186
  29. package/src/helpers/diagrams.ts +43 -43
  30. package/src/helpers/emails.ts +6 -6
  31. package/src/helpers/eval.ts +5 -5
  32. package/src/helpers/file.test.js +50 -50
  33. package/src/helpers/file.ts +63 -63
  34. package/src/helpers/flatted.ts +149 -149
  35. package/src/helpers/functions.ts +16 -16
  36. package/src/helpers/graph/calendar.types.ts +10 -10
  37. package/src/helpers/http.ts +69 -69
  38. package/src/helpers/images.ts +22 -22
  39. package/src/helpers/json.ts +44 -44
  40. package/src/helpers/md5.ts +189 -189
  41. package/src/helpers/objects.test.js +33 -33
  42. package/src/helpers/objects.ts +274 -274
  43. package/src/helpers/promises.test.js +37 -37
  44. package/src/helpers/promises.ts +165 -165
  45. package/src/helpers/random.ts +27 -27
  46. package/src/helpers/scheduler/scheduler.test.js +103 -103
  47. package/src/helpers/scheduler/scheduler.ts +131 -131
  48. package/src/helpers/sharepoint.ts +796 -796
  49. package/src/helpers/strings.test.js +122 -122
  50. package/src/helpers/strings.ts +337 -337
  51. package/src/helpers/typecheckers.test.js +34 -34
  52. package/src/helpers/typecheckers.ts +266 -266
  53. package/src/helpers/url.test.js +43 -43
  54. package/src/helpers/url.ts +207 -207
  55. package/src/helpers/urlhelper.ts +111 -111
  56. package/src/index.ts +6 -6
  57. package/src/types/auth.ts +62 -62
  58. package/src/types/common.types.ts +15 -15
  59. package/src/types/flatted.types.ts +59 -59
  60. package/src/types/globals.types.ts +6 -6
  61. package/src/types/graph/calendar.types.ts +80 -80
  62. package/src/types/knownscript.types.ts +18 -18
  63. package/src/types/libs/datajs.types.ts +28 -28
  64. package/src/types/libs/ics.types.ts +30 -30
  65. package/src/types/libs/msal.types.ts +57 -57
  66. package/src/types/locales.ts +125 -125
  67. package/src/types/localstoragecache.types.ts +8 -8
  68. package/src/types/location.types.ts +27 -27
  69. package/src/types/moment.ts +11 -11
  70. package/src/types/regex.types.ts +16 -16
  71. package/src/types/rest.types.ts +95 -95
  72. package/src/types/sharepoint.types.ts +1466 -1466
  73. package/src/types/sharepoint.utils.types.ts +306 -306
  74. package/src/utils/auth/common.ts +118 -118
  75. package/src/utils/auth/discovery.test.js +12 -12
  76. package/src/utils/auth/discovery.ts +132 -132
  77. package/src/utils/base64.ts +27 -27
  78. package/src/utils/consolelogger.ts +333 -333
  79. package/src/utils/date.ts +172 -172
  80. package/src/utils/emails.ts +24 -24
  81. package/src/utils/knownscript.ts +286 -286
  82. package/src/utils/localstoragecache.ts +446 -446
  83. package/src/utils/rest.ts +501 -501
  84. package/src/utils/script.ts +170 -170
  85. package/src/utils/sharepoint.rest/common.ts +159 -159
  86. package/src/utils/sharepoint.rest/date.ts +62 -62
  87. package/src/utils/sharepoint.rest/file.folder.ts +685 -685
  88. package/src/utils/sharepoint.rest/item.ts +547 -547
  89. package/src/utils/sharepoint.rest/list.ts +1572 -1572
  90. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  91. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  92. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  93. package/src/utils/sharepoint.rest/location.ts +141 -141
  94. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  95. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  96. package/src/utils/sharepoint.rest/user.ts +558 -558
  97. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  98. package/src/utils/sod.ts +194 -194
  99. package/.madgerc +0 -3
  100. package/fix-folder-imports.js +0 -27
@@ -1,64 +1,64 @@
1
- import { escapeRegExp } from "./strings";
2
-
3
- //https://support.microsoft.com/en-gb/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa
4
- //These names aren't allowed for files or folders: .lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_,
5
- //desktop.ini, any filename starting with ~$. "_vti_" can't appear anywhere in a file name.
6
-
7
- export const ImageFileTypes = ["png", "jpg", "jpeg", "gif", "bmp", "svg", "webp"];
8
- export const DocumentFileTypes = ["docx", "doc", "pdf", "txt", "rtf", "odt"];
9
- export const VideoFileTypes = ["mp4", "mov", "wmv", "avi", "mkv", "flv", "webm"];
10
- export const OfficeFileTypes = ["docx", "doc", "xlsx", "xls", "pptx", "ppt", "csv"];
11
-
12
- function _getRegexCollection() {
13
- return {
14
- IllegalCharsRegex: new RegExp("[" + escapeRegExp(`"*:<>?/\\|`) + "]", "gi"),
15
- IllegalCharsExtraRegex: new RegExp("[" + escapeRegExp(`~"#%&*:<>?/\\|`) + "]", "gi"),
16
- IllegalNamesRegex: /^(\.lock|CON|PRN|AUX|NUL|COM\d|LPT\d|.*_VTI_.*|~\$.*)$/gi,
17
- IsDesktopIni: /^desktop\.ini$/gi
18
- };
19
- }
20
-
21
- export function validateFilename(fileNameWithExtension: string) {
22
- let filenameWithOutExtension = fileNameWithExtension;
23
- let split = filenameWithOutExtension.split(".");
24
- split.pop();
25
- filenameWithOutExtension = split.join(".");
26
-
27
- let regexCollection = _getRegexCollection();
28
-
29
- let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(filenameWithOutExtension);
30
- let hasIllegalName = regexCollection.IllegalNamesRegex.test(filenameWithOutExtension) || regexCollection.IsDesktopIni.test(fileNameWithExtension);
31
-
32
- return {
33
- hasIllegalCharacter,
34
- hasIllegalName,
35
- valid: !hasIllegalCharacter && !hasIllegalName
36
- };
37
- }
38
-
39
- export function validateFoldername(folderName: string) {
40
- let regexCollection = _getRegexCollection();
41
-
42
- let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(folderName);
43
- let hasIllegalName = regexCollection.IllegalNamesRegex.test(folderName) || regexCollection.IsDesktopIni.test(folderName);
44
-
45
- return {
46
- hasIllegalCharacter,
47
- hasIllegalName,
48
- valid: !hasIllegalCharacter && !hasIllegalName
49
- };
50
- }
51
-
52
- export function validateAndSetFilename(fileNameWithExtension: string) {
53
- let regexCollection = _getRegexCollection();
54
-
55
- let validateFilenameChk = validateFilename(fileNameWithExtension);
56
- if (!validateFilenameChk.valid || regexCollection.IllegalCharsExtraRegex.test(fileNameWithExtension)) {
57
- fileNameWithExtension =
58
- fileNameWithExtension.replace(regexCollection.IllegalCharsRegex, "")
59
- .replace(regexCollection.IllegalCharsExtraRegex, "")
60
- .replace(regexCollection.IllegalNamesRegex, "")
61
- .replace(regexCollection.IsDesktopIni, "");
62
- }
63
- return fileNameWithExtension;
1
+ import { escapeRegExp } from "./strings";
2
+
3
+ //https://support.microsoft.com/en-gb/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa
4
+ //These names aren't allowed for files or folders: .lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_,
5
+ //desktop.ini, any filename starting with ~$. "_vti_" can't appear anywhere in a file name.
6
+
7
+ export const ImageFileTypes = ["png", "jpg", "jpeg", "gif", "bmp", "svg", "webp"];
8
+ export const DocumentFileTypes = ["docx", "doc", "pdf", "txt", "rtf", "odt"];
9
+ export const VideoFileTypes = ["mp4", "mov", "wmv", "avi", "mkv", "flv", "webm"];
10
+ export const OfficeFileTypes = ["docx", "doc", "xlsx", "xls", "pptx", "ppt", "csv"];
11
+
12
+ function _getRegexCollection() {
13
+ return {
14
+ IllegalCharsRegex: new RegExp("[" + escapeRegExp(`"*:<>?/\\|`) + "]", "gi"),
15
+ IllegalCharsExtraRegex: new RegExp("[" + escapeRegExp(`~"#%&*:<>?/\\|`) + "]", "gi"),
16
+ IllegalNamesRegex: /^(\.lock|CON|PRN|AUX|NUL|COM\d|LPT\d|.*_VTI_.*|~\$.*)$/gi,
17
+ IsDesktopIni: /^desktop\.ini$/gi
18
+ };
19
+ }
20
+
21
+ export function validateFilename(fileNameWithExtension: string) {
22
+ let filenameWithOutExtension = fileNameWithExtension;
23
+ let split = filenameWithOutExtension.split(".");
24
+ split.pop();
25
+ filenameWithOutExtension = split.join(".");
26
+
27
+ let regexCollection = _getRegexCollection();
28
+
29
+ let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(filenameWithOutExtension);
30
+ let hasIllegalName = regexCollection.IllegalNamesRegex.test(filenameWithOutExtension) || regexCollection.IsDesktopIni.test(fileNameWithExtension);
31
+
32
+ return {
33
+ hasIllegalCharacter,
34
+ hasIllegalName,
35
+ valid: !hasIllegalCharacter && !hasIllegalName
36
+ };
37
+ }
38
+
39
+ export function validateFoldername(folderName: string) {
40
+ let regexCollection = _getRegexCollection();
41
+
42
+ let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(folderName);
43
+ let hasIllegalName = regexCollection.IllegalNamesRegex.test(folderName) || regexCollection.IsDesktopIni.test(folderName);
44
+
45
+ return {
46
+ hasIllegalCharacter,
47
+ hasIllegalName,
48
+ valid: !hasIllegalCharacter && !hasIllegalName
49
+ };
50
+ }
51
+
52
+ export function validateAndSetFilename(fileNameWithExtension: string) {
53
+ let regexCollection = _getRegexCollection();
54
+
55
+ let validateFilenameChk = validateFilename(fileNameWithExtension);
56
+ if (!validateFilenameChk.valid || regexCollection.IllegalCharsExtraRegex.test(fileNameWithExtension)) {
57
+ fileNameWithExtension =
58
+ fileNameWithExtension.replace(regexCollection.IllegalCharsRegex, "")
59
+ .replace(regexCollection.IllegalCharsExtraRegex, "")
60
+ .replace(regexCollection.IllegalNamesRegex, "")
61
+ .replace(regexCollection.IsDesktopIni, "");
62
+ }
63
+ return fileNameWithExtension;
64
64
  }
@@ -1,150 +1,150 @@
1
- /* eslint-disable */
2
-
3
- /*! (c) 2020 Andrea Giammarchi */
4
-
5
- import { IFlatted } from "../types/flatted.types";
6
- import { isNullOrEmptyArray } from "./typecheckers";
7
-
8
- /** Version 3.2.9 */
9
- /**
10
- * Fast and minimal circular JSON parser.
11
- * logic example
12
- ```js
13
- var a = [{one: 1}, {two: '2'}];
14
- a[0].a = a;
15
- // a is the main object, will be at index '0'
16
- // {one: 1} is the second object, index '1'
17
- // {two: '2'} the third, in '2', and it has a string
18
- // which will be found at index '3'
19
- Flatted.stringify(a);
20
- // [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
21
- // a[one,two] {one: 1, a} {two: '2'} '2'
22
- ```
23
- */
24
- const { parse: $parse, stringify: $stringify } = JSON;
25
- const { keys } = Object;
26
-
27
- const Primitive = String; // it could be Number
28
- const primitive = 'string'; // it could be 'number'
29
-
30
- const ignore = {};
31
- const object = 'object';
32
-
33
- const noop = (_, value) => value;
34
-
35
- const primitives = value => (
36
- value instanceof Primitive ? Primitive(value) : value
37
- );
38
-
39
- const Primitives = (_, value) => (
40
- typeof value === primitive ? new Primitive(value) : value
41
- );
42
-
43
- const revive = (input, parsed, output, $) => {
44
- const lazy = [];
45
- for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
46
- const k = ke[y];
47
- const value = output[k];
48
- if (value instanceof Primitive) {
49
- const tmp = input[value as string];
50
- if (typeof tmp === object && !parsed.has(tmp)) {
51
- parsed.add(tmp);
52
- output[k] = ignore;
53
- lazy.push({ k, a: [input, parsed, tmp, $] });
54
- }
55
- else
56
- output[k] = $.call(output, k, tmp);
57
- }
58
- else if (output[k] !== ignore)
59
- output[k] = $.call(output, k, value);
60
- }
61
- for (let { length } = lazy, i = 0; i < length; i++) {
62
- const { k, a } = lazy[i];
63
- output[k] = $.call(output, k, revive.apply(null, a));
64
- }
65
- return output;
66
- };
67
-
68
- const set = (known, input, value) => {
69
- const index = Primitive(input.push(value) - 1);
70
- known.set(value, index);
71
- return index;
72
- };
73
-
74
- const parse = (text, reviver?) => {
75
- const input = $parse(text, Primitives).map(primitives);
76
- const value = input[0];
77
- const $ = reviver || noop;
78
- const tmp = typeof value === object && value ?
79
- revive(input, new Set, value, $) :
80
- value;
81
- return $.call({ '': tmp }, '', tmp);
82
- };
83
- //exports.parse = parse;
84
-
85
- const stringify = (value, replacer?, space?) => {
86
- const $ = replacer && typeof replacer === object ?
87
- (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
88
- (replacer || noop);
89
- const known = new Map;
90
- const input = [];
91
- const output = [];
92
- let i = +set(known, input, $.call({ '': value }, '', value));
93
- let firstRun = !i;
94
- while (i < input.length) {
95
- firstRun = true;
96
- output[i] = $stringify(input[i++], replace, space);
97
- }
98
- return '[' + output.join(',') + ']';
99
- function replace(key, value) {
100
- if (firstRun) {
101
- firstRun = !firstRun;
102
- return value;
103
- }
104
- const after = $.call(this, key, value);
105
- switch (typeof after) {
106
- case object:
107
- if (after === null) return after;
108
- return known.get(after) || set(known, input, after);
109
- case primitive:
110
- return known.get(after) || set(known, input, after);
111
- }
112
- return after;
113
- }
114
- };
115
- //exports.stringify = stringify;
116
-
117
- const toJSON = any => $parse(stringify(any));
118
- //exports.toJSON = toJSON;
119
- const fromJSON = any => parse($stringify(any));
120
- //exports.fromJSON = fromJSON;
121
-
122
-
123
- /*! (c) 2020 Andrea Giammarchi */
124
- /**
125
- * Fast and minimal circular JSON parser.
126
- * logic example
127
- ```js
128
- var a = [{one: 1}, {two: '2'}];
129
- a[0].a = a;
130
- // a is the main object, will be at index '0'
131
- // {one: 1} is the second object, index '1'
132
- // {two: '2'} the third, in '2', and it has a string
133
- // which will be found at index '3'
134
- Flatted.stringify(a);
135
- // [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
136
- // a[one,two] {one: 1, a} {two: '2'} '2'
137
- ```
138
- */
139
- export var flatted: IFlatted = {
140
- toJSON: toJSON,
141
- fromJSON: fromJSON,
142
- stringify: stringify,
143
- parse: parse
144
- };
145
-
146
- export function flattedClone<T>(obj: T): T {
147
- if (isNullOrEmptyArray(obj)) return obj;
148
- //json clone won't work on circular object. must use flatted.
149
- return flatted.parse(flatted.stringify(obj));
1
+ /* eslint-disable */
2
+
3
+ /*! (c) 2020 Andrea Giammarchi */
4
+
5
+ import { IFlatted } from "../types/flatted.types";
6
+ import { isNullOrEmptyArray } from "./typecheckers";
7
+
8
+ /** Version 3.2.9 */
9
+ /**
10
+ * Fast and minimal circular JSON parser.
11
+ * logic example
12
+ ```js
13
+ var a = [{one: 1}, {two: '2'}];
14
+ a[0].a = a;
15
+ // a is the main object, will be at index '0'
16
+ // {one: 1} is the second object, index '1'
17
+ // {two: '2'} the third, in '2', and it has a string
18
+ // which will be found at index '3'
19
+ Flatted.stringify(a);
20
+ // [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
21
+ // a[one,two] {one: 1, a} {two: '2'} '2'
22
+ ```
23
+ */
24
+ const { parse: $parse, stringify: $stringify } = JSON;
25
+ const { keys } = Object;
26
+
27
+ const Primitive = String; // it could be Number
28
+ const primitive = 'string'; // it could be 'number'
29
+
30
+ const ignore = {};
31
+ const object = 'object';
32
+
33
+ const noop = (_, value) => value;
34
+
35
+ const primitives = value => (
36
+ value instanceof Primitive ? Primitive(value) : value
37
+ );
38
+
39
+ const Primitives = (_, value) => (
40
+ typeof value === primitive ? new Primitive(value) : value
41
+ );
42
+
43
+ const revive = (input, parsed, output, $) => {
44
+ const lazy = [];
45
+ for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
46
+ const k = ke[y];
47
+ const value = output[k];
48
+ if (value instanceof Primitive) {
49
+ const tmp = input[value as string];
50
+ if (typeof tmp === object && !parsed.has(tmp)) {
51
+ parsed.add(tmp);
52
+ output[k] = ignore;
53
+ lazy.push({ k, a: [input, parsed, tmp, $] });
54
+ }
55
+ else
56
+ output[k] = $.call(output, k, tmp);
57
+ }
58
+ else if (output[k] !== ignore)
59
+ output[k] = $.call(output, k, value);
60
+ }
61
+ for (let { length } = lazy, i = 0; i < length; i++) {
62
+ const { k, a } = lazy[i];
63
+ output[k] = $.call(output, k, revive.apply(null, a));
64
+ }
65
+ return output;
66
+ };
67
+
68
+ const set = (known, input, value) => {
69
+ const index = Primitive(input.push(value) - 1);
70
+ known.set(value, index);
71
+ return index;
72
+ };
73
+
74
+ const parse = (text, reviver?) => {
75
+ const input = $parse(text, Primitives).map(primitives);
76
+ const value = input[0];
77
+ const $ = reviver || noop;
78
+ const tmp = typeof value === object && value ?
79
+ revive(input, new Set, value, $) :
80
+ value;
81
+ return $.call({ '': tmp }, '', tmp);
82
+ };
83
+ //exports.parse = parse;
84
+
85
+ const stringify = (value, replacer?, space?) => {
86
+ const $ = replacer && typeof replacer === object ?
87
+ (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
88
+ (replacer || noop);
89
+ const known = new Map;
90
+ const input = [];
91
+ const output = [];
92
+ let i = +set(known, input, $.call({ '': value }, '', value));
93
+ let firstRun = !i;
94
+ while (i < input.length) {
95
+ firstRun = true;
96
+ output[i] = $stringify(input[i++], replace, space);
97
+ }
98
+ return '[' + output.join(',') + ']';
99
+ function replace(key, value) {
100
+ if (firstRun) {
101
+ firstRun = !firstRun;
102
+ return value;
103
+ }
104
+ const after = $.call(this, key, value);
105
+ switch (typeof after) {
106
+ case object:
107
+ if (after === null) return after;
108
+ return known.get(after) || set(known, input, after);
109
+ case primitive:
110
+ return known.get(after) || set(known, input, after);
111
+ }
112
+ return after;
113
+ }
114
+ };
115
+ //exports.stringify = stringify;
116
+
117
+ const toJSON = any => $parse(stringify(any));
118
+ //exports.toJSON = toJSON;
119
+ const fromJSON = any => parse($stringify(any));
120
+ //exports.fromJSON = fromJSON;
121
+
122
+
123
+ /*! (c) 2020 Andrea Giammarchi */
124
+ /**
125
+ * Fast and minimal circular JSON parser.
126
+ * logic example
127
+ ```js
128
+ var a = [{one: 1}, {two: '2'}];
129
+ a[0].a = a;
130
+ // a is the main object, will be at index '0'
131
+ // {one: 1} is the second object, index '1'
132
+ // {two: '2'} the third, in '2', and it has a string
133
+ // which will be found at index '3'
134
+ Flatted.stringify(a);
135
+ // [["1","2"],{"one":1,"a":"0"},{"two":"3"},"2"]
136
+ // a[one,two] {one: 1, a} {two: '2'} '2'
137
+ ```
138
+ */
139
+ export var flatted: IFlatted = {
140
+ toJSON: toJSON,
141
+ fromJSON: fromJSON,
142
+ stringify: stringify,
143
+ parse: parse
144
+ };
145
+
146
+ export function flattedClone<T>(obj: T): T {
147
+ if (isNullOrEmptyArray(obj)) return obj;
148
+ //json clone won't work on circular object. must use flatted.
149
+ return flatted.parse(flatted.stringify(obj));
150
150
  }
@@ -1,17 +1,17 @@
1
- import { isFunction } from "./typecheckers";
2
-
3
- export function wrapFunction<ValueType, ReturnType>(f: (value: ValueType) => ReturnType, props: {
4
- before?: (value: ValueType) => ValueType;
5
- after?: (value: ValueType, returned: ReturnType) => void;
6
- }) {
7
- return (v: ValueType) => {
8
- if (isFunction(props.before)) {
9
- v = props.before(v);
10
- }
11
- let result = f(v);
12
- if (isFunction(props.after))
13
- props.after(v, result);
14
-
15
- return result;
16
- };
1
+ import { isFunction } from "./typecheckers";
2
+
3
+ export function wrapFunction<ValueType, ReturnType>(f: (value: ValueType) => ReturnType, props: {
4
+ before?: (value: ValueType) => ValueType;
5
+ after?: (value: ValueType, returned: ReturnType) => void;
6
+ }) {
7
+ return (v: ValueType) => {
8
+ if (isFunction(props.before)) {
9
+ v = props.before(v);
10
+ }
11
+ let result = f(v);
12
+ if (isFunction(props.after))
13
+ props.after(v, result);
14
+
15
+ return result;
16
+ };
17
17
  }
@@ -1,11 +1,11 @@
1
- import { IGraphEventAttendee, IGraphEventUser } from "../../types/graph/calendar.types";
2
- import { isNullOrEmptyString } from "../typecheckers";
3
-
4
- export function IsGraphEventUser(obj: any): obj is IGraphEventUser {
5
- let asEA = obj as IGraphEventUser;
6
- return asEA && asEA.emailAddress && !isNullOrEmptyString(asEA.emailAddress.address);
7
- }
8
- export function IsGraphEventAttendee(obj: any): obj is IGraphEventAttendee {
9
- let asEA = obj as IGraphEventAttendee;
10
- return IsGraphEventUser(obj) && asEA.status && !isNullOrEmptyString(asEA.type);
1
+ import { IGraphEventAttendee, IGraphEventUser } from "../../types/graph/calendar.types";
2
+ import { isNullOrEmptyString } from "../typecheckers";
3
+
4
+ export function IsGraphEventUser(obj: any): obj is IGraphEventUser {
5
+ let asEA = obj as IGraphEventUser;
6
+ return asEA && asEA.emailAddress && !isNullOrEmptyString(asEA.emailAddress.address);
7
+ }
8
+ export function IsGraphEventAttendee(obj: any): obj is IGraphEventAttendee {
9
+ let asEA = obj as IGraphEventAttendee;
10
+ return IsGraphEventUser(obj) && asEA.status && !isNullOrEmptyString(asEA.type);
11
11
  }
@@ -1,70 +1,70 @@
1
- import { objectValues } from "./objects";
2
- import { isNullOrUndefined } from "./typecheckers";
3
-
4
- // eslint-disable-next-line no-shadow
5
- export enum CommonHttpHeaderNames {
6
- Accept = "Accept",
7
- Authorization = "Authorization",
8
- ContentType = "content-type",
9
- XHTTPMethod = "X-HTTP-Method",
10
- XRapidApiHost = "x-rapidapi-host",
11
- XRapidApiKey = "x-rapidapi-key"
12
- }
13
-
14
- // eslint-disable-next-line no-shadow
15
- enum AcceptOrContentTypeHeaderValues {
16
- JsonVerbose = "application/json; odata=verbose",
17
- JsonMinimal = "application/json; odata=minimal",
18
- JsonNometadata = "application/json; odata=nometadata"
19
- }
20
-
21
- // eslint-disable-next-line no-shadow
22
- enum AuthorizationHeaderValues {
23
- Bearer = "Bearer [token]",
24
- Basic = "Basic [user]:[password]"
25
- }
26
-
27
- // eslint-disable-next-line no-shadow
28
- enum XHttpMethodHeaderValues {
29
- MERGE = "MERGE",
30
- DELETE = "DELETE",
31
- PUT = "PUT"
32
- }
33
-
34
- export function GetCommonHeaderNames() {
35
- return objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames);
36
- }
37
-
38
- export function GetCommonHeaderValueSuggestions(headerName: CommonHttpHeaderNames | string) {
39
- if (isNullOrUndefined(headerName)) {
40
- return [];
41
- }
42
-
43
- let parsedHeaderName = _getValueByKeyForStringEnum(headerName);
44
-
45
- if (isNullOrUndefined(parsedHeaderName)) {
46
- return [];
47
- }
48
-
49
- switch (parsedHeaderName) {
50
- case CommonHttpHeaderNames.Accept:
51
- case CommonHttpHeaderNames.ContentType:
52
- return objectValues<AcceptOrContentTypeHeaderValues>(AcceptOrContentTypeHeaderValues);
53
- case CommonHttpHeaderNames.Authorization:
54
- return objectValues<AuthorizationHeaderValues>(AuthorizationHeaderValues);
55
- case CommonHttpHeaderNames.XHTTPMethod:
56
- return objectValues<XHttpMethodHeaderValues>(XHttpMethodHeaderValues);
57
- default:
58
- return [];
59
- }
60
- }
61
-
62
- function _getValueByKeyForStringEnum(keyOrValue: string | CommonHttpHeaderNames) {
63
- let found = objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames).filter((value) => {
64
- return value === keyOrValue;
65
- })[0];
66
- if (isNullOrUndefined(found)) {
67
- found = CommonHttpHeaderNames[keyOrValue as keyof typeof CommonHttpHeaderNames];
68
- }
69
- return found;
1
+ import { objectValues } from "./objects";
2
+ import { isNullOrUndefined } from "./typecheckers";
3
+
4
+ // eslint-disable-next-line no-shadow
5
+ export enum CommonHttpHeaderNames {
6
+ Accept = "Accept",
7
+ Authorization = "Authorization",
8
+ ContentType = "content-type",
9
+ XHTTPMethod = "X-HTTP-Method",
10
+ XRapidApiHost = "x-rapidapi-host",
11
+ XRapidApiKey = "x-rapidapi-key"
12
+ }
13
+
14
+ // eslint-disable-next-line no-shadow
15
+ enum AcceptOrContentTypeHeaderValues {
16
+ JsonVerbose = "application/json; odata=verbose",
17
+ JsonMinimal = "application/json; odata=minimal",
18
+ JsonNometadata = "application/json; odata=nometadata"
19
+ }
20
+
21
+ // eslint-disable-next-line no-shadow
22
+ enum AuthorizationHeaderValues {
23
+ Bearer = "Bearer [token]",
24
+ Basic = "Basic [user]:[password]"
25
+ }
26
+
27
+ // eslint-disable-next-line no-shadow
28
+ enum XHttpMethodHeaderValues {
29
+ MERGE = "MERGE",
30
+ DELETE = "DELETE",
31
+ PUT = "PUT"
32
+ }
33
+
34
+ export function GetCommonHeaderNames() {
35
+ return objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames);
36
+ }
37
+
38
+ export function GetCommonHeaderValueSuggestions(headerName: CommonHttpHeaderNames | string) {
39
+ if (isNullOrUndefined(headerName)) {
40
+ return [];
41
+ }
42
+
43
+ let parsedHeaderName = _getValueByKeyForStringEnum(headerName);
44
+
45
+ if (isNullOrUndefined(parsedHeaderName)) {
46
+ return [];
47
+ }
48
+
49
+ switch (parsedHeaderName) {
50
+ case CommonHttpHeaderNames.Accept:
51
+ case CommonHttpHeaderNames.ContentType:
52
+ return objectValues<AcceptOrContentTypeHeaderValues>(AcceptOrContentTypeHeaderValues);
53
+ case CommonHttpHeaderNames.Authorization:
54
+ return objectValues<AuthorizationHeaderValues>(AuthorizationHeaderValues);
55
+ case CommonHttpHeaderNames.XHTTPMethod:
56
+ return objectValues<XHttpMethodHeaderValues>(XHttpMethodHeaderValues);
57
+ default:
58
+ return [];
59
+ }
60
+ }
61
+
62
+ function _getValueByKeyForStringEnum(keyOrValue: string | CommonHttpHeaderNames) {
63
+ let found = objectValues<CommonHttpHeaderNames>(CommonHttpHeaderNames).filter((value) => {
64
+ return value === keyOrValue;
65
+ })[0];
66
+ if (isNullOrUndefined(found)) {
67
+ found = CommonHttpHeaderNames[keyOrValue as keyof typeof CommonHttpHeaderNames];
68
+ }
69
+ return found;
70
70
  }