@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,293 @@
1
+ //Unused file
2
+ export interface DetectedInfo<N extends string, O, V = null> {
3
+ readonly name: N;
4
+ readonly version: V;
5
+ readonly os: O;
6
+ }
7
+
8
+ export class BrowserInfo
9
+ implements DetectedInfo<Browser, OperatingSystem | null, string> {
10
+ public constructor(
11
+ public readonly name: Browser,
12
+ public readonly version: string,
13
+ public readonly os: OperatingSystem | null
14
+ ) { }
15
+ }
16
+
17
+ export class BotInfo implements DetectedInfo<'bot', null, null> {
18
+ public readonly bot = true as const; // NOTE: deprecated test name instead
19
+ public readonly name = 'bot' as const;
20
+ public readonly version: null = null;
21
+ public readonly os: null = null;
22
+ }
23
+
24
+ export type Browser =
25
+ | 'aol'
26
+ | 'edge'
27
+ | 'yandexbrowser'
28
+ | 'vivaldi'
29
+ | 'kakaotalk'
30
+ | 'samsung'
31
+ | 'silk'
32
+ | 'miui'
33
+ | 'beaker'
34
+ | 'edge-chromium'
35
+ | 'chrome'
36
+ | 'chromium-webview'
37
+ | 'phantomjs'
38
+ | 'crios'
39
+ | 'firefox'
40
+ | 'fxios'
41
+ | 'opera-mini'
42
+ | 'opera'
43
+ | 'ie'
44
+ | 'bb10'
45
+ | 'android'
46
+ | 'ios'
47
+ | 'safari'
48
+ | 'facebook'
49
+ | 'instagram'
50
+ | 'ios-webview'
51
+ | 'searchbot'
52
+ | 'unknown';
53
+ export type OperatingSystem =
54
+ | 'iOS'
55
+ | 'Android OS'
56
+ | 'BlackBerry OS'
57
+ | 'Windows Mobile'
58
+ | 'Amazon OS'
59
+ | 'Windows 3.11'
60
+ | 'Windows 95'
61
+ | 'Windows 98'
62
+ | 'Windows 2000'
63
+ | 'Windows XP'
64
+ | 'Windows Server 2003'
65
+ | 'Windows Vista'
66
+ | 'Windows 7'
67
+ | 'Windows 8'
68
+ | 'Windows 8.1'
69
+ | 'Windows 10'
70
+ | 'Windows ME'
71
+ | 'Open BSD'
72
+ | 'Sun OS'
73
+ | 'Linux'
74
+ | 'Mac OS'
75
+ | 'QNX'
76
+ | 'BeOS'
77
+ | 'OS/2'
78
+ | 'Chrome OS'
79
+ | 'Search Bot'
80
+ | 'unknown';
81
+ type UserAgentRule = [Browser, RegExp];
82
+ type UserAgentMatch = [Browser, RegExpExecArray] | false;
83
+ type OperatingSystemRule = [OperatingSystem, RegExp];
84
+
85
+ const SEARCHBOX_UA_REGEX = /alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/;
86
+ const SEARCHBOT_OS_REGEX = /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/;
87
+ const REQUIRED_VERSION_PARTS = 3;
88
+
89
+ const userAgentRules: UserAgentRule[] = [
90
+ ['aol', /AOLShield\/([0-9._]+)/],
91
+ ['edge', /Edge\/([0-9._]+)/],
92
+ ['yandexbrowser', /YaBrowser\/([0-9._]+)/],
93
+ ['vivaldi', /Vivaldi\/([0-9.]+)/],
94
+ ['kakaotalk', /KAKAOTALK\s([0-9.]+)/],
95
+ ['samsung', /SamsungBrowser\/([0-9.]+)/],
96
+ ['silk', /\bSilk\/([0-9._-]+)\b/],
97
+ ['miui', /MiuiBrowser\/([0-9.]+)$/],
98
+ ['beaker', /BeakerBrowser\/([0-9.]+)/],
99
+ ['edge-chromium', /Edg\/([0-9.]+)/],
100
+ [
101
+ 'chromium-webview',
102
+ /(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/,
103
+ ],
104
+ ['chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/],
105
+ ['phantomjs', /PhantomJS\/([0-9.]+)(:?\s|$)/],
106
+ ['crios', /CriOS\/([0-9.]+)(:?\s|$)/],
107
+ ['firefox', /Firefox\/([0-9.]+)(?:\s|$)/],
108
+ ['fxios', /FxiOS\/([0-9.]+)/],
109
+ ['opera-mini', /Opera Mini.*Version\/([0-9.]+)/],
110
+ ['opera', /Opera\/([0-9.]+)(?:\s|$)/],
111
+ ['opera', /OPR\/([0-9.]+)(:?\s|$)/],
112
+ ['ie', /Trident\/7\.0.*rv:([0-9.]+).*\).*Gecko$/],
113
+ ['ie', /MSIE\s([0-9.]+);.*Trident\/[4-7].0/],
114
+ ['ie', /MSIE\s(7\.0)/],
115
+ ['bb10', /BB10;\sTouch.*Version\/([0-9.]+)/],
116
+ ['android', /Android\s([0-9.]+)/],
117
+ ['ios', /Version\/([0-9._]+).*Mobile.*Safari.*/],
118
+ ['safari', /Version\/([0-9._]+).*Safari/],
119
+ ['facebook', /FBAV\/([0-9.]+)/],
120
+ ['instagram', /Instagram\s([0-9.]+)/],
121
+ ['ios-webview', /AppleWebKit\/([0-9.]+).*Mobile/],
122
+ ['ios-webview', /AppleWebKit\/([0-9.]+).*Gecko\)$/],
123
+ ['searchbot', SEARCHBOX_UA_REGEX]
124
+ ];
125
+ const operatingSystemRules: OperatingSystemRule[] = [
126
+ ['iOS', /iP(hone|od|ad)/],
127
+ ['Android OS', /Android/],
128
+ ['BlackBerry OS', /BlackBerry|BB10/],
129
+ ['Windows Mobile', /IEMobile/],
130
+ ['Amazon OS', /Kindle/],
131
+ ['Windows 3.11', /Win16/],
132
+ ['Windows 95', /(Windows 95)|(Win95)|(Windows_95)/],
133
+ ['Windows 98', /(Windows 98)|(Win98)/],
134
+ ['Windows 2000', /(Windows NT 5.0)|(Windows 2000)/],
135
+ ['Windows XP', /(Windows NT 5.1)|(Windows XP)/],
136
+ ['Windows Server 2003', /(Windows NT 5.2)/],
137
+ ['Windows Vista', /(Windows NT 6.0)/],
138
+ ['Windows 7', /(Windows NT 6.1)/],
139
+ ['Windows 8', /(Windows NT 6.2)/],
140
+ ['Windows 8.1', /(Windows NT 6.3)/],
141
+ ['Windows 10', /(Windows NT 10.0)/],
142
+ ['Windows ME', /Windows ME/],
143
+ ['Open BSD', /OpenBSD/],
144
+ ['Sun OS', /SunOS/],
145
+ ['Chrome OS', /CrOS/],
146
+ ['Linux', /(Linux)|(X11)/],
147
+ ['Mac OS', /(Mac_PowerPC)|(Macintosh)/],
148
+ ['QNX', /QNX/],
149
+ ['BeOS', /BeOS/],
150
+ ['OS/2', /OS\/2/],
151
+ ['Search Bot', SEARCHBOT_OS_REGEX],
152
+ ];
153
+
154
+ export function detect(userAgent?: string): BrowserInfo | BotInfo | null {
155
+ if (userAgent) {
156
+ return parseUserAgent(userAgent);
157
+ }
158
+
159
+ if (typeof navigator !== 'undefined') {
160
+ return parseUserAgent(navigator.userAgent);
161
+ }
162
+
163
+ //return getNodeVersion();
164
+ return new BrowserInfo("unknown", "unknown", "unknown");
165
+ }
166
+
167
+ export function parseUserAgent(ua: string): BrowserInfo | BotInfo | null {
168
+ // opted for using reduce here rather than Array#first with a regex.test call
169
+ // this is primarily because using the reduce we only perform the regex
170
+ // execution once rather than once for the test and for the exec again below
171
+ // probably something that needs to be benchmarked though
172
+ const matchedRule: UserAgentMatch =
173
+ ua !== '' &&
174
+ userAgentRules.reduce<UserAgentMatch>(
175
+ (matched: UserAgentMatch, [browser, regex]) => {
176
+ if (matched) {
177
+ return matched;
178
+ }
179
+
180
+ const uaMatch = regex.exec(ua);
181
+ return !!uaMatch && [browser, uaMatch];
182
+ },
183
+ false,
184
+ );
185
+
186
+ if (!matchedRule) {
187
+ return null;
188
+ }
189
+
190
+ const [name, match] = matchedRule;
191
+ if (name === 'searchbot') {
192
+ return new BotInfo();
193
+ }
194
+ let versionParts = match[1] && match[1].split(/[._]/).slice(0, 3);
195
+ if (versionParts) {
196
+ if (versionParts.length < REQUIRED_VERSION_PARTS) {
197
+ versionParts = [
198
+ ...versionParts,
199
+ ...createVersionParts(REQUIRED_VERSION_PARTS - versionParts.length),
200
+ ];
201
+ }
202
+ } else {
203
+ versionParts = [];
204
+ }
205
+
206
+ return new BrowserInfo(name, versionParts.join('.'), detectOS(ua));
207
+ }
208
+
209
+ export function detectOS(ua: string): OperatingSystem | null {
210
+ for (let ii = 0, count = operatingSystemRules.length; ii < count; ii++) {
211
+ const [os, regex] = operatingSystemRules[ii];
212
+ const match = regex.test(ua);
213
+ if (match) {
214
+ return os;
215
+ }
216
+ }
217
+
218
+ return null;
219
+ }
220
+
221
+ export function detectPDF() {
222
+ var browserInfo = parseUserAgent(navigator.userAgent);
223
+
224
+ if (browserInfo.name === 'ie') {
225
+ // load the activeX control
226
+ // AcroPDF.PDF is used by version 7 and later
227
+ // PDF.PdfCtrl is used by version 6 and earlier
228
+ return getActiveXObject('AcroPDF.PDF')
229
+ || getActiveXObject('AcroPDF.PDF.1')
230
+ || getActiveXObject('PDF.PdfCtrl')
231
+ || getActiveXObject('PDF.PdfCtrl.1')
232
+ || getActiveXObject('PDF.PdfCtrl.2')
233
+ || getActiveXObject('PDF.PdfCtrl.3')
234
+ || getActiveXObject('PDF.PdfCtrl.4')
235
+ || getActiveXObject('PDF.PdfCtrl.5')
236
+ || getActiveXObject('PDF.PdfCtrl.6')
237
+ || getActiveXObject('PDF.PdfCtrl.7')
238
+ || getActiveXObject('PDF.PdfCtrl.8')
239
+ || getActiveXObject('PDF.PdfCtrl.9');
240
+ } else {
241
+ return getNavigatorPluginByMimeType("application/pdf");
242
+ }
243
+ }
244
+ function supportsActiveX() {
245
+ var _supportsActiveX = false;
246
+ try {
247
+ _supportsActiveX = (<any>window).ActiveXObject !== undefined;
248
+ } catch (e) {
249
+
250
+ }
251
+ return _supportsActiveX;
252
+ }
253
+
254
+ function getActiveXObject(name: string) {
255
+ if (supportsActiveX()) {
256
+ try {
257
+ return new (<any>window).ActiveXObject(name);
258
+ } catch (e) {
259
+ }
260
+ }
261
+ }
262
+
263
+ function getNavigatorPluginByMimeType(mimeTypeName: string) {
264
+ if (navigator && navigator.plugins) {
265
+ // eslint-disable-next-line guard-for-in
266
+ for (var key in navigator.plugins) {
267
+ var plugin = navigator.plugins[key];
268
+ var pdfMimeType = (plugin as any)[mimeTypeName];
269
+
270
+ if (!pdfMimeType && plugin.length) {
271
+ for (var mimeTypeIndex = 0; mimeTypeIndex < plugin.length; mimeTypeIndex++) {
272
+ var mimeType = plugin[mimeTypeIndex];
273
+ if (mimeType.type === mimeTypeName) {
274
+ pdfMimeType = mimeType;
275
+ break;
276
+ }
277
+ }
278
+ }
279
+
280
+ if (pdfMimeType) return plugin;
281
+ }
282
+ }
283
+ return null;
284
+ }
285
+
286
+ function createVersionParts(count: number): string[] {
287
+ const output = [];
288
+ for (let ii = 0; ii < count; ii++) {
289
+ output.push('0');
290
+ }
291
+
292
+ return output;
293
+ }
@@ -0,0 +1,26 @@
1
+ import assert from 'assert/strict';
2
+ import test from 'node:test';
3
+ import { forEachAsync, makeUniqueArray, numbersArray } from "./collections.base";
4
+
5
+ test('forEachAsync', async t => {
6
+ let results = await forEachAsync([1, 2, 3], num => Promise.resolve(num * 2));
7
+ assert.deepEqual(results, [2, 4, 6]);
8
+ results = await forEachAsync([1, 2, 3], num => Promise.resolve(num * 2), { parallel: true });
9
+ assert.deepEqual(results, [2, 4, 6]);
10
+ results = await forEachAsync(null, num => Promise.resolve(num * 2), { parallel: true });
11
+ assert.deepEqual(results, []);
12
+ results = await forEachAsync("test", str => Promise.resolve(`Char: ${str}`), { parallel: true });
13
+ assert.deepEqual(results, ["Char: t", "Char: e", "Char: s", "Char: t"]);
14
+ });
15
+
16
+ test('makeUniqueArray', async t => {
17
+ assert.strictEqual(makeUniqueArray([1, 2, 5, 5, 2]).length, 3);
18
+ assert.strictEqual(makeUniqueArray([]).length, 0);
19
+ assert.strictEqual(makeUniqueArray([1]).length, 1);
20
+ });
21
+
22
+ test('numbersArray', t => {
23
+ assert.deepEqual(numbersArray(), []);
24
+ assert.deepEqual(numbersArray(2), [0, 1]);
25
+ assert.deepEqual(numbersArray(2, 2), [2, 3]);
26
+ });