@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,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
  }