@kwiz/common 1.0.105 → 1.0.106

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 (106) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/helpers/browser.js +26 -1
  6. package/lib/cjs/helpers/browser.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/utils/date.js +139 -1
  9. package/lib/cjs/utils/date.js.map +1 -1
  10. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  11. package/lib/esm/helpers/browser.js +24 -0
  12. package/lib/esm/helpers/browser.js.map +1 -1
  13. package/lib/esm/types/libs/msal.types.js +26 -26
  14. package/lib/esm/utils/date.js +137 -0
  15. package/lib/esm/utils/date.js.map +1 -1
  16. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  17. package/lib/types/helpers/browser.d.ts +1 -0
  18. package/lib/types/types/locales.d.ts +1 -0
  19. package/lib/types/utils/date.d.ts +1 -0
  20. package/package.json +81 -81
  21. package/readme.md +17 -17
  22. package/src/_dependencies.ts +12 -12
  23. package/src/config.ts +17 -17
  24. package/src/helpers/Guid.ts +181 -181
  25. package/src/helpers/base64.ts +173 -173
  26. package/src/helpers/browser.test.js +13 -13
  27. package/src/helpers/browser.ts +1428 -1428
  28. package/src/helpers/browserinfo.ts +292 -292
  29. package/src/helpers/collections.base.test.js +25 -25
  30. package/src/helpers/collections.base.ts +437 -437
  31. package/src/helpers/collections.ts +107 -107
  32. package/src/helpers/color.ts +54 -54
  33. package/src/helpers/cookies.ts +59 -59
  34. package/src/helpers/date.test.js +119 -119
  35. package/src/helpers/date.ts +188 -188
  36. package/src/helpers/debug.ts +186 -186
  37. package/src/helpers/diagrams.ts +43 -43
  38. package/src/helpers/emails.ts +6 -6
  39. package/src/helpers/eval.ts +5 -5
  40. package/src/helpers/file.test.js +50 -50
  41. package/src/helpers/file.ts +63 -63
  42. package/src/helpers/flatted.ts +149 -149
  43. package/src/helpers/functions.ts +16 -16
  44. package/src/helpers/graph/calendar.types.ts +10 -10
  45. package/src/helpers/http.ts +69 -69
  46. package/src/helpers/images.ts +22 -22
  47. package/src/helpers/json.ts +44 -44
  48. package/src/helpers/md5.ts +189 -189
  49. package/src/helpers/objects.test.js +33 -33
  50. package/src/helpers/objects.ts +274 -274
  51. package/src/helpers/promises.test.js +37 -37
  52. package/src/helpers/promises.ts +165 -165
  53. package/src/helpers/random.ts +27 -27
  54. package/src/helpers/scheduler/scheduler.test.js +103 -103
  55. package/src/helpers/scheduler/scheduler.ts +131 -131
  56. package/src/helpers/sharepoint.ts +785 -785
  57. package/src/helpers/strings.test.js +122 -122
  58. package/src/helpers/strings.ts +337 -337
  59. package/src/helpers/typecheckers.test.js +34 -34
  60. package/src/helpers/typecheckers.ts +266 -266
  61. package/src/helpers/url.test.js +43 -43
  62. package/src/helpers/url.ts +207 -207
  63. package/src/helpers/urlhelper.ts +111 -111
  64. package/src/index.ts +6 -6
  65. package/src/types/auth.ts +54 -54
  66. package/src/types/common.types.ts +15 -15
  67. package/src/types/flatted.types.ts +59 -59
  68. package/src/types/globals.types.ts +6 -6
  69. package/src/types/graph/calendar.types.ts +80 -80
  70. package/src/types/knownscript.types.ts +18 -18
  71. package/src/types/libs/datajs.types.ts +28 -28
  72. package/src/types/libs/ics.types.ts +30 -30
  73. package/src/types/libs/msal.types.ts +49 -49
  74. package/src/types/locales.ts +125 -124
  75. package/src/types/localstoragecache.types.ts +8 -8
  76. package/src/types/location.types.ts +27 -27
  77. package/src/types/moment.ts +11 -11
  78. package/src/types/regex.types.ts +16 -16
  79. package/src/types/rest.types.ts +95 -95
  80. package/src/types/sharepoint.types.ts +1466 -1466
  81. package/src/types/sharepoint.utils.types.ts +287 -287
  82. package/src/utils/auth/common.ts +74 -74
  83. package/src/utils/auth/discovery.test.js +12 -12
  84. package/src/utils/auth/discovery.ts +132 -132
  85. package/src/utils/base64.ts +27 -27
  86. package/src/utils/consolelogger.ts +320 -320
  87. package/src/utils/date.ts +172 -172
  88. package/src/utils/emails.ts +24 -24
  89. package/src/utils/knownscript.ts +286 -286
  90. package/src/utils/localstoragecache.ts +446 -446
  91. package/src/utils/rest.ts +501 -501
  92. package/src/utils/script.ts +170 -170
  93. package/src/utils/sharepoint.rest/common.ts +154 -154
  94. package/src/utils/sharepoint.rest/date.ts +62 -62
  95. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  96. package/src/utils/sharepoint.rest/item.ts +547 -547
  97. package/src/utils/sharepoint.rest/list.ts +1481 -1481
  98. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  99. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  100. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  101. package/src/utils/sharepoint.rest/location.ts +141 -141
  102. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  103. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  104. package/src/utils/sharepoint.rest/user.ts +491 -491
  105. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  106. package/src/utils/sod.ts +194 -194
