@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,44 +1,44 @@
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)
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
44
  });
@@ -1,208 +1,208 @@
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;
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
208
  }