@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.
Files changed (118) 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 +5 -1
  6. package/lib/cjs/helpers/sharepoint.js.map +1 -1
  7. package/lib/cjs/helpers/typecheckers.js +5 -1
  8. package/lib/cjs/helpers/typecheckers.js.map +1 -1
  9. package/lib/cjs/types/libs/msal.types.js +26 -26
  10. package/lib/cjs/utils/sharepoint.rest/list.js +1 -1
  11. package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
  12. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  13. package/lib/esm/helpers/sharepoint.js +3 -0
  14. package/lib/esm/helpers/sharepoint.js.map +1 -1
  15. package/lib/esm/helpers/typecheckers.js +3 -0
  16. package/lib/esm/helpers/typecheckers.js.map +1 -1
  17. package/lib/esm/types/libs/msal.types.js +26 -26
  18. package/lib/esm/utils/sharepoint.rest/list.js +2 -2
  19. package/lib/esm/utils/sharepoint.rest/list.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/lib/types/helpers/typecheckers.d.ts +1 -0
  23. package/package.json +77 -77
  24. package/readme.md +17 -17
  25. package/src/_dependencies.ts +12 -12
  26. package/src/config.ts +17 -17
  27. package/src/helpers/Guid.ts +181 -181
  28. package/src/helpers/base64.ts +173 -173
  29. package/src/helpers/browser.test.js +13 -13
  30. package/src/helpers/browser.ts +1348 -1348
  31. package/src/helpers/browserinfo.ts +292 -292
  32. package/src/helpers/collections.base.test.js +25 -25
  33. package/src/helpers/collections.base.ts +437 -437
  34. package/src/helpers/collections.ts +107 -107
  35. package/src/helpers/color.ts +54 -54
  36. package/src/helpers/cookies.ts +59 -59
  37. package/src/helpers/date.test.js +119 -119
  38. package/src/helpers/date.ts +188 -188
  39. package/src/helpers/debug.ts +186 -186
  40. package/src/helpers/emails.ts +6 -6
  41. package/src/helpers/eval.ts +5 -5
  42. package/src/helpers/file.test.js +50 -50
  43. package/src/helpers/file.ts +58 -58
  44. package/src/helpers/flatted.ts +149 -149
  45. package/src/helpers/functions.ts +16 -16
  46. package/src/helpers/graph/calendar.types.ts +10 -10
  47. package/src/helpers/http.ts +69 -69
  48. package/src/helpers/images.ts +22 -22
  49. package/src/helpers/json.ts +38 -38
  50. package/src/helpers/md5.ts +189 -189
  51. package/src/helpers/objects.test.js +33 -33
  52. package/src/helpers/objects.ts +270 -270
  53. package/src/helpers/promises.test.js +37 -37
  54. package/src/helpers/promises.ts +165 -165
  55. package/src/helpers/random.ts +27 -27
  56. package/src/helpers/scheduler/scheduler.test.js +103 -103
  57. package/src/helpers/scheduler/scheduler.ts +131 -131
  58. package/src/helpers/sharepoint.ts +776 -772
  59. package/src/helpers/strings.test.js +101 -101
  60. package/src/helpers/strings.ts +317 -317
  61. package/src/helpers/typecheckers.test.js +34 -34
  62. package/src/helpers/typecheckers.ts +266 -262
  63. package/src/helpers/url.test.js +43 -43
  64. package/src/helpers/url.ts +207 -207
  65. package/src/helpers/urlhelper.ts +111 -111
  66. package/src/index.ts +6 -6
  67. package/src/types/auth.ts +54 -54
  68. package/src/types/common.types.ts +15 -15
  69. package/src/types/flatted.types.ts +59 -59
  70. package/src/types/globals.types.ts +6 -6
  71. package/src/types/graph/calendar.types.ts +80 -80
  72. package/src/types/knownscript.types.ts +18 -18
  73. package/src/types/libs/datajs.types.ts +28 -28
  74. package/src/types/libs/ics.types.ts +30 -30
  75. package/src/types/libs/msal.types.ts +49 -49
  76. package/src/types/locales.ts +124 -124
  77. package/src/types/localstoragecache.types.ts +8 -8
  78. package/src/types/location.types.ts +27 -27
  79. package/src/types/moment.ts +11 -11
  80. package/src/types/regex.types.ts +16 -16
  81. package/src/types/rest.types.ts +95 -95
  82. package/src/types/sharepoint.types.ts +1465 -1465
  83. package/src/types/sharepoint.utils.types.ts +287 -287
  84. package/src/utils/auth/common.ts +74 -74
  85. package/src/utils/auth/discovery.test.js +12 -12
  86. package/src/utils/auth/discovery.ts +132 -132
  87. package/src/utils/base64.ts +27 -27
  88. package/src/utils/consolelogger.ts +320 -320
  89. package/src/utils/date.ts +35 -35
  90. package/src/utils/emails.ts +24 -24
  91. package/src/utils/knownscript.ts +286 -286
  92. package/src/utils/localstoragecache.ts +441 -441
  93. package/src/utils/rest.ts +501 -501
  94. package/src/utils/script.ts +170 -170
  95. package/src/utils/sharepoint.rest/common.ts +154 -154
  96. package/src/utils/sharepoint.rest/date.ts +62 -62
  97. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  98. package/src/utils/sharepoint.rest/item.ts +547 -547
  99. package/src/utils/sharepoint.rest/list.ts +1388 -1388
  100. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  101. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  102. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  103. package/src/utils/sharepoint.rest/location.ts +141 -141
  104. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  105. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  106. package/src/utils/sharepoint.rest/user.ts +491 -491
  107. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  108. package/src/utils/sod.ts +194 -194
  109. package/lib/cjs/helpers/_dependencies.js +0 -21
  110. package/lib/cjs/helpers/_dependencies.js.map +0 -1
  111. package/lib/cjs/utils/_dependencies.js +0 -24
  112. package/lib/cjs/utils/_dependencies.js.map +0 -1
  113. package/lib/esm/helpers/_dependencies.js +0 -3
  114. package/lib/esm/helpers/_dependencies.js.map +0 -1
  115. package/lib/esm/utils/_dependencies.js +0 -4
  116. package/lib/esm/utils/_dependencies.js.map +0 -1
  117. package/lib/types/helpers/_dependencies.d.ts +0 -2
  118. package/lib/types/utils/_dependencies.d.ts +0 -3