@@ -1,35 +1,35 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { isEmptyObject, isNullOrEmptyString, isPrimitiveValue } from './typecheckers';
4
-
5
- test('isNullOrEmptyString', async t => {
6
- // This test passes because it does not throw an exception.
7
- await t.test("null", t => assert.strictEqual(isNullOrEmptyString(null), true));
8
- await t.test("undefined", t => assert.strictEqual(isNullOrEmptyString(undefined), true));
9
- await t.test("empty string", t => assert.strictEqual(isNullOrEmptyString(""), true));
10
- await t.test("space", t => assert.strictEqual(isNullOrEmptyString(" "), false));
11
- await t.test("0", t => assert.strictEqual(isNullOrEmptyString(0), false));
12
- await t.test("1", t => assert.strictEqual(isNullOrEmptyString(1), false));
13
- });
14
-
15
- test('isEmptyObject', async t => {
16
- await t.test("null", t => assert.strictEqual(isEmptyObject(null), true));
17
- await t.test("undefined", t => assert.strictEqual(isEmptyObject(undefined), true));
18
- await t.test("[]", t => assert.strictEqual(isEmptyObject([]), true));
19
- await t.test("{}", t => assert.strictEqual(isEmptyObject({}), true));
20
- await t.test("ignore keys", t => assert.strictEqual(isEmptyObject({ test: 1 }, { ignoreKeys: ["test"] }), true));
21
- await t.test("[1]", t => assert.strictEqual(isEmptyObject([1]), false));
22
- await t.test("non empty object", t => assert.strictEqual(isEmptyObject({ test: 1 }), false));
23
- await t.test("non empty object with ignored key", t => assert.strictEqual(isEmptyObject({ test: 1, test2: 2 }, { ignoreKeys: ["test"] }), false));
24
- });
25
-
26
- test('isPrimitiveValue', async t => {
27
- assert.strictEqual(isPrimitiveValue(1.42), true);
28
- assert.strictEqual(isPrimitiveValue(new Date()), true);
29
- assert.strictEqual(isPrimitiveValue({ title: "hello" }), false);
30
- assert.strictEqual(isPrimitiveValue("hello"), true);
31
- assert.strictEqual(isPrimitiveValue(() => { }), false);
32
- assert.strictEqual(isPrimitiveValue([1, 2, 3]), false);
33
- assert.strictEqual(isPrimitiveValue([]), false);
34
- assert.strictEqual(isPrimitiveValue(), true);
1
+ import assert from 'assert/strict';
2
+ import test from 'node:test';
3
+ import { isEmptyObject, isNullOrEmptyString, isPrimitiveValue } from './typecheckers';
4
+
5
+ test('isNullOrEmptyString', async t => {
6
+ // This test passes because it does not throw an exception.
7
+ await t.test("null", t => assert.strictEqual(isNullOrEmptyString(null), true));
8
+ await t.test("undefined", t => assert.strictEqual(isNullOrEmptyString(undefined), true));
9
+ await t.test("empty string", t => assert.strictEqual(isNullOrEmptyString(""), true));
10
+ await t.test("space", t => assert.strictEqual(isNullOrEmptyString(" "), false));
11
+ await t.test("0", t => assert.strictEqual(isNullOrEmptyString(0), false));
12
+ await t.test("1", t => assert.strictEqual(isNullOrEmptyString(1), false));
13
+ });
14
+
15
+ test('isEmptyObject', async t => {
16
+ await t.test("null", t => assert.strictEqual(isEmptyObject(null), true));
17
+ await t.test("undefined", t => assert.strictEqual(isEmptyObject(undefined), true));
18
+ await t.test("[]", t => assert.strictEqual(isEmptyObject([]), true));
19
+ await t.test("{}", t => assert.strictEqual(isEmptyObject({}), true));
20
+ await t.test("ignore keys", t => assert.strictEqual(isEmptyObject({ test: 1 }, { ignoreKeys: ["test"] }), true));
21
+ await t.test("[1]", t => assert.strictEqual(isEmptyObject([1]), false));
22
+ await t.test("non empty object", t => assert.strictEqual(isEmptyObject({ test: 1 }), false));
23
+ await t.test("non empty object with ignored key", t => assert.strictEqual(isEmptyObject({ test: 1, test2: 2 }, { ignoreKeys: ["test"] }), false));
24
+ });
25
+
26
+ test('isPrimitiveValue', async t => {
27
+ assert.strictEqual(isPrimitiveValue(1.42), true);
28
+ assert.strictEqual(isPrimitiveValue(new Date()), true);
29
+ assert.strictEqual(isPrimitiveValue({ title: "hello" }), false);
30
+ assert.strictEqual(isPrimitiveValue("hello"), true);
31
+ assert.strictEqual(isPrimitiveValue(() => { }), false);
32
+ assert.strictEqual(isPrimitiveValue([1, 2, 3]), false);
33
+ assert.strictEqual(isPrimitiveValue([]), false);
34
+ assert.strictEqual(isPrimitiveValue(), true);
35
35
  });
@@ -1,267 +1,267 @@
1
- var _objectTypes = {
2
- "Function": typeof (() => {/*empty*/ }),
3
- "Undefined": typeof (undefined),
4
- "String": typeof (""),
5
- "Number": typeof (1),
6
- "Object": typeof ({}),
7
- "Boolean": typeof (true)
8
- };
9
-
10
- /** check if a global object in that full name exists and return its type or "undefined" */
11
- export function typeofFullName(fullName: string, windowOrParent?: Window | any) {
12
- //todo: possible to merge with getFromFullName, but we need to distinguish between null and undefined
13
-
14
- if (!fullName) {
15
- return _objectTypes.Undefined;
16
- }
17
- try {
18
- let names = fullName.split(".");
19
- let len = names.length;
20
- let obj = windowOrParent || window;
21
-
22
- for (var i = 0; i < len; i++) {
23
- obj = obj[names[i]];
24
- if (typeof obj === _objectTypes.Undefined)
25
- return _objectTypes.Undefined;
26
- if (obj === null && i < len)//one of the chained objects (not the leaf) is null - so return undefined
27
- return _objectTypes.Undefined;
28
- }
29
- return typeof obj;
30
- } catch (ex) {
31
- return _objectTypes.Undefined;
32
- }
33
- }
34
-
35
- /** get the value by full name of property */
36
- export function getFromFullName<T>(fullName: string, windowOrParent?: Window | any) {
37
- try {
38
- if (isNullOrEmptyString(fullName)) {
39
- return null;
40
- }
41
- try {
42
- var names = fullName.split(".");
43
- var len = names.length;
44
- var obj = windowOrParent || window;
45
-
46
- for (var i = 0; i < len; i++) {
47
- obj = obj[names[i]];
48
- if (typeof obj === _objectTypes.Undefined || obj === null) {
49
- return null;
50
- }
51
- }
52
- return <T>obj;
53
- } catch (ex) {
54
- }
55
- } catch (e) { }
56
- return null;
57
- }
58
-
59
- export function isTypeofFullNameObject(fullName: string, windowOrParent?: Window | any): boolean {
60
- return typeofFullName(fullName, windowOrParent) === _objectTypes.Object;
61
- }
62
-
63
- export function isTypeofFullNameString(fullName: string, windowOrParent?: Window | any): boolean {
64
- return typeofFullName(fullName, windowOrParent) === _objectTypes.String;
65
- }
66
-
67
- export function isTypeofFullNameNumber(fullName: string, windowOrParent?: Window | any): boolean {
68
- return typeofFullName(fullName, windowOrParent) === _objectTypes.Number;
69
- }
70
-
71
- export function isTypeofFullNameNullOrUndefined(fullName: string, windowOrParent?: Window | any): boolean {
72
- if (typeofFullName(fullName, windowOrParent) === _objectTypes.Undefined) {
73
- return true;
74
- }
75
-
76
- try {
77
- var names = fullName.split(".");
78
- var len = names.length;
79
- var obj = windowOrParent || window;
80
-
81
- for (var i = 0; i < len && obj !== null; i++) {
82
- obj = obj[names[i]];
83
- }
84
-
85
- return obj === null || obj === undefined;
86
- } catch (ex) {
87
- return true;
88
- }
89
- }
90
-
91
- export function isTypeofFullNameUndefined(fullName: string, windowOrParent?: Window | any): boolean {
92
- return typeofFullName(fullName, windowOrParent) === _objectTypes.Undefined;
93
- }
94
-
95
- export function isTypeofFullNameFunction(fullName: string, windowOrParent?: Window | any): boolean {
96
- return typeofFullName(fullName, windowOrParent) === _objectTypes.Function;
97
- }
98
-
99
- export function isTypeofFullNameBoolean(fullName: string, windowOrParent?: Window | any): boolean {
100
- return typeofFullName(fullName, windowOrParent) === _objectTypes.Boolean;
101
- }
102
-
103
- export function isType(obj: any, str: string) {
104
- return typeof (obj) === str;
105
- }
106
-
107
- // eslint-disable-next-line @typescript-eslint/ban-types
108
- export function isObject(obj: any): obj is object {
109
- return isType(obj, _objectTypes.Object);
110
- }
111
-
112
- /** Checks if obj is empty - as primitive, array or object
113
- * If an object, pass an optional array of keys to ignore
114
- */
115
- export function isEmptyObject(obj: any, options?: { ignoreKeys?: string[] }) {
116
- let ignoreKeys = options && options.ignoreKeys || [];
117
- return isNullOrUndefined(obj) || (Array.isArray(obj) && obj.length === 0) ||
118
- (isObject(obj) && Object.keys(obj)
119
- //if options.ignoreKeys is not empty - only include keys that are NOT in this array
120
- .filter(key => SafeIfElse(() => ignoreKeys.indexOf(key) < 0, true))
121
- .length === 0);
122
- }
123
-
124
- export function isNullOrUndefined(obj: any) {
125
- return isUndefined(obj) || obj === null;
126
- }
127
-
128
- /** return true if o is undefined, null or not a number */
129
- export function isNullOrNaN(o: any): boolean {
130
- return isNullOrEmptyString(o) || isNaN(o);
131
- }
132
-
133
- /** return true if o is undefined, null or empty string */
134
- export function isNullOrEmptyString(o: any): o is null | undefined | "" {
135
- return isNullOrUndefined(o) || o === '';
136
- }
137
-
138
- /** o is an array that is not empty (length > 0) */
139
- export function isNotEmptyArray(o: any): o is any[] {
140
- return Array.isArray(o) && o.length > 0;
141
- }
142
- /** o is undefined, null or an empty array */
143
- export function isNullOrEmptyArray(o: any): boolean {
144
- return isNullOrUndefined(o) || (Array.isArray(o) && o.length < 1);
145
- }
146
-
147
- export function isString(obj: any): obj is string {
148
- return isType(obj, _objectTypes.String);
149
- }
150
-
151
- export function isNotEmptyString(obj: any): obj is string {
152
- return isString(obj) && obj.length > 0;
153
- }
154
-
155
- /** true if object is a Date object */
156
- export function isDate(obj: any): obj is Date {
157
- return !isNullOrUndefined(obj) && isFunction(obj.getTime) && !isNullOrNaN((obj as Date).getTime());
158
- }
159
-
160
- /** true if obj is a number or a numeric string */
161
- export function isNumeric(obj: any): obj is number | string {
162
- return !isNullOrEmptyString(obj) && !Array.isArray(obj) &&//[14] will return true, since [14].toString() is "14"
163
- !isNaN(parseFloat(obj as string)) && isFinite(obj as number) && isType(Number(obj), _objectTypes.Number);
164
- }
165
- /** true if obj is a number */
166
- export function isNumber(obj?: any): obj is number {
167
- return !isNullOrNaN(obj) && isType(obj, _objectTypes.Number);
168
- }
169
-
170
- export function isNumberArray(obj: any[]): obj is number[] {
171
- return !isNullOrUndefined(obj) && Array.isArray(obj) && obj.every((entry) => {
172
- return isNumber(entry);
173
- });
174
- }
175
-
176
- export function isUndefined(obj: any): obj is undefined {
177
- return isType(obj, _objectTypes.Undefined);
178
- }
179
-
180
- //eslint-disable-next-line @typescript-eslint/ban-types
181
- export function isFunction(obj: any): obj is Function {
182
- return isType(obj, _objectTypes.Function);
183
- }
184
-
185
- export function isBoolean(obj: any): obj is boolean {
186
- return isType(obj, _objectTypes.Boolean);
187
- }
188
-
189
- export function isPromise<t>(obj: any): obj is Promise<t> {
190
- return obj && isFunction(obj["then"]);
191
- }
192
-
193
- export type primitiveTypes = string | number | Date | boolean | null;
194
- /**returns true if object is string, number, date, boolean value or null*/
195
- export function isPrimitiveValue(obj: any): obj is primitiveTypes {
196
- return isNullOrUndefined(obj) || isString(obj) || isNumber(obj) || isDate(obj) || isBoolean(obj);
197
- }
198
-
199
- export function isValidGuid(str: string) {
200
- var a = new RegExp("^[{|\\(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[\\)|}]?$");
201
- return !!a.exec(str);
202
- }
203
-
204
- export var BoolTrueStrings = ["true", "1", "on", "yes"];
205
- export var BoolFalseStrings = ["false", "0", "off", "no"];
206
- export function isTrueString(str: string, options?: { allowPositiveNumbers?: boolean; }) {
207
- if (isNullOrEmptyString(str)) return false;
208
- else if (BoolTrueStrings.includes(str.toLowerCase()))
209
- return true;
210
- else if (options && options.allowPositiveNumbers && isNumeric(str))
211
- return Number(str) > 0;//any number greater than 0 is considered true.
212
- else return false;
213
- }
214
-
215
- export function newGuid() {
216
- var S4 = () => {
217
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
218
- };
219
- // then to call it, plus stitch in '4' in the third group
220
- return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
221
- }
222
-
223
- /** check if object has all members (they are not undefined) */
224
- export function hasMembers(o: any, ...members: string[]) {
225
- if (!isNullOrUndefined(o)) {
226
- for (let i = 0; i < members.length; i++)
227
- if (isUndefined(o[members[i]]))
228
- return false;
229
- return true;//not null and all members exist
230
- }
231
- return false;
232
- }
233
-
234
- /** compares 2 versions. if v1 is bigger return 1, if v2 is bigger returns -1, if equals return 0 */
235
- export function CompareVersion(v1: string, v2: string) {
236
- let v1Split = v1 && v1.split('.').map(s => parseInt(s, 10)) || [];
237
- let v2Split = v2 && v2.split('.').map(s => parseInt(s, 10)) || [];
238
-
239
- for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
240
- let p1 = v1Split[i];
241
- let p2 = v2Split[i];
242
- if (isNaN(p1)) p1 = -1;
243
- if (isNaN(p2)) p2 = -1;
244
-
245
- if (p1 > p2) return 1;
246
- else if (p1 < p2) return -1;
247
- }
248
- //finished while equal? return 0
249
- return 0;
250
- }
251
-
252
- /** pass along a list of unsafe tests to get a value, the first one that doesn't throw an exception and doesnt return null will get returned */
253
- export function SafeIfElse<T>(...list: ((() => T) | T)[]) {
254
- for (let i = 0; i < list.length; i++) {
255
- let v: T = null;
256
- let getter = list[i];
257
- if (isFunction(getter)) {
258
- try {
259
- v = getter();
260
- } catch (e) { v = null; }
261
- }
262
- else v = getter;
263
-
264
- if (!isNullOrUndefined(v)) return v;
265
- }
266
- return null;
1
+ var _objectTypes = {
2
+ "Function": typeof (() => {/*empty*/ }),
3
+ "Undefined": typeof (undefined),
4
+ "String": typeof (""),
5
+ "Number": typeof (1),
6
+ "Object": typeof ({}),
7
+ "Boolean": typeof (true)
8
+ };
9
+
10
+ /** check if a global object in that full name exists and return its type or "undefined" */
11
+ export function typeofFullName(fullName: string, windowOrParent?: Window | any) {
12
+ //todo: possible to merge with getFromFullName, but we need to distinguish between null and undefined
13
+
14
+ if (!fullName) {
15
+ return _objectTypes.Undefined;
16
+ }
17
+ try {
18
+ let names = fullName.split(".");
19
+ let len = names.length;
20
+ let obj = windowOrParent || window;
21
+
22
+ for (var i = 0; i < len; i++) {
23
+ obj = obj[names[i]];
24
+ if (typeof obj === _objectTypes.Undefined)
25
+ return _objectTypes.Undefined;
26
+ if (obj === null && i < len)//one of the chained objects (not the leaf) is null - so return undefined
27
+ return _objectTypes.Undefined;
28
+ }
29
+ return typeof obj;
30
+ } catch (ex) {
31
+ return _objectTypes.Undefined;
32
+ }
33
+ }
34
+
35
+ /** get the value by full name of property */
36
+ export function getFromFullName<T>(fullName: string, windowOrParent?: Window | any) {
37
+ try {
38
+ if (isNullOrEmptyString(fullName)) {
39
+ return null;
40
+ }
41
+ try {
42
+ var names = fullName.split(".");
43
+ var len = names.length;
44
+ var obj = windowOrParent || window;
45
+
46
+ for (var i = 0; i < len; i++) {
47
+ obj = obj[names[i]];
48
+ if (typeof obj === _objectTypes.Undefined || obj === null) {
49
+ return null;
50
+ }
51
+ }
52
+ return <T>obj;
53
+ } catch (ex) {
54
+ }
55
+ } catch (e) { }
56
+ return null;
57
+ }
58
+
59
+ export function isTypeofFullNameObject(fullName: string, windowOrParent?: Window | any): boolean {
60
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.Object;
61
+ }
62
+
63
+ export function isTypeofFullNameString(fullName: string, windowOrParent?: Window | any): boolean {
64
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.String;
65
+ }
66
+
67
+ export function isTypeofFullNameNumber(fullName: string, windowOrParent?: Window | any): boolean {
68
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.Number;
69
+ }
70
+
71
+ export function isTypeofFullNameNullOrUndefined(fullName: string, windowOrParent?: Window | any): boolean {
72
+ if (typeofFullName(fullName, windowOrParent) === _objectTypes.Undefined) {
73
+ return true;
74
+ }
75
+
76
+ try {
77
+ var names = fullName.split(".");
78
+ var len = names.length;
79
+ var obj = windowOrParent || window;
80
+
81
+ for (var i = 0; i < len && obj !== null; i++) {
82
+ obj = obj[names[i]];
83
+ }
84
+
85
+ return obj === null || obj === undefined;
86
+ } catch (ex) {
87
+ return true;
88
+ }
89
+ }
90
+
91
+ export function isTypeofFullNameUndefined(fullName: string, windowOrParent?: Window | any): boolean {
92
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.Undefined;
93
+ }
94
+
95
+ export function isTypeofFullNameFunction(fullName: string, windowOrParent?: Window | any): boolean {
96
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.Function;
97
+ }
98
+
99
+ export function isTypeofFullNameBoolean(fullName: string, windowOrParent?: Window | any): boolean {
100
+ return typeofFullName(fullName, windowOrParent) === _objectTypes.Boolean;
101
+ }
102
+
103
+ export function isType(obj: any, str: string) {
104
+ return typeof (obj) === str;
105
+ }
106
+
107
+ // eslint-disable-next-line @typescript-eslint/ban-types
108
+ export function isObject(obj: any): obj is object {
109
+ return isType(obj, _objectTypes.Object);
110
+ }
111
+
112
+ /** Checks if obj is empty - as primitive, array or object
113
+ * If an object, pass an optional array of keys to ignore
114
+ */
115
+ export function isEmptyObject(obj: any, options?: { ignoreKeys?: string[] }) {
116
+ let ignoreKeys = options && options.ignoreKeys || [];
117
+ return isNullOrUndefined(obj) || (Array.isArray(obj) && obj.length === 0) ||
118
+ (isObject(obj) && Object.keys(obj)
119
+ //if options.ignoreKeys is not empty - only include keys that are NOT in this array
120
+ .filter(key => SafeIfElse(() => ignoreKeys.indexOf(key) < 0, true))
121
+ .length === 0);
122
+ }
123
+
124
+ export function isNullOrUndefined(obj: any) {
125
+ return isUndefined(obj) || obj === null;
126
+ }
127
+
128
+ /** return true if o is undefined, null or not a number */
129
+ export function isNullOrNaN(o: any): boolean {
130
+ return isNullOrEmptyString(o) || isNaN(o);
131
+ }
132
+
133
+ /** return true if o is undefined, null or empty string */
134
+ export function isNullOrEmptyString(o: any): o is null | undefined | "" {
135
+ return isNullOrUndefined(o) || o === '';
136
+ }
137
+
138
+ /** o is an array that is not empty (length > 0) */
139
+ export function isNotEmptyArray(o: any): o is any[] {
140
+ return Array.isArray(o) && o.length > 0;
141
+ }
142
+ /** o is undefined, null or an empty array */
143
+ export function isNullOrEmptyArray(o: any): boolean {
144
+ return isNullOrUndefined(o) || (Array.isArray(o) && o.length < 1);
145
+ }
146
+
147
+ export function isString(obj: any): obj is string {
148
+ return isType(obj, _objectTypes.String);
149
+ }
150
+
151
+ export function isNotEmptyString(obj: any): obj is string {
152
+ return isString(obj) && obj.length > 0;
153
+ }
154
+
155
+ /** true if object is a Date object */
156
+ export function isDate(obj: any): obj is Date {
157
+ return !isNullOrUndefined(obj) && isFunction(obj.getTime) && !isNullOrNaN((obj as Date).getTime());
158
+ }
159
+
160
+ /** true if obj is a number or a numeric string */
161
+ export function isNumeric(obj: any): obj is number | string {
162
+ return !isNullOrEmptyString(obj) && !Array.isArray(obj) &&//[14] will return true, since [14].toString() is "14"
163
+ !isNaN(parseFloat(obj as string)) && isFinite(obj as number) && isType(Number(obj), _objectTypes.Number);
164
+ }
165
+ /** true if obj is a number */
166
+ export function isNumber(obj?: any): obj is number {
167
+ return !isNullOrNaN(obj) && isType(obj, _objectTypes.Number);
168
+ }
169
+
170
+ export function isNumberArray(obj: any[]): obj is number[] {
171
+ return !isNullOrUndefined(obj) && Array.isArray(obj) && obj.every((entry) => {
172
+ return isNumber(entry);
173
+ });
174
+ }
175
+
176
+ export function isUndefined(obj: any): obj is undefined {
177
+ return isType(obj, _objectTypes.Undefined);
178
+ }
179
+
180
+ //eslint-disable-next-line @typescript-eslint/ban-types
181
+ export function isFunction(obj: any): obj is Function {
182
+ return isType(obj, _objectTypes.Function);
183
+ }
184
+
185
+ export function isBoolean(obj: any): obj is boolean {
186
+ return isType(obj, _objectTypes.Boolean);
187
+ }
188
+
189
+ export function isPromise<t>(obj: any): obj is Promise<t> {
190
+ return obj && isFunction(obj["then"]);
191
+ }
192
+
193
+ export type primitiveTypes = string | number | Date | boolean | null;
194
+ /**returns true if object is string, number, date, boolean value or null*/
195
+ export function isPrimitiveValue(obj: any): obj is primitiveTypes {
196
+ return isNullOrUndefined(obj) || isString(obj) || isNumber(obj) || isDate(obj) || isBoolean(obj);
197
+ }
198
+
199
+ export function isValidGuid(str: string) {
200
+ var a = new RegExp("^[{|\\(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[\\)|}]?$");
201
+ return !!a.exec(str);
202
+ }
203
+
204
+ export var BoolTrueStrings = ["true", "1", "on", "yes"];
205
+ export var BoolFalseStrings = ["false", "0", "off", "no"];
206
+ export function isTrueString(str: string, options?: { allowPositiveNumbers?: boolean; }) {
207
+ if (isNullOrEmptyString(str)) return false;
208
+ else if (BoolTrueStrings.includes(str.toLowerCase()))
209
+ return true;
210
+ else if (options && options.allowPositiveNumbers && isNumeric(str))
211
+ return Number(str) > 0;//any number greater than 0 is considered true.
212
+ else return false;
213
+ }
214
+
215
+ export function newGuid() {
216
+ var S4 = () => {
217
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
218
+ };
219
+ // then to call it, plus stitch in '4' in the third group
220
+ return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
221
+ }
222
+
223
+ /** check if object has all members (they are not undefined) */
224
+ export function hasMembers(o: any, ...members: string[]) {
225
+ if (!isNullOrUndefined(o)) {
226
+ for (let i = 0; i < members.length; i++)
227
+ if (isUndefined(o[members[i]]))
228
+ return false;
229
+ return true;//not null and all members exist
230
+ }
231
+ return false;
232
+ }
233
+
234
+ /** compares 2 versions. if v1 is bigger return 1, if v2 is bigger returns -1, if equals return 0 */
235
+ export function CompareVersion(v1: string, v2: string) {
236
+ let v1Split = v1 && v1.split('.').map(s => parseInt(s, 10)) || [];
237
+ let v2Split = v2 && v2.split('.').map(s => parseInt(s, 10)) || [];
238
+
239
+ for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
240
+ let p1 = v1Split[i];
241
+ let p2 = v2Split[i];
242
+ if (isNaN(p1)) p1 = -1;
243
+ if (isNaN(p2)) p2 = -1;
244
+
245
+ if (p1 > p2) return 1;
246
+ else if (p1 < p2) return -1;
247
+ }
248
+ //finished while equal? return 0
249
+ return 0;
250
+ }
251
+
252
+ /** pass along a list of unsafe tests to get a value, the first one that doesn't throw an exception and doesnt return null will get returned */
253
+ export function SafeIfElse<T>(...list: ((() => T) | T)[]) {
254
+ for (let i = 0; i < list.length; i++) {
255
+ let v: T = null;
256
+ let getter = list[i];
257
+ if (isFunction(getter)) {
258
+ try {
259
+ v = getter();
260
+ } catch (e) { v = null; }
261
+ }
262
+ else v = getter;
263
+
264
+ if (!isNullOrUndefined(v)) return v;
265
+ }
266
+ return null;
267
267
  }