@kwiz/common 1.0.132 → 1.0.134

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 (108) hide show
  1. package/lib/cjs/helpers/promises.js +4 -3
  2. package/lib/cjs/helpers/promises.js.map +1 -1
  3. package/lib/cjs/utils/sharepoint.rest/web.js +10 -2
  4. package/lib/cjs/utils/sharepoint.rest/web.js.map +1 -1
  5. package/lib/esm/helpers/promises.js +4 -3
  6. package/lib/esm/helpers/promises.js.map +1 -1
  7. package/lib/esm/utils/sharepoint.rest/web.js +7 -0
  8. package/lib/esm/utils/sharepoint.rest/web.js.map +1 -1
  9. package/lib/types/helpers/promises.d.ts +1 -1
  10. package/lib/types/utils/sharepoint.rest/web.d.ts +1 -0
  11. package/package.json +3 -2
  12. package/.github/workflows/npm-publish.yml +0 -24
  13. package/src/_dependencies.ts +0 -13
  14. package/src/config.ts +0 -19
  15. package/src/exports-index.ts +0 -4
  16. package/src/helpers/Guid.ts +0 -182
  17. package/src/helpers/base64.ts +0 -174
  18. package/src/helpers/browser.test.js +0 -13
  19. package/src/helpers/browser.ts +0 -1505
  20. package/src/helpers/browserinfo.ts +0 -293
  21. package/src/helpers/collections.base.test.js +0 -26
  22. package/src/helpers/collections.base.ts +0 -438
  23. package/src/helpers/collections.ts +0 -108
  24. package/src/helpers/color.ts +0 -55
  25. package/src/helpers/cookies.ts +0 -60
  26. package/src/helpers/date.test.js +0 -120
  27. package/src/helpers/date.ts +0 -189
  28. package/src/helpers/debug.ts +0 -187
  29. package/src/helpers/diagrams.ts +0 -44
  30. package/src/helpers/emails.ts +0 -7
  31. package/src/helpers/eval.ts +0 -5
  32. package/src/helpers/exports-index.ts +0 -30
  33. package/src/helpers/file.test.js +0 -51
  34. package/src/helpers/file.ts +0 -64
  35. package/src/helpers/flatted.ts +0 -150
  36. package/src/helpers/functions.ts +0 -17
  37. package/src/helpers/graph/calendar.types.ts +0 -11
  38. package/src/helpers/graph/exports-index.ts +0 -1
  39. package/src/helpers/http.ts +0 -70
  40. package/src/helpers/images.ts +0 -23
  41. package/src/helpers/json.ts +0 -45
  42. package/src/helpers/md5.ts +0 -190
  43. package/src/helpers/objects.test.js +0 -34
  44. package/src/helpers/objects.ts +0 -275
  45. package/src/helpers/promises.test.js +0 -38
  46. package/src/helpers/promises.ts +0 -166
  47. package/src/helpers/random.ts +0 -27
  48. package/src/helpers/scheduler/exports-index.ts +0 -1
  49. package/src/helpers/scheduler/scheduler.test.js +0 -104
  50. package/src/helpers/scheduler/scheduler.ts +0 -132
  51. package/src/helpers/sharepoint.ts +0 -797
  52. package/src/helpers/strings.test.js +0 -123
  53. package/src/helpers/strings.ts +0 -338
  54. package/src/helpers/typecheckers.test.js +0 -35
  55. package/src/helpers/typecheckers.ts +0 -267
  56. package/src/helpers/url.test.js +0 -44
  57. package/src/helpers/url.ts +0 -208
  58. package/src/helpers/urlhelper.ts +0 -112
  59. package/src/index.ts +0 -6
  60. package/src/types/auth.ts +0 -63
  61. package/src/types/common.types.ts +0 -16
  62. package/src/types/exports-index.ts +0 -15
  63. package/src/types/flatted.types.ts +0 -60
  64. package/src/types/globals.types.ts +0 -7
  65. package/src/types/graph/calendar.types.ts +0 -81
  66. package/src/types/graph/exports-index.ts +0 -1
  67. package/src/types/knownscript.types.ts +0 -19
  68. package/src/types/libs/datajs.types.ts +0 -29
  69. package/src/types/libs/exports-index.ts +0 -3
  70. package/src/types/libs/ics.types.ts +0 -31
  71. package/src/types/libs/msal.types.ts +0 -58
  72. package/src/types/locales.ts +0 -126
  73. package/src/types/localstoragecache.types.ts +0 -9
  74. package/src/types/location.types.ts +0 -28
  75. package/src/types/moment.ts +0 -12
  76. package/src/types/regex.types.ts +0 -17
  77. package/src/types/rest.types.ts +0 -96
  78. package/src/types/sharepoint.types.ts +0 -1467
  79. package/src/types/sharepoint.utils.types.ts +0 -307
  80. package/src/utils/auth/common.ts +0 -119
  81. package/src/utils/auth/discovery.test.js +0 -13
  82. package/src/utils/auth/discovery.ts +0 -132
  83. package/src/utils/auth/exports-index.ts +0 -2
  84. package/src/utils/base64.ts +0 -28
  85. package/src/utils/consolelogger.ts +0 -334
  86. package/src/utils/date.ts +0 -173
  87. package/src/utils/emails.ts +0 -25
  88. package/src/utils/exports-index.ts +0 -11
  89. package/src/utils/knownscript.ts +0 -287
  90. package/src/utils/localstoragecache.ts +0 -447
  91. package/src/utils/rest.ts +0 -502
  92. package/src/utils/script.ts +0 -171
  93. package/src/utils/sharepoint.rest/common.ts +0 -160
  94. package/src/utils/sharepoint.rest/date.ts +0 -63
  95. package/src/utils/sharepoint.rest/exports-index.ts +0 -11
  96. package/src/utils/sharepoint.rest/file.folder.ts +0 -685
  97. package/src/utils/sharepoint.rest/item.ts +0 -547
  98. package/src/utils/sharepoint.rest/list.ts +0 -1572
  99. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -775
  100. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -275
  101. package/src/utils/sharepoint.rest/listutils/common.ts +0 -207
  102. package/src/utils/sharepoint.rest/listutils/exports-index.ts +0 -3
  103. package/src/utils/sharepoint.rest/location.ts +0 -142
  104. package/src/utils/sharepoint.rest/navigation-links.ts +0 -87
  105. package/src/utils/sharepoint.rest/user-search.ts +0 -253
  106. package/src/utils/sharepoint.rest/user.ts +0 -559
  107. package/src/utils/sharepoint.rest/web.ts +0 -1385
  108. package/src/utils/sod.ts +0 -195