@@ -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,263 +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
- /** true if object is a Date object */
152
- export function isDate(obj: any): obj is Date {
153
- return !isNullOrUndefined(obj) && isFunction(obj.getTime) && !isNullOrNaN((obj as Date).getTime());
154
- }
155
-
156
- /** true if obj is a number or a numeric string */
157
- export function isNumeric(obj: any): obj is number | string {
158
- return !isNullOrEmptyString(obj) && !Array.isArray(obj) &&//[14] will return true, since [14].toString() is "14"
159
- !isNaN(parseFloat(obj as string)) && isFinite(obj as number) && isType(Number(obj), _objectTypes.Number);
160
- }
161
- /** true if obj is a number */
162
- export function isNumber(obj?: any): obj is number {
163
- return !isNullOrNaN(obj) && isType(obj, _objectTypes.Number);
164
- }
165
-
166
- export function isNumberArray(obj: any[]): obj is number[] {
167
- return !isNullOrUndefined(obj) && Array.isArray(obj) && obj.every((entry) => {
168
- return isNumber(entry);
169
- });
170
- }
171
-
172
- export function isUndefined(obj: any): obj is undefined {
173
- return isType(obj, _objectTypes.Undefined);
174
- }
175
-
176
- //eslint-disable-next-line @typescript-eslint/ban-types
177
- export function isFunction(obj: any): obj is Function {
178
- return isType(obj, _objectTypes.Function);
179
- }
180
-
181
- export function isBoolean(obj: any): obj is boolean {
182
- return isType(obj, _objectTypes.Boolean);
183
- }
184
-
185
- export function isPromise<t>(obj: any): obj is Promise<t> {
186
- return obj && isFunction(obj["then"]);
187
- }
188
-
189
- export type primitiveTypes = string | number | Date | boolean | null;
190
- /**returns true if object is string, number, date, boolean value or null*/
191
- export function isPrimitiveValue(obj: any): obj is primitiveTypes {
192
- return isNullOrUndefined(obj) || isString(obj) || isNumber(obj) || isDate(obj) || isBoolean(obj);
193
- }
194
-
195
- export function isValidGuid(str: string) {
196
- var a = new RegExp("^[{|\\(]?[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}[\\)|}]?$");
197
- return !!a.exec(str);
198
- }
199
-
200
- export var BoolTrueStrings = ["true", "1", "on", "yes"];
201
- export var BoolFalseStrings = ["false", "0", "off", "no"];
202
- export function isTrueString(str: string, options?: { allowPositiveNumbers?: boolean; }) {
203
- if (isNullOrEmptyString(str)) return false;
204
- else if (BoolTrueStrings.includes(str.toLowerCase()))
205
- return true;
206
- else if (options && options.allowPositiveNumbers && isNumeric(str))
207
- return Number(str) > 0;//any number greater than 0 is considered true.
208
- else return false;
209
- }
210
-
211
- export function newGuid() {
212
- var S4 = () => {
213
- return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
214
- };
215
- // then to call it, plus stitch in '4' in the third group
216
- return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
217
- }
218
-
219
- /** check if object has all members (they are not undefined) */
220
- export function hasMembers(o: any, ...members: string[]) {
221
- if (!isNullOrUndefined(o)) {
222
- for (let i = 0; i < members.length; i++)
223
- if (isUndefined(o[members[i]]))
224
- return false;
225
- return true;//not null and all members exist
226
- }
227
- return false;
228
- }
229
-
230
- /** compares 2 versions. if v1 is bigger return 1, if v2 is bigger returns -1, if equals return 0 */
231
- export function CompareVersion(v1: string, v2: string) {
232
- let v1Split = v1 && v1.split('.').map(s => parseInt(s, 10)) || [];
233
- let v2Split = v2 && v2.split('.').map(s => parseInt(s, 10)) || [];
234
-
235
- for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
236
- let p1 = v1Split[i];
237
- let p2 = v2Split[i];
238
- if (isNaN(p1)) p1 = -1;
239
- if (isNaN(p2)) p2 = -1;
240
-
241
- if (p1 > p2) return 1;
242
- else if (p1 < p2) return -1;
243
- }
244
- //finished while equal? return 0
245
- return 0;
246
- }
247
-
248
- /** 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 */
249
- export function SafeIfElse<T>(...list: ((() => T) | T)[]) {
250
- for (let i = 0; i < list.length; i++) {
251
- let v: T = null;
252
- let getter = list[i];
253
- if (isFunction(getter)) {
254
- try {
255
- v = getter();
256
- } catch (e) { v = null; }
257
- }
258
- else v = getter;
259
-
260
- if (!isNullOrUndefined(v)) return v;
261
- }
262
- 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;
263
267
  }