@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,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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function
|
|
167
|
-
return !
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
export function
|
|
182
|
-
return isType(obj, _objectTypes.
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function
|
|
186
|
-
return obj
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
export function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
else
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
}
|