@@ -1,267 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
1
- import assert from 'assert/strict';
2
- import test from 'node:test';
3
- import { makeFullUrl, parseHash, parseQueryString, removeUrlKeyValue, setUrlKeyValue, } from './url';
4
-
5
- test('parseQueryString', t => {
6
- assert.deepEqual(parseQueryString(), {});
7
- assert.deepEqual(parseQueryString("http://foo"), {});
8
- assert.deepEqual(parseQueryString("http://foo?p1=1&p2=2"), { p1: '1', p2: '2' });
9
- assert.deepEqual(parseQueryString("http://foo?p1=1&p2=2#someAnchor"), { p1: '1', p2: '2' });
10
- });
11
- test('parseHash', t => {
12
- assert.deepEqual(parseHash(), {});
13
- assert.deepEqual(parseHash("http://foo"), {});
14
- assert.deepEqual(parseHash("http://foo?p1=1&p2=2"), {});
15
- assert.deepEqual(parseHash("http://foo?p1=1&p2=2#someAnchor"), { someAnchor: '' });
16
- assert.deepEqual(parseHash("http://foo?p1=3&p2=4#p1=1&p2=2"), { p1: '1', p2: '2' });
17
- assert.deepEqual(parseHash("http://foo#p1=1&p2=2"), { p1: '1', p2: '2' });
18
- });
19
-
20
- test('makeFullUrl', t => {
21
- assert.deepEqual(makeFullUrl("http://foo"), "http://foo");
22
- assert.deepEqual(makeFullUrl("http://foo", "http://fii"), "http://foo");
23
- assert.deepEqual(makeFullUrl("foo/fii", "http://host/folder"), "http://host/folder/foo/fii");
24
- assert.deepEqual(makeFullUrl("/foo/fii", "http://host"), "http://host/foo/fii");
25
- //fix # to full URL
26
- assert.deepEqual(makeFullUrl("#hashnav", "http://foo"), "http://foo#hashnav");
27
- assert.deepEqual(makeFullUrl("#hashnav2", "http://foo#hashnav"), "http://foo#hashnav2");
28
- assert.deepEqual(makeFullUrl("#hashnav", "http://foo/page.aspx"), "http://foo/page.aspx#hashnav");
29
- });
30
-
31
- test('removeUrlKeyValue', t => {
32
- let trueUrl = "https://www.domain.com/page.aspx?showindatasheet=true";
33
- let falseUrl = "https://www.domain.com/page.aspx?showindatasheet=false";
34
- let noParamUrl = "https://www.domain.com/page.aspx";
35
-
36
- let output = removeUrlKeyValue("showindatasheet", trueUrl, true);
37
- assert.deepEqual(output, noParamUrl);
38
-
39
- output = removeUrlKeyValue("ShowInDataSheet", trueUrl, true);
40
- assert.deepEqual(output, noParamUrl);
41
-
42
- output = setUrlKeyValue("showindatasheet", "false", false, trueUrl);
43
- assert.deepEqual(output, falseUrl)
44
- });
@@ -1,208 +0,0 @@
1
- import { IDictionary } from "../types/common.types";
2
- import { ArrayFill, lastOrNull } from "./collections.base";
3
- import { isNullOrEmptyString, isString } from "./typecheckers";
4
- import { URLHelper } from "./urlhelper";
5
-
6
- /**
7
- * Get query string parameter by name
8
- * @param name name of parameter
9
- * @param url optional, url. if not sent - current window.location.href will be used
10
- */
11
- export function getQueryStringParameter(param: string, url?: string, caseInSensitive = true) {
12
- let search = window.location.search;
13
- if (!isNullOrEmptyString(url)) {
14
- let tmp = url.split('#')[0].split('?');
15
- search = tmp.length > 1 ? tmp[1] : '';
16
- }
17
-
18
- return getParameterValue(param, search, caseInSensitive);
19
- }
20
- /**
21
- * Get url hash parameter by name
22
- * @param name name of parameter
23
- * @param url optional, url. if not sent - current window.location.href will be used
24
- */
25
- export function getHashParameter(param: string, url?: string, caseInSensitive = true) {
26
- let hash = window.location.hash;
27
- if (!isNullOrEmptyString(url)) {
28
- let tmp = url.split('#');
29
- hash = tmp.length > 1 ? tmp[1] : '';
30
- }
31
- return getParameterValue(param, hash, caseInSensitive);
32
- }
33
-
34
- /** return a value of a parameter from a key/value string like: key=value&key2=value2 */
35
- export function getParameterValue(param: string, keyValueString: string, caseInSensitive = true) {
36
- let _keyValueString = keyValueString.startsWith("#") || keyValueString.startsWith("?") ? keyValueString.substring(1) : keyValueString;
37
- let parsed = _keyValueString.split('&');
38
- for (var i = 0; i < parsed.length; i++) {
39
- let values = parsed[i].split('=');
40
-
41
- if (caseInSensitive ? values[0].toLowerCase() === param.toLowerCase() : values[0] === param) {
42
- let v = (values.length > 1 ? values[1] : param);
43
- return decodeURIComponent(v.replace(/\+/g, " "));
44
- }
45
-
46
- //ISSUE: 1301 - the query string parameter name was encoded in window.location.href/window.location.search even though in the
47
- //url bar the paramter name was not encoded
48
- if (caseInSensitive ? decodeURIComponent(values[0]).toLowerCase() === param.toLowerCase() : decodeURIComponent(values[0]) === param) {
49
- let v = (values.length > 1 ? values[1] : param);
50
- return decodeURIComponent(v.replace(/\+/g, " "));
51
- }
52
- }
53
- return "";
54
- }
55
-
56
- /**
57
- * Make full url relative to current page location
58
- * @param url
59
- */
60
- export function makeFullUrl(url: string, baseUrl?: string): string {
61
- if (isNullOrEmptyString(url)) url = baseUrl || window.location.href;
62
-
63
- if (url.indexOf('://') > 0) return url;
64
- else {
65
- if (url.startsWith('/') || url.startsWith('#')) {
66
- //server relative
67
- if (isNullOrEmptyString(baseUrl)) {//no override base
68
- let xxx = document.createElement("a");
69
- xxx.href = url;
70
- return xxx.href;
71
- }
72
- else//have override base
73
- {
74
- if (url.startsWith('#')) return `${baseUrl.split('#')[0]}${url}`;
75
- return `${baseUrl.split('/').slice(0, 3).join("/")}${url}`;
76
- }
77
- }
78
- else//folder relative URL, and we have a different baseURL to base it on
79
- {
80
- return makeFullUrl(makeServerRelativeUrl(url, baseUrl), baseUrl);
81
- }
82
- }
83
- }
84
-
85
- /** if the url is the same, only different hash parameter - reload the page. otherwise - navigate to the page */
86
- export function navigateOrReload(urlWithHash: string) {
87
- if (makeServerRelativeUrl(urlWithHash).split('#')[0].toLowerCase() === makeServerRelativeUrl(window.location.href).split('#')[0].toLowerCase())
88
- window.location.reload();//can't change hash - it won't refresh page
89
- else
90
- window.location.href = urlWithHash;
91
- }
92
-
93
- /** baseUrl is optional full or server relative URL to build folder relative urls from. */
94
- export function makeServerRelativeUrl(url: string, baseUrl?: string): string {
95
- if (isNullOrEmptyString(url)) url = baseUrl || window.location.href.split('?')[0];
96
-
97
- let index = url.indexOf("//");
98
- if (index > 0)//this is a full URL, just trim it from // until the first / and return.
99
- {
100
- index = url.indexOf("/", index + 2);//find next / after the ://domain.name
101
- if (index < 0) return "/";//not found - return "/" for the root.
102
- else return url.slice(index);//found - return from that "/" onwards.
103
- }
104
- else if (url.startsWith('/'))//server relative url already
105
- return url;
106
- else//folder relative url
107
- {
108
- let baseRelativeUrl = makeServerRelativeUrl(baseUrl || window.location.href);
109
- baseRelativeUrl = baseRelativeUrl.split('?')[0];
110
- //if ends with file name - strip it
111
- if (lastOrNull(baseRelativeUrl.split('/')).indexOf('.') >= 0)
112
- baseRelativeUrl = baseRelativeUrl.substr(0, baseRelativeUrl.lastIndexOf('/'));
113
- return normalizeUrl(baseRelativeUrl, true) + url;
114
- }
115
- }
116
-
117
- /** Normalizes URL ending, end with or without slash */
118
- export function normalizeUrl(url: string, endWithSlash = false): string {
119
- let tmp = url;
120
- if (endWithSlash) {
121
- if (isNullOrEmptyString(tmp))
122
- tmp = "/";
123
- else if (tmp.substr(-1) !== "/")
124
- tmp += "/";
125
- }
126
- else {
127
- if (!isNullOrEmptyString(tmp) && tmp.endsWith('/'))
128
- tmp = tmp.slice(0, url.length - 1);
129
- }
130
- return tmp;
131
- }
132
-
133
- /**
134
- * Returns the extension for a specified url string. Requires the URL polyfill for IE.
135
- */
136
- export function getURLExtension(url: string) {//, baseUri?: string) {
137
- if (!isString(url)) {
138
- return "";
139
- }
140
- //if (!isString(baseUri)) {
141
- // baseUri = document.baseURI || window.location.protocol + "://" + window.location.hostname + window.location.pathname;
142
- //}
143
- let urlObj = new URL(url, "https://example.com");
144
- url = urlObj.href.replace(urlObj.host, "").replace(urlObj.hash, "").replace(urlObj.search, "");
145
- return url.substring(url.lastIndexOf("/") + 1).split(/#|\?/)[0].split(".").pop().trim();
146
- }
147
-
148
- export function isDataUrl(url: string) {
149
- let REGEXP_DATA_URL = /^data:(?:.+?\/.+?)?(?:;.+?=.+?)*(?:;base64)?,.*$/;
150
- return REGEXP_DATA_URL.test(url);
151
- }
152
-
153
- export function setUrlKeyValue(keyName: string, keyValue: string, bEncode: boolean, url?: string) {
154
- if (!isString(url)) {
155
- url = window.location.href + "";
156
- }
157
-
158
- let urlParams = new URLHelper(url);
159
- return urlParams.setQueryStringParam(keyName, keyValue, bEncode);
160
- }
161
-
162
- export function removeUrlKeyValue(keyName: string, url?: string, bCaseInsensitive?: boolean) {
163
- if (!isString(url)) {
164
- url = window.location.href + "";
165
- }
166
-
167
- let urlParams = new URLHelper(url);
168
- return urlParams.removeQueryStringParam(keyName, bCaseInsensitive);
169
- }
170
-
171
- /**
172
- * Returns encoded string from encodeURIComponent with single quote replaced with %27 or %27%27
173
- */
174
- export function encodeURIComponentEX(str, options?: {
175
- /** use this flag when making a REST requst, and encoding a parameter surrounded by 'param'
176
- * for each level of '' your param is sorounded with
177
- * example: filename('par'am') > send 2 to make it filename('par''am')
178
- * example 2: sheet(' ''par'am'' ') > send 4 to make it sheet(' ''par''''am'' ')
179
- */
180
- singleQuoteMultiplier?: number;
181
- }) {
182
- return encodeURIComponent(str).replace(/'/g, (s) => {
183
- return options && options.singleQuoteMultiplier > 1
184
- ? ArrayFill(new Array(options.singleQuoteMultiplier), "%27").join('')
185
- : `%27`;
186
- });
187
- }
188
-
189
- export function parseQueryString(url: string): IDictionary<string> {
190
- if (isNullOrEmptyString(url) || url.indexOf('?') < 0) return {};
191
- let strParams = url.split('?')[1].split('#')[0].split('&');
192
- let params: IDictionary<string> = {};
193
- strParams.forEach(p => {
194
- let keyValue = p.split("=");
195
- params[keyValue[0]] = decodeURIComponent(keyValue[1] || "");
196
- });
197
- return params;
198
- }
199
- export function parseHash(url: string): IDictionary<string> {
200
- if (isNullOrEmptyString(url) || url.indexOf('#') < 0) return {};
201
- let strParams = url.split('#')[1].split('&');
202
- let params: IDictionary<string> = {};
203
- strParams.forEach(p => {
204
- let keyValue = p.split("=");
205
- params[keyValue[0]] = decodeURIComponent(keyValue[1] || "");
206
- });
207
- return params;
208
- }
@@ -1,112 +0,0 @@
1
- export class URLHelper {
2
- private queryStringParams: { [key: string]: string; };
3
- private hashParams: { [key: string]: string; };
4
- private path: string;
5
-
6
- public constructor(url: string) {
7
- let parts = url.split("#");
8
- let pathAndQueryString = parts[0];
9
- let hash = parts[1];
10
- let parts2 = pathAndQueryString.split("?");
11
- let path = parts2[0];
12
- let queryString = parts2[1];
13
-
14
- this.path = path;
15
- this.queryStringParams = this._parseParams(queryString);
16
- this.hashParams = this._parseParams(hash);
17
- }
18
-
19
- public getQueryStringParam(keyName: string, bNoDecode?: boolean, bCaseInsensitive?: boolean) {
20
- return this._getParam(this.queryStringParams, keyName, bNoDecode, bCaseInsensitive);
21
- }
22
-
23
- public setQueryStringParam(keyName: string, keyValue: string, bEncode: boolean) {
24
- this.queryStringParams[keyName] = bEncode ? encodeURIComponent(keyValue) : keyValue;
25
- return this.getUrl();
26
- }
27
-
28
- public removeQueryStringParam(keyName: string, bCaseInsensitive?: boolean) {
29
- this._removeParam(this.queryStringParams, keyName, bCaseInsensitive);
30
- return this.getUrl();
31
- }
32
-
33
- public getHashParam(keyName: string, bNoDecode?: boolean, bCaseInsensitive?: boolean) {
34
- return this._getParam(this.hashParams, keyName, bNoDecode, bCaseInsensitive);
35
- }
36
-
37
- public setHashParam(keyName: string, keyValue: string, bEncode: boolean) {
38
- this.hashParams[keyName] = bEncode ? encodeURIComponent(keyValue) : keyValue;
39
- return this.getUrl();
40
- }
41
-
42
- public removeHashParam(keyName: string) {
43
- this._removeParam(this.hashParams, keyName);
44
- return this.getUrl();
45
- }
46
-
47
- private _parseParams(paramsAsString: string) {
48
- var paramsDict: { [key: string]: string; } = {};
49
- try {
50
- (typeof (paramsAsString) === "string" && paramsAsString.length ? paramsAsString.split("&") : []).forEach((s) => {
51
- let q = s.split("=");
52
- let paramKey = decodeURIComponent(q[0]);
53
- let paramValue = q[1];
54
- if (typeof (paramKey) === "string" && paramKey.length) {
55
- paramsDict[paramKey] = typeof (paramValue) === "string" && paramValue.length ? paramValue : null;
56
- }
57
- });
58
- } catch (ex) {
59
- }
60
- return paramsDict;
61
- }
62
-
63
- private _removeParam(obj: { [key: string]: string; }, keyName: string, bCaseInsensitive?: boolean) {
64
- if (!obj) {
65
- return;
66
- }
67
- Object.keys(obj).filter((key) => {
68
- if (bCaseInsensitive === true) {
69
- return key.toLowerCase() === keyName.toLowerCase();
70
- }
71
- return key === keyName;
72
- }).forEach((key) => {
73
- try {
74
- delete obj[key];
75
- } catch {
76
- }
77
- });
78
- }
79
-
80
- private _getParam(obj: { [key: string]: string; }, keyName: string, bNoDecode?: boolean, bCaseInsensitive?: boolean) {
81
- let value: string = null;
82
- if (bCaseInsensitive) {
83
- let matchedKey = Object.keys(obj).filter((key) => {
84
- return key.toLowerCase() === keyName.toLowerCase();
85
- })[0];
86
-
87
- if (matchedKey) {
88
- value = obj[matchedKey];
89
- }
90
- } else {
91
- value = obj[keyName];
92
- }
93
- return typeof (value) === "string" ? (bNoDecode ? value : decodeURIComponent(value)) : null;
94
- }
95
-
96
- public getUrl() {
97
- let queryString = Object.keys(this.queryStringParams).map((key) => {
98
- let value = this.queryStringParams[key];
99
- return `${key}` + (value !== null ? `=${value}` : "");
100
- });
101
- let hash = Object.keys(this.hashParams).map((key) => {
102
- var value = this.hashParams[key];
103
- return `${key}` + (value !== null ? `=${value}` : "");
104
- });
105
- let newUrl = [
106
- typeof (this.path) === "string" && this.path.length ? this.path : "",
107
- queryString && queryString.length ? `?${queryString.join("&")}` : "",
108
- hash && hash.length ? `#${hash.join("&")}` : ""
109
- ];
110
- return newUrl.join("");
111
- }
112
- }
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import { default as _script } from "./utils/script";
2
- import { default as _sod } from "./utils/sod";
3
- export * from './exports-index';
4
- export const script = _script;
5
- export const Sod = _sod;
6
-