@kwiz/common 1.0.1

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 (310) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_dependencies.d.ts +1 -0
  3. package/dist/_dependencies.js +8 -0
  4. package/dist/_dependencies.js.map +1 -0
  5. package/dist/helpers/Guid.d.ts +119 -0
  6. package/dist/helpers/Guid.js +183 -0
  7. package/dist/helpers/Guid.js.map +1 -0
  8. package/dist/helpers/_dependencies.d.ts +2 -0
  9. package/dist/helpers/_dependencies.js +21 -0
  10. package/dist/helpers/_dependencies.js.map +1 -0
  11. package/dist/helpers/base64.d.ts +8 -0
  12. package/dist/helpers/base64.js +178 -0
  13. package/dist/helpers/base64.js.map +1 -0
  14. package/dist/helpers/browser.d.ts +144 -0
  15. package/dist/helpers/browser.js +1200 -0
  16. package/dist/helpers/browser.js.map +1 -0
  17. package/dist/helpers/browserinfo.d.ts +23 -0
  18. package/dist/helpers/browserinfo.js +215 -0
  19. package/dist/helpers/browserinfo.js.map +1 -0
  20. package/dist/helpers/collections.base.d.ts +128 -0
  21. package/dist/helpers/collections.base.js +430 -0
  22. package/dist/helpers/collections.base.js.map +1 -0
  23. package/dist/helpers/collections.d.ts +18 -0
  24. package/dist/helpers/collections.js +99 -0
  25. package/dist/helpers/collections.js.map +1 -0
  26. package/dist/helpers/color.d.ts +11 -0
  27. package/dist/helpers/color.js +57 -0
  28. package/dist/helpers/color.js.map +1 -0
  29. package/dist/helpers/cookies.d.ts +6 -0
  30. package/dist/helpers/cookies.js +56 -0
  31. package/dist/helpers/cookies.js.map +1 -0
  32. package/dist/helpers/date.d.ts +43 -0
  33. package/dist/helpers/date.js +158 -0
  34. package/dist/helpers/date.js.map +1 -0
  35. package/dist/helpers/debug.d.ts +33 -0
  36. package/dist/helpers/debug.js +177 -0
  37. package/dist/helpers/debug.js.map +1 -0
  38. package/dist/helpers/emails.d.ts +2 -0
  39. package/dist/helpers/emails.js +10 -0
  40. package/dist/helpers/emails.js.map +1 -0
  41. package/dist/helpers/eval.d.ts +1 -0
  42. package/dist/helpers/eval.js +10 -0
  43. package/dist/helpers/eval.js.map +1 -0
  44. package/dist/helpers/file.d.ts +11 -0
  45. package/dist/helpers/file.js +55 -0
  46. package/dist/helpers/file.js.map +1 -0
  47. package/dist/helpers/flatted.d.ts +20 -0
  48. package/dist/helpers/flatted.js +135 -0
  49. package/dist/helpers/flatted.js.map +1 -0
  50. package/dist/helpers/functions.d.ts +4 -0
  51. package/dist/helpers/functions.js +17 -0
  52. package/dist/helpers/functions.js.map +1 -0
  53. package/dist/helpers/graph/calendar.types.d.ts +3 -0
  54. package/dist/helpers/graph/calendar.types.js +15 -0
  55. package/dist/helpers/graph/calendar.types.js.map +1 -0
  56. package/dist/helpers/http.d.ts +25 -0
  57. package/dist/helpers/http.js +70 -0
  58. package/dist/helpers/http.js.map +1 -0
  59. package/dist/helpers/images.d.ts +16 -0
  60. package/dist/helpers/images.js +21 -0
  61. package/dist/helpers/images.js.map +1 -0
  62. package/dist/helpers/index.d.ts +29 -0
  63. package/dist/helpers/index.js +46 -0
  64. package/dist/helpers/index.js.map +1 -0
  65. package/dist/helpers/json.d.ts +3 -0
  66. package/dist/helpers/json.js +44 -0
  67. package/dist/helpers/json.js.map +1 -0
  68. package/dist/helpers/md5.d.ts +5 -0
  69. package/dist/helpers/md5.js +172 -0
  70. package/dist/helpers/md5.js.map +1 -0
  71. package/dist/helpers/objects.d.ts +49 -0
  72. package/dist/helpers/objects.js +271 -0
  73. package/dist/helpers/objects.js.map +1 -0
  74. package/dist/helpers/promises.d.ts +14 -0
  75. package/dist/helpers/promises.js +112 -0
  76. package/dist/helpers/promises.js.map +1 -0
  77. package/dist/helpers/random.d.ts +2 -0
  78. package/dist/helpers/random.js +32 -0
  79. package/dist/helpers/random.js.map +1 -0
  80. package/dist/helpers/scheduler/scheduler.d.ts +39 -0
  81. package/dist/helpers/scheduler/scheduler.js +109 -0
  82. package/dist/helpers/scheduler/scheduler.js.map +1 -0
  83. package/dist/helpers/sharepoint.d.ts +112 -0
  84. package/dist/helpers/sharepoint.js +629 -0
  85. package/dist/helpers/sharepoint.js.map +1 -0
  86. package/dist/helpers/strings.d.ts +56 -0
  87. package/dist/helpers/strings.js +282 -0
  88. package/dist/helpers/strings.js.map +1 -0
  89. package/dist/helpers/typecheckers.d.ts +56 -0
  90. package/dist/helpers/typecheckers.js +274 -0
  91. package/dist/helpers/typecheckers.js.map +1 -0
  92. package/dist/helpers/url.d.ts +46 -0
  93. package/dist/helpers/url.js +199 -0
  94. package/dist/helpers/url.js.map +1 -0
  95. package/dist/helpers/urlhelper.d.ts +16 -0
  96. package/dist/helpers/urlhelper.js +96 -0
  97. package/dist/helpers/urlhelper.js.map +1 -0
  98. package/dist/index.d.ts +15 -0
  99. package/dist/index.js +37 -0
  100. package/dist/index.js.map +1 -0
  101. package/dist/types/common.types.d.ts +19 -0
  102. package/dist/types/common.types.js +4 -0
  103. package/dist/types/common.types.js.map +1 -0
  104. package/dist/types/flatted.types.d.ts +49 -0
  105. package/dist/types/flatted.types.js +3 -0
  106. package/dist/types/flatted.types.js.map +1 -0
  107. package/dist/types/globals.types.d.ts +6 -0
  108. package/dist/types/globals.types.js +3 -0
  109. package/dist/types/globals.types.js.map +1 -0
  110. package/dist/types/graph/calendar.types.d.ts +79 -0
  111. package/dist/types/graph/calendar.types.js +3 -0
  112. package/dist/types/graph/calendar.types.js.map +1 -0
  113. package/dist/types/graph/index.d.ts +1 -0
  114. package/dist/types/graph/index.js +18 -0
  115. package/dist/types/graph/index.js.map +1 -0
  116. package/dist/types/index.d.ts +11 -0
  117. package/dist/types/index.js +28 -0
  118. package/dist/types/index.js.map +1 -0
  119. package/dist/types/knownscript.types.d.ts +22 -0
  120. package/dist/types/knownscript.types.js +3 -0
  121. package/dist/types/knownscript.types.js.map +1 -0
  122. package/dist/types/libs/datajs.types.d.ts +29 -0
  123. package/dist/types/libs/datajs.types.js +3 -0
  124. package/dist/types/libs/datajs.types.js.map +1 -0
  125. package/dist/types/libs/ics.types.d.ts +29 -0
  126. package/dist/types/libs/ics.types.js +3 -0
  127. package/dist/types/libs/ics.types.js.map +1 -0
  128. package/dist/types/libs/index.d.ts +3 -0
  129. package/dist/types/libs/index.js +20 -0
  130. package/dist/types/libs/index.js.map +1 -0
  131. package/dist/types/libs/msal.types.d.ts +33 -0
  132. package/dist/types/libs/msal.types.js +63 -0
  133. package/dist/types/libs/msal.types.js.map +1 -0
  134. package/dist/types/locales.d.ts +122 -0
  135. package/dist/types/locales.js +1 -0
  136. package/dist/types/locales.js.map +1 -0
  137. package/dist/types/localstoragecache.types.d.ts +8 -0
  138. package/dist/types/localstoragecache.types.js +3 -0
  139. package/dist/types/localstoragecache.types.js.map +1 -0
  140. package/dist/types/moment.d.ts +6 -0
  141. package/dist/types/moment.js +1 -0
  142. package/dist/types/moment.js.map +1 -0
  143. package/dist/types/regex.types.d.ts +14 -0
  144. package/dist/types/regex.types.js +3 -0
  145. package/dist/types/regex.types.js.map +1 -0
  146. package/dist/types/rest.types.d.ts +81 -0
  147. package/dist/types/rest.types.js +24 -0
  148. package/dist/types/rest.types.js.map +1 -0
  149. package/dist/types/sharepoint.types.d.ts +1432 -0
  150. package/dist/types/sharepoint.types.js +629 -0
  151. package/dist/types/sharepoint.types.js.map +1 -0
  152. package/dist/types/sharepoint.utils.types.d.ts +246 -0
  153. package/dist/types/sharepoint.utils.types.js +26 -0
  154. package/dist/types/sharepoint.utils.types.js.map +1 -0
  155. package/dist/utils/_dependencies.d.ts +3 -0
  156. package/dist/utils/_dependencies.js +24 -0
  157. package/dist/utils/_dependencies.js.map +1 -0
  158. package/dist/utils/base64.d.ts +2 -0
  159. package/dist/utils/base64.js +41 -0
  160. package/dist/utils/base64.js.map +1 -0
  161. package/dist/utils/consolelogger.d.ts +73 -0
  162. package/dist/utils/consolelogger.js +281 -0
  163. package/dist/utils/consolelogger.js.map +1 -0
  164. package/dist/utils/date.d.ts +10 -0
  165. package/dist/utils/date.js +30 -0
  166. package/dist/utils/date.js.map +1 -0
  167. package/dist/utils/emails.d.ts +2 -0
  168. package/dist/utils/emails.js +24 -0
  169. package/dist/utils/emails.js.map +1 -0
  170. package/dist/utils/index.d.ts +13 -0
  171. package/dist/utils/index.js +31 -0
  172. package/dist/utils/index.js.map +1 -0
  173. package/dist/utils/knownscript.d.ts +99 -0
  174. package/dist/utils/knownscript.js +261 -0
  175. package/dist/utils/knownscript.js.map +1 -0
  176. package/dist/utils/localstoragecache.d.ts +19 -0
  177. package/dist/utils/localstoragecache.js +372 -0
  178. package/dist/utils/localstoragecache.js.map +1 -0
  179. package/dist/utils/rest.d.ts +17 -0
  180. package/dist/utils/rest.js +402 -0
  181. package/dist/utils/rest.js.map +1 -0
  182. package/dist/utils/script.d.ts +33 -0
  183. package/dist/utils/script.js +169 -0
  184. package/dist/utils/script.js.map +1 -0
  185. package/dist/utils/sharepoint.rest/common.d.ts +32 -0
  186. package/dist/utils/sharepoint.rest/common.js +146 -0
  187. package/dist/utils/sharepoint.rest/common.js.map +1 -0
  188. package/dist/utils/sharepoint.rest/date.d.ts +2 -0
  189. package/dist/utils/sharepoint.rest/date.js +57 -0
  190. package/dist/utils/sharepoint.rest/date.js.map +1 -0
  191. package/dist/utils/sharepoint.rest/file.folder.d.ts +58 -0
  192. package/dist/utils/sharepoint.rest/file.folder.js +305 -0
  193. package/dist/utils/sharepoint.rest/file.folder.js.map +1 -0
  194. package/dist/utils/sharepoint.rest/index.d.ts +11 -0
  195. package/dist/utils/sharepoint.rest/index.js +28 -0
  196. package/dist/utils/sharepoint.rest/index.js.map +1 -0
  197. package/dist/utils/sharepoint.rest/item.d.ts +81 -0
  198. package/dist/utils/sharepoint.rest/item.js +444 -0
  199. package/dist/utils/sharepoint.rest/item.js.map +1 -0
  200. package/dist/utils/sharepoint.rest/list.d.ts +228 -0
  201. package/dist/utils/sharepoint.rest/list.js +868 -0
  202. package/dist/utils/sharepoint.rest/list.js.map +1 -0
  203. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.d.ts +19 -0
  204. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +629 -0
  205. package/dist/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -0
  206. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.d.ts +14 -0
  207. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js +222 -0
  208. package/dist/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -0
  209. package/dist/utils/sharepoint.rest/listutils/common.d.ts +3 -0
  210. package/dist/utils/sharepoint.rest/listutils/common.js +198 -0
  211. package/dist/utils/sharepoint.rest/listutils/common.js.map +1 -0
  212. package/dist/utils/sharepoint.rest/user-search.d.ts +76 -0
  213. package/dist/utils/sharepoint.rest/user-search.js +239 -0
  214. package/dist/utils/sharepoint.rest/user-search.js.map +1 -0
  215. package/dist/utils/sharepoint.rest/user.d.ts +71 -0
  216. package/dist/utils/sharepoint.rest/user.js +404 -0
  217. package/dist/utils/sharepoint.rest/user.js.map +1 -0
  218. package/dist/utils/sharepoint.rest/web.d.ts +107 -0
  219. package/dist/utils/sharepoint.rest/web.js +929 -0
  220. package/dist/utils/sharepoint.rest/web.js.map +1 -0
  221. package/dist/utils/sod.d.ts +29 -0
  222. package/dist/utils/sod.js +177 -0
  223. package/dist/utils/sod.js.map +1 -0
  224. package/package.json +60 -0
  225. package/readme.md +13 -0
  226. package/src/_dependencies.ts +2 -0
  227. package/src/helpers/Guid.ts +182 -0
  228. package/src/helpers/_dependencies.ts +3 -0
  229. package/src/helpers/base64.ts +174 -0
  230. package/src/helpers/browser.test.js +9 -0
  231. package/src/helpers/browser.ts +1299 -0
  232. package/src/helpers/browserinfo.ts +293 -0
  233. package/src/helpers/collections.base.test.js +26 -0
  234. package/src/helpers/collections.base.ts +439 -0
  235. package/src/helpers/collections.ts +108 -0
  236. package/src/helpers/color.ts +55 -0
  237. package/src/helpers/cookies.ts +55 -0
  238. package/src/helpers/date.test.js +97 -0
  239. package/src/helpers/date.ts +163 -0
  240. package/src/helpers/debug.ts +187 -0
  241. package/src/helpers/emails.ts +7 -0
  242. package/src/helpers/eval.ts +5 -0
  243. package/src/helpers/file.test.js +51 -0
  244. package/src/helpers/file.ts +59 -0
  245. package/src/helpers/flatted.ts +150 -0
  246. package/src/helpers/functions.ts +17 -0
  247. package/src/helpers/graph/calendar.types.ts +11 -0
  248. package/src/helpers/http.ts +70 -0
  249. package/src/helpers/images.ts +23 -0
  250. package/src/helpers/index.ts +29 -0
  251. package/src/helpers/json.ts +39 -0
  252. package/src/helpers/md5.ts +190 -0
  253. package/src/helpers/objects.test.js +27 -0
  254. package/src/helpers/objects.ts +256 -0
  255. package/src/helpers/promises.test.js +18 -0
  256. package/src/helpers/promises.ts +102 -0
  257. package/src/helpers/random.ts +27 -0
  258. package/src/helpers/scheduler/scheduler.test.js +104 -0
  259. package/src/helpers/scheduler/scheduler.ts +132 -0
  260. package/src/helpers/sharepoint.ts +681 -0
  261. package/src/helpers/strings.test.js +43 -0
  262. package/src/helpers/strings.ts +288 -0
  263. package/src/helpers/typecheckers.test.js +35 -0
  264. package/src/helpers/typecheckers.ts +263 -0
  265. package/src/helpers/url.test.js +18 -0
  266. package/src/helpers/url.ts +202 -0
  267. package/src/helpers/urlhelper.ts +104 -0
  268. package/src/index.ts +24 -0
  269. package/src/types/common.types.ts +16 -0
  270. package/src/types/flatted.types.ts +60 -0
  271. package/src/types/globals.types.ts +7 -0
  272. package/src/types/graph/calendar.types.ts +81 -0
  273. package/src/types/graph/index.ts +1 -0
  274. package/src/types/index.ts +12 -0
  275. package/src/types/knownscript.types.ts +19 -0
  276. package/src/types/libs/datajs.types.ts +29 -0
  277. package/src/types/libs/ics.types.ts +31 -0
  278. package/src/types/libs/index.ts +4 -0
  279. package/src/types/libs/msal.types.ts +79 -0
  280. package/src/types/locales.ts +125 -0
  281. package/src/types/localstoragecache.types.ts +9 -0
  282. package/src/types/moment.ts +7 -0
  283. package/src/types/regex.types.ts +17 -0
  284. package/src/types/rest.types.ts +94 -0
  285. package/src/types/sharepoint.types.ts +1413 -0
  286. package/src/types/sharepoint.utils.types.ts +246 -0
  287. package/src/utils/_dependencies.ts +4 -0
  288. package/src/utils/base64.ts +27 -0
  289. package/src/utils/consolelogger.ts +315 -0
  290. package/src/utils/date.ts +36 -0
  291. package/src/utils/emails.ts +25 -0
  292. package/src/utils/index.ts +13 -0
  293. package/src/utils/knownscript.ts +280 -0
  294. package/src/utils/localstoragecache.ts +419 -0
  295. package/src/utils/rest.ts +465 -0
  296. package/src/utils/script.ts +168 -0
  297. package/src/utils/sharepoint.rest/common.ts +149 -0
  298. package/src/utils/sharepoint.rest/date.ts +61 -0
  299. package/src/utils/sharepoint.rest/file.folder.ts +368 -0
  300. package/src/utils/sharepoint.rest/index.ts +11 -0
  301. package/src/utils/sharepoint.rest/item.ts +456 -0
  302. package/src/utils/sharepoint.rest/list.ts +1144 -0
  303. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +750 -0
  304. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +265 -0
  305. package/src/utils/sharepoint.rest/listutils/common.ts +202 -0
  306. package/src/utils/sharepoint.rest/user-search.ts +254 -0
  307. package/src/utils/sharepoint.rest/user.ts +447 -0
  308. package/src/utils/sharepoint.rest/web.ts +1031 -0
  309. package/src/utils/sod.ts +193 -0
  310. package/tsconfig.json +21 -0
@@ -0,0 +1,97 @@
1
+ import assert from 'assert/strict';
2
+ import test from 'node:test';
3
+ import { shiftMonths, getTotalDaysInMonth, getDateFromToken, isISODate, isISODateUTC, isNowToken, isStandardDate, isTodayToken } from "./date";
4
+
5
+ test('isTodayToken', t => {
6
+ assert.strictEqual(isTodayToken(''), false);
7
+ assert.strictEqual(isTodayToken('today'), false);
8
+ assert.strictEqual(isTodayToken('[ to day]'), false);
9
+ assert.strictEqual(isTodayToken('[today ]'), false);
10
+ assert.strictEqual(isTodayToken('asd[today]'), false);
11
+ assert.strictEqual(isTodayToken('[today]adsd'), true);
12
+ assert.strictEqual(isTodayToken('[today] asd'), true);
13
+ assert.strictEqual(isTodayToken('[today]'), true);
14
+ });
15
+
16
+ test('isNowToken', t => {
17
+ assert.strictEqual(isNowToken(''), false);
18
+ assert.strictEqual(isNowToken('now'), false);
19
+ assert.strictEqual(isNowToken('[ now]'), false);
20
+ assert.strictEqual(isNowToken('[now ]'), false);
21
+ assert.strictEqual(isNowToken('asd[now]'), false);
22
+ assert.strictEqual(isNowToken('[now]adsd'), true);
23
+ assert.strictEqual(isNowToken('[now] asd'), true);
24
+ assert.strictEqual(isNowToken('[now]'), true);
25
+ });
26
+
27
+ test('getDateFromToken', t => {
28
+ let now = new Date();
29
+ assert.strictEqual(getDateFromToken('[today]+1', { now: now }).getTime(), (now.getTime() + (24 * 60 * 60 * 1000)));
30
+ assert.strictEqual(getDateFromToken('[today]-1', { now: now }).getTime(), (now.getTime() + (-24 * 60 * 60 * 1000)));
31
+ assert.strictEqual(getDateFromToken('[now]+15', { now: now }).getTime(), (now.getTime() + (+15 * 60 * 1000)));
32
+ assert.strictEqual(getDateFromToken('[now]-15', { now: now }).getTime(), (now.getTime() + (-15 * 60 * 1000)));
33
+
34
+ let test = new Date(now.getTime());
35
+ test.setHours(0, 0, 0, 0);
36
+ assert.strictEqual(getDateFromToken('[today]+1', { now: now, zeroTimeForToday: true }).getTime(), (test.getTime() + (24 * 60 * 60 * 1000)));
37
+ assert.strictEqual(getDateFromToken('[today]-1', { now: now, zeroTimeForToday: true }).getTime(), (test.getTime() + (-24 * 60 * 60 * 1000)));
38
+
39
+ });
40
+
41
+ test('isStandardDate', t => {
42
+ assert.strictEqual(isStandardDate(''), false);
43
+ assert.strictEqual(isStandardDate('2023-08-21T15:54:14.954Z'), false);
44
+ assert.strictEqual(isStandardDate('2023-08-21T15:54:14.954'), false);
45
+ assert.strictEqual(isStandardDate('2023-08-21T15:54:14Z'), false);
46
+ assert.strictEqual(isStandardDate('2023-08-21T15:54:14'), false);
47
+ assert.strictEqual(isStandardDate('2023-08-21T15:54'), true);
48
+ });
49
+
50
+ test('isISODate', t => {
51
+ assert.strictEqual(isISODate(''), false);
52
+ assert.strictEqual(isISODate('2023-08-21T15:54:14.954Z'), true);
53
+ assert.strictEqual(isISODate('2023-08-21T15:54:14.954'), true);
54
+ assert.strictEqual(isISODate('2023-08-21T15:54:14Z'), true);
55
+ assert.strictEqual(isISODate('2023-08-21T15:54:14'), true);
56
+ assert.strictEqual(isISODate('2023-08-21T15:54'), false);
57
+ });
58
+
59
+ test('isISODateUTC', t => {
60
+ assert.strictEqual(isISODateUTC(''), false);
61
+ assert.strictEqual(isISODateUTC('2023-08-21T15:54:14.954Z'), true);
62
+ assert.strictEqual(isISODateUTC('2023-08-21T15:54:14.954'), false);
63
+ assert.strictEqual(isISODateUTC('2023-08-21T15:54:14Z'), true);
64
+ assert.strictEqual(isISODateUTC('2023-08-21T15:54:14'), false);
65
+ assert.strictEqual(isISODateUTC('2023-08-21T15:54'), false);
66
+ });
67
+
68
+ test('getTotalDaysInMonth', t => {
69
+ var d = new Date("01-01-2023");
70
+ assert.strictEqual(getTotalDaysInMonth(d), 31);
71
+
72
+ d = new Date("09-01-2023");
73
+ assert.strictEqual(getTotalDaysInMonth(d), 30);
74
+
75
+ d = new Date("02-01-2023");
76
+ assert.strictEqual(getTotalDaysInMonth(d), 28);
77
+
78
+ d = new Date("02-01-2024"); //leap year
79
+ assert.strictEqual(getTotalDaysInMonth(d), 29);
80
+ });
81
+
82
+ test('shiftMonths', t => {
83
+ var d = new Date("01-31-2023");
84
+ shiftMonths(d, 1)
85
+ assert.strictEqual(d.getMonth() + 1, 2);
86
+ assert.strictEqual(d.getDate(), 28);
87
+
88
+ d = new Date("01-31-2023");
89
+ shiftMonths(d, 13)
90
+ assert.strictEqual(d.getMonth() + 1, 2);
91
+ assert.strictEqual(d.getDate(), 29); //leap year
92
+
93
+ d = new Date("01-31-2023");
94
+ shiftMonths(d, -11)
95
+ assert.strictEqual(d.getMonth() + 1, 2);
96
+ assert.strictEqual(d.getDate(), 28);
97
+ });
@@ -0,0 +1,163 @@
1
+ /**
2
+ * a date helper that is not relying on SharePoint or any utils at all
3
+ * can be synced to the server code and external projects
4
+ * do not add code that needs SP or utils -> move it to utils/date
5
+ */
6
+
7
+ import { endsWith } from "./strings";
8
+ import { isDate, isNullOrUndefined, isString } from "./typecheckers";
9
+
10
+ export function isISODateUTC(d: string) {
11
+ //2023-08-21T15:54:14.954Z = true
12
+ //2023-08-21T15:54:14.954 = false
13
+ //2023-08-21T15:54:14Z = true
14
+ //2023-08-21T15:54:14 = false
15
+ //2023-08-21T15:54 = false
16
+ return isISODate(d) && endsWith(d, "Z", true);
17
+ }
18
+
19
+ export function isISODate(d: string) {
20
+ //2023-08-21T15:54:14.954Z = true
21
+ //2023-08-21T15:54:14.954 = true
22
+ //2023-08-21T15:54:14Z = true
23
+ //2023-08-21T15:54:14 = true
24
+ //2023-08-21T15:54 = false
25
+ return isString(d) && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/.test(d);
26
+ }
27
+
28
+ export function isStandardDate(d: string) {
29
+ //2023-08-21T15:54:14.954Z = false
30
+ //2023-08-21T15:54:14.954 = false
31
+ //2023-08-21T15:54:14Z = false
32
+ //2023-08-21T15:54:14 = false
33
+ //2023-08-21T15:54 = true
34
+ return isString(d) && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.test(d);
35
+ }
36
+
37
+ export function parseISODate(a: string): Date | null {
38
+ if (!Date.prototype.toISOString) {
39
+ if (a.length < 19) {
40
+ return null;
41
+ }
42
+ var i = Number(a.substr(0, 4)),
43
+ f = Number(a.substr(5, 2)),
44
+ d = Number(a.substr(8, 2)),
45
+ h = Number(a.substr(11, 2)),
46
+ e = Number(a.substr(14, 2)),
47
+ g = Number(a.substr(17, 2));
48
+ if (isNaN(i) || isNaN(f) || isNaN(d) || isNaN(h) || isNaN(e) || isNaN(g)) {
49
+ return null;
50
+ }
51
+ // b = new Date(Date.UTC(i, f - 1, d, h, e, g));
52
+ return new Date(Date.UTC(i, f - 1, d, h, e, g));
53
+ } else {
54
+ return new Date(a);
55
+ }
56
+ }
57
+
58
+ /** Get now date, without seconds or milliseconds. */
59
+ export function getNow() {
60
+ let now = new Date();
61
+ now.setSeconds(0, 0);
62
+ return now;
63
+ }
64
+ /** Get today date, without hours, minutes, seconds or milliseconds. */
65
+ export function getToday() {
66
+ let today = new Date();
67
+ today.setHours(0, 0, 0, 0);
68
+ return today;
69
+ }
70
+
71
+ // eslint-disable-next-line no-shadow
72
+ export enum DateFormats {
73
+ YMD = "yyyy-MM-dd"
74
+ }
75
+ export function changeDate(options: { years?: number; months?: number; days?: number; hours?: number; minutes?: number; }, startDate?: Date): Date {
76
+ let newDate = isDate(startDate) ? new Date(startDate.getTime()) : new Date();//today, or the day that was passed
77
+
78
+ if (options) {
79
+ if (!isNullOrUndefined(options.years))
80
+ newDate.setFullYear(newDate.getFullYear() + options.years);
81
+
82
+ if (!isNullOrUndefined(options.months))
83
+ newDate.setMonth(newDate.getMonth() + options.months);
84
+
85
+ if (!isNullOrUndefined(options.days))
86
+ options.hours = (isNullOrUndefined(options.hours) ? 0 : options.hours) + (options.days * 24);
87
+
88
+ if (!isNullOrUndefined(options.hours))
89
+ options.minutes = (isNullOrUndefined(options.minutes) ? 0 : options.minutes) + (options.hours * 60);
90
+ if (!isNullOrUndefined(options.minutes) && options.minutes !== 0)
91
+ newDate = new Date(newDate.getTime() + (options.minutes * 60 * 1000));
92
+ }
93
+
94
+ return newDate;
95
+ }
96
+
97
+ export function cloneDate(date: Date) {
98
+ return new Date(date.getTime());
99
+ }
100
+
101
+ /** Returns a new date object adjusted for the time format */
102
+ export function getDateFromToken(str: string, options?: { now?: Date; zeroTimeForToday?: boolean; }) {
103
+ let now = options && options.now ? new Date(options.now.getTime()) : new Date();
104
+
105
+ if (!isTodayToken(str) && !isNowToken(str)) return now;
106
+ let token: "Now" | "Today" = isTodayToken(str) ? "Today" : "Now";
107
+ var includeTime = token === "Now";
108
+ if (!includeTime && options && options.zeroTimeForToday) {
109
+ now.setHours(0, 0, 0, 0);
110
+ }
111
+
112
+ var n = str.replace(new RegExp(`\\[${token}\\]`, "im"), "");
113
+ n = n.replace(/\s/g, "");
114
+ var offset = n && n !== "" ? Number(n) : 0;
115
+
116
+ if (includeTime) {
117
+ now.setMinutes(now.getMinutes() + offset);
118
+ } else {
119
+ now.setDate(now.getDate() + offset);
120
+ }
121
+
122
+ return now;
123
+ }
124
+
125
+ export function isTodayToken(str: string) {
126
+ return str.match(/^\[today\]/im) !== null;
127
+ }
128
+ export function isNowToken(str: string) {
129
+ return str.match(/^\[now\]/im) !== null;
130
+ }
131
+
132
+ /** Get the number of seconds from date (in the past) to now */
133
+ export function getSecondsElapsed(from: Date) {
134
+ let secondsElapsed = (new Date().getTime() - from.getTime()) / 1000;
135
+ return secondsElapsed;
136
+ }
137
+
138
+ /** Get the total number of days in a given month specified by a date object */
139
+ export function getTotalDaysInMonth(obj: Date) {
140
+ if (isDate(obj)) {
141
+ let d = new Date(obj.getFullYear(), obj.getMonth() + 1, 0);
142
+ return d.getDate();
143
+ }
144
+ return 0;
145
+ }
146
+
147
+ /** Shifts the date by a certain number of months and takes into account the total number of days in the new month.
148
+ * For example, if you shift January 31st by one month it will return February 28th (29th for a leap year) instead of March 3rd (2nd in leap year)
149
+ */
150
+ export function shiftMonths(obj: Date, months: number) {
151
+ let desiredDate = obj.getDate();
152
+ //move to first day to avoid skipping months (ie. Jan 31 -> March 3)
153
+ obj.setDate(1);
154
+ obj.setMonth(obj.getMonth() + months);
155
+ obj.setDate(Math.min(desiredDate, getTotalDaysInMonth(obj)));
156
+ }
157
+
158
+ /**
159
+ * Gets last day of month given a date
160
+ */
161
+ export function getLastDayOfMomth(obj: Date) {
162
+ return new Date(obj.getFullYear(), obj.getMonth() + 1, 0);
163
+ }
@@ -0,0 +1,187 @@
1
+ import { IsLocalDev } from "./_dependencies";
2
+ import { deleteCookie, getCookie, setCookie } from "./cookies";
3
+ import { getKWizComGlobal } from "./objects";
4
+ import { sleepAsync } from "./promises";
5
+ import { isFunction, isNotEmptyArray, isNullOrEmptyString, isNullOrUndefined } from "./typecheckers";
6
+
7
+ interface IKWizComGlobalDebug {
8
+ _debug: boolean;
9
+ _consoleLoggerFilter: string[];
10
+ On: (Permanent?: boolean) => void;
11
+ Off: () => void;
12
+ ToggleLogs: (categoryName: string, silent?: boolean) => void;
13
+ /** purge all cache storage (SPFx may keep scripts cached) */
14
+ PurgeCache: (options?: {
15
+ skipCookies?: boolean;
16
+ skipStorage?: boolean;
17
+ onlyKWizComCaches?: boolean;
18
+ }) => Promise<{ success: boolean; error?: any; message?: string; }>;
19
+ }
20
+
21
+ /** Get the global debug object. it will only be on the top window so don't put it in the IKWizComGlobals */
22
+ export function GetGlobalDebug() {
23
+ return getKWizComGlobal(true) as { Debug?: IKWizComGlobalDebug; } & IKWizComGlobals;
24
+ }
25
+ function SetGlobalDebugFunction() {
26
+ var kGlobal = GetGlobalDebug();
27
+
28
+ if (isNullOrUndefined(kGlobal.Debug)) {
29
+ kGlobal.Debug = {
30
+ _debug: null,
31
+ _consoleLoggerFilter: null,
32
+ On: (Permanent?: boolean) => {
33
+ kGlobal.Debug._debug = true;
34
+ setCookie("KWizComDebug", "true", Permanent === true ? 365 : 1);
35
+ console.log("KWIZ Debug Mode: On");
36
+ },
37
+ Off: () => {
38
+ kGlobal.Debug._debug = false;
39
+ deleteCookie("KWizComDebug");
40
+ console.log("KWIZ Debug Mode: Off");
41
+ },
42
+ ToggleLogs: (categoryName: string, silent?: boolean) => {
43
+ if (silent === true) {
44
+ if (kGlobal.Debug._consoleLoggerFilter === null)
45
+ kGlobal.Debug._consoleLoggerFilter = [categoryName];
46
+ else if (!kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
47
+ kGlobal.Debug._consoleLoggerFilter.push(categoryName);
48
+ }
49
+ else {
50
+ if (kGlobal.Debug._consoleLoggerFilter === null)
51
+ kGlobal.Debug._consoleLoggerFilter = [];
52
+ else if (kGlobal.Debug._consoleLoggerFilter.includes(categoryName))
53
+ kGlobal.Debug._consoleLoggerFilter = kGlobal.Debug._consoleLoggerFilter.filter(c => c !== categoryName);
54
+ }
55
+
56
+ setCookie("KWizComDebugFilter", kGlobal.Debug._consoleLoggerFilter.join('~'), 365);
57
+ console.log(`logs for ${categoryName} will ${silent === true ? 'not show up' : 'show up'}`);
58
+ },
59
+ PurgeCache: async (options?: {
60
+ skipCookies?: boolean;
61
+ skipStorage?: boolean;
62
+ onlyKWizComCaches?: boolean;
63
+ }) => {
64
+ options = options || {};
65
+
66
+ let result: { success: boolean; error?: any; message?: string; } = { success: true };
67
+ let failedKeys: string[] = [];
68
+ if (options.skipStorage !== true) {
69
+ console.log(`purging local storage`);
70
+ localStorage.clear();
71
+ console.log(`purging session storage`);
72
+ sessionStorage.clear();
73
+ }
74
+
75
+ if (options.skipCookies !== true) {
76
+ console.log(`purging all cookies`);
77
+ var cookies = document.cookie.split(";");
78
+ cookies.forEach(cookie => { document.cookie = cookie.split("=")[0] + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; });
79
+ }
80
+
81
+ console.log(`purging caches`);
82
+ try {
83
+ let keys = await caches.keys();
84
+ for (let i1 = 0; i1 < keys.length; i1++) {
85
+ let key = keys[i1];
86
+ try {
87
+ let cache = await caches.open(key);
88
+ if (cache) {
89
+ let subKeys = await cache.keys();
90
+ if (subKeys && subKeys.length) {
91
+ let keysToRemove = options.onlyKWizComCaches !== true ? subKeys : subKeys.filter(k => k.url.toLowerCase().indexOf('apps.kwizcom.com/') >= 0);
92
+ for (let i2 = 0; i2 < keysToRemove.length; i2++) {
93
+ let success = await cache.delete(keysToRemove[i2]);
94
+ if (!success)//failed
95
+ failedKeys.push(keysToRemove[i2].url);
96
+ }
97
+ }
98
+ }
99
+ } catch (b) {
100
+ failedKeys.push(key);
101
+ }
102
+ }
103
+ } catch (e) {
104
+ result.success = false;
105
+ result.error = e;
106
+ result.message = (e.message || "Something went wrong.");
107
+ }
108
+
109
+ if (isNotEmptyArray(failedKeys)) {
110
+ result.success = false;
111
+ result.message = (isNullOrEmptyString(result.message) ? '' : ' ') + `Failed keys: ${failedKeys.join()}`;
112
+ }
113
+
114
+ console.group('PurgeCache complete');
115
+ console.dir(result);
116
+ console.groupEnd();
117
+
118
+ return result;
119
+ }
120
+ };
121
+ //no need to do this anymore, once we added max-age cache to our response headers, the SP Service worker now clears
122
+ //the cache of our SPFx controls on its own.
123
+ // //by default - DO NOT clear cookies/storage and non-KWIZ caches!
124
+ // window.setTimeout(() => kGlobal.Debug.PurgeCache({
125
+ // skipCookies: true,
126
+ // skipStorage: true,
127
+ // onlyKWizComCaches: true
128
+ // }), 3000);
129
+ }
130
+ }
131
+
132
+ SetGlobalDebugFunction();
133
+
134
+ export function isDebug() {
135
+ var kGlobal = GetGlobalDebug();
136
+
137
+ if (isNullOrUndefined(kGlobal.Debug._debug)) {
138
+ kGlobal.Debug._debug = IsLocalDev ||
139
+ window.location.href.indexOf('kwdebug=true') > 0 ||
140
+ window.location.href.indexOf('/workbench.aspx') > 0 ||
141
+ getCookie("KWizComDebug") === "true";
142
+ }
143
+ return kGlobal.Debug._debug === true;
144
+ }
145
+ /** returns true if this is a kwizcom production/test tenant */
146
+ export function isKWizComTenant() {
147
+ return window.location.host === "kwizcom.sharepoint.com" || window.location.host === "kwizcomqa.sharepoint.com";
148
+ }
149
+ export function isDebugOnKWizComTenant() {
150
+ return isKWizComTenant() && isDebug();
151
+ }
152
+
153
+ export function consoleLoggerFilter() {
154
+ var kGlobal = GetGlobalDebug();
155
+
156
+ if (isNullOrUndefined(kGlobal.Debug._consoleLoggerFilter)) {
157
+ let KWizComDebugFilter = getCookie("KWizComDebugFilter");
158
+ if (!isNullOrEmptyString(KWizComDebugFilter))
159
+ kGlobal.Debug._consoleLoggerFilter = KWizComDebugFilter.split('~');
160
+ else kGlobal.Debug._consoleLoggerFilter = [];
161
+ }
162
+ return kGlobal.Debug._consoleLoggerFilter;
163
+ }
164
+
165
+ export async function waitIfDebug(seconds?: number): Promise<void> {
166
+ if (isDebug())
167
+ await sleepAsync(seconds);
168
+ }
169
+
170
+ export function trackChangesToObject<T>(parent: unknown, objectName: string, tracker: {
171
+ onBeforeGet?: (v: T) => void;
172
+ onBeforeSet?: (v: T) => void;
173
+ onAfterSet?: (v: T) => void;
174
+ }) {
175
+ let originalValue: T = parent[objectName];
176
+ Object.defineProperty(parent, objectName, {
177
+ set: (newValue: T) => {
178
+ if (isFunction(tracker.onBeforeSet)) tracker.onBeforeSet(newValue);
179
+ originalValue = newValue;
180
+ if (isFunction(tracker.onAfterSet)) tracker.onAfterSet(newValue);
181
+ },
182
+ get: () => {
183
+ if (isFunction(tracker.onBeforeGet)) tracker.onBeforeGet(originalValue);
184
+ return originalValue;
185
+ }
186
+ });
187
+ }
@@ -0,0 +1,7 @@
1
+ import { isNullOrEmptyString } from "./typecheckers";
2
+
3
+ export function isValidEmail(email: string) {
4
+ return !isNullOrEmptyString(email) && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
5
+ }
6
+
7
+ export const freeEmailNotAllowedMessage = "Please use a work email, free emails are not allowed";
@@ -0,0 +1,5 @@
1
+ //eval breaks treeshaking for the entire module it is in, so keep it in separate
2
+ export function eval2(str: string) {
3
+ // eslint-disable-next-line no-eval
4
+ return eval(str);
5
+ }
@@ -0,0 +1,51 @@
1
+ import assert from 'assert/strict';
2
+ import test from 'node:test';
3
+ import { validateFilename, validateFoldername } from './file'
4
+
5
+ test('validateFilename', t => {
6
+ '"*:<>?/\\|'.split("").forEach((char) => {
7
+ let result = validateFilename(`random${char}filename.txt`);
8
+ assert.strictEqual(result.valid, false);
9
+ assert.strictEqual(result.hasIllegalCharacter, true);
10
+ });
11
+
12
+ ".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_filename|~$randomfilename".split("|").forEach((name) => {
13
+ let result = validateFilename(`${name}.txt`);
14
+ assert.strictEqual(result.valid, false);
15
+ assert.strictEqual(result.hasIllegalName, true);
16
+ });
17
+
18
+ let result = validateFilename(`desktop.ini`);
19
+ assert.strictEqual(result.valid, false);
20
+ assert.strictEqual(result.hasIllegalName, true);
21
+
22
+ ["filename.txt", "test.jpg", "image.png", "worddocument.doc"].forEach((name) => {
23
+ result = validateFilename(name);
24
+ assert.strictEqual(result.valid, true);
25
+ assert.strictEqual(result.hasIllegalName, false);
26
+ });
27
+ });
28
+
29
+ test('validateFoldername', t => {
30
+ '"*:<>?/\\|'.split("").forEach((char) => {
31
+ let result = validateFoldername(`random${char}folder`);
32
+ assert.strictEqual(result.valid, false);
33
+ assert.strictEqual(result.hasIllegalCharacter, true);
34
+ });
35
+
36
+ ".lock|CON|PRN|AUX|NUL|COM3|COM9|COM0|LPT8|LPT2|LPT6|random_VTI_folder|~$randomfolder".split("|").forEach((name) => {
37
+ let result = validateFoldername(`${name}`);
38
+ assert.strictEqual(result.valid, false);
39
+ assert.strictEqual(result.hasIllegalName, true);
40
+ });
41
+
42
+ let result = validateFoldername(`desktop.ini`);
43
+ assert.strictEqual(result.valid, false);
44
+ assert.strictEqual(result.hasIllegalName, true);
45
+
46
+ ["folder1", "imagesfolder", "assets", "kwizcom"].forEach((name) => {
47
+ result = validateFoldername(name);
48
+ assert.strictEqual(result.valid, true);
49
+ assert.strictEqual(result.hasIllegalName, false);
50
+ });
51
+ });
@@ -0,0 +1,59 @@
1
+ import { escapeRegExp } from "./strings";
2
+
3
+ //https://support.microsoft.com/en-gb/office/restrictions-and-limitations-in-onedrive-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa
4
+ //These names aren't allowed for files or folders: .lock, CON, PRN, AUX, NUL, COM0 - COM9, LPT0 - LPT9, _vti_,
5
+ //desktop.ini, any filename starting with ~$. "_vti_" can't appear anywhere in a file name.
6
+
7
+ function _getRegexCollection() {
8
+ return {
9
+ IllegalCharsRegex: new RegExp("[" + escapeRegExp(`"*:<>?/\\|`) + "]", "gi"),
10
+ IllegalCharsExtraRegex: new RegExp("[" + escapeRegExp(`~"#%&*:<>?/\\|`) + "]", "gi"),
11
+ IllegalNamesRegex: /^(\.lock|CON|PRN|AUX|NUL|COM\d|LPT\d|.*_VTI_.*|~\$.*)$/gi,
12
+ IsDesktopIni: /^desktop\.ini$/gi
13
+ };
14
+ }
15
+
16
+ export function validateFilename(fileNameWithExtension: string) {
17
+ let filenameWithOutExtension = fileNameWithExtension;
18
+ let split = filenameWithOutExtension.split(".");
19
+ split.pop();
20
+ filenameWithOutExtension = split.join(".");
21
+
22
+ let regexCollection = _getRegexCollection();
23
+
24
+ let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(filenameWithOutExtension);
25
+ let hasIllegalName = regexCollection.IllegalNamesRegex.test(filenameWithOutExtension) || regexCollection.IsDesktopIni.test(fileNameWithExtension);
26
+
27
+ return {
28
+ hasIllegalCharacter,
29
+ hasIllegalName,
30
+ valid: !hasIllegalCharacter && !hasIllegalName
31
+ };
32
+ }
33
+
34
+ export function validateFoldername(folderName: string) {
35
+ let regexCollection = _getRegexCollection();
36
+
37
+ let hasIllegalCharacter = regexCollection.IllegalCharsRegex.test(folderName);
38
+ let hasIllegalName = regexCollection.IllegalNamesRegex.test(folderName) || regexCollection.IsDesktopIni.test(folderName);
39
+
40
+ return {
41
+ hasIllegalCharacter,
42
+ hasIllegalName,
43
+ valid: !hasIllegalCharacter && !hasIllegalName
44
+ };
45
+ }
46
+
47
+ export function validateAndSetFilename(fileNameWithExtension: string) {
48
+ let regexCollection = _getRegexCollection();
49
+
50
+ let validateFilenameChk = validateFilename(fileNameWithExtension);
51
+ if (!validateFilenameChk.valid || regexCollection.IllegalCharsExtraRegex.test(fileNameWithExtension)) {
52
+ fileNameWithExtension =
53
+ fileNameWithExtension.replace(regexCollection.IllegalCharsRegex, "")
54
+ .replace(regexCollection.IllegalCharsExtraRegex, "")
55
+ .replace(regexCollection.IllegalNamesRegex, "")
56
+ .replace(regexCollection.IsDesktopIni, "");
57
+ }
58
+ return fileNameWithExtension;
59
+ }