tool-shack 0.0.11 → 0.0.14

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 (153) hide show
  1. package/dist/browser/index.js +6 -4
  2. package/dist/browser/isPushNotificationSupported.js +7 -0
  3. package/dist/browser/isShareSupported.js +7 -0
  4. package/dist/browser/isTouchSupported.js +4 -2
  5. package/dist/browser/preferColorScheme.js +2 -2
  6. package/dist/browser/tabFocusListener.js +3 -3
  7. package/dist/dateTime/index.js +3 -3
  8. package/dist/dateTime/interfaces/index.js +1 -1
  9. package/dist/dom/addEventListener.js +3 -3
  10. package/dist/dom/appendAfter.js +1 -1
  11. package/dist/dom/appendBefore.js +1 -1
  12. package/dist/dom/index.js +8 -8
  13. package/dist/dom/interfaces/index.js +1 -1
  14. package/dist/general/index.js +3 -3
  15. package/dist/general/isEmpty.js +1 -1
  16. package/dist/index.js +6 -6
  17. package/dist/schedule/index.js +2 -2
  18. package/dist/schedule/runAsync.js +1 -1
  19. package/dist/string/byteSize.js +8 -0
  20. package/dist/string/index.js +5 -4
  21. package/dist/string/slugify.js +1 -1
  22. package/package.json +23 -10
  23. package/src/browser/index.ts +6 -4
  24. package/src/browser/interfaces/isTouchSupported.ts +3 -3
  25. package/src/browser/isPushNotificationSupported.ts +7 -0
  26. package/src/browser/isShareSupported.ts +7 -0
  27. package/src/browser/isTabFocused.ts +6 -6
  28. package/src/browser/isTouchSupported.ts +11 -12
  29. package/src/browser/preferColorScheme.ts +23 -20
  30. package/src/browser/tabFocusListener.ts +18 -18
  31. package/src/dateTime/dateAsIso.ts +24 -18
  32. package/src/dateTime/index.ts +4 -4
  33. package/src/dateTime/interfaces/index.ts +1 -1
  34. package/src/dateTime/interfaces/parseDuration.ts +7 -7
  35. package/src/dateTime/parseDuration.ts +19 -19
  36. package/src/dom/addAsyncEventListener.ts +34 -32
  37. package/src/dom/addClickOutsideListener.ts +16 -16
  38. package/src/dom/addEventListener.ts +32 -27
  39. package/src/dom/appendAfter.ts +9 -9
  40. package/src/dom/appendBefore.ts +9 -9
  41. package/src/dom/createElement.ts +55 -55
  42. package/src/dom/fireEvent.ts +9 -8
  43. package/src/dom/index.ts +9 -9
  44. package/src/dom/interfaces/createElement.ts +36 -36
  45. package/src/dom/interfaces/index.ts +1 -1
  46. package/src/general/index.ts +3 -3
  47. package/src/general/isEmpty.ts +21 -21
  48. package/src/general/isNil.ts +7 -7
  49. package/src/general/isValidJson.ts +15 -15
  50. package/src/index.ts +6 -6
  51. package/src/schedule/index.ts +2 -2
  52. package/src/schedule/runAnimation.ts +51 -51
  53. package/src/schedule/runAsync.ts +21 -23
  54. package/src/string/byteSize.ts +7 -0
  55. package/src/string/escapeHTML.ts +12 -12
  56. package/src/string/index.ts +5 -4
  57. package/src/string/removeDiacritics.ts +11 -11
  58. package/src/string/slugify.ts +17 -17
  59. package/src/string/truncate.ts +21 -21
  60. package/.editorconfig +0 -16
  61. package/dist/browser/index.d.ts +0 -4
  62. package/dist/browser/index.js.map +0 -1
  63. package/dist/browser/interfaces/isTouchSupported.d.ts +0 -3
  64. package/dist/browser/interfaces/isTouchSupported.js.map +0 -1
  65. package/dist/browser/isTabFocused.d.ts +0 -6
  66. package/dist/browser/isTabFocused.js.map +0 -1
  67. package/dist/browser/isTouchSupported.d.ts +0 -6
  68. package/dist/browser/isTouchSupported.js.map +0 -1
  69. package/dist/browser/preferColorScheme.d.ts +0 -18
  70. package/dist/browser/preferColorScheme.js.map +0 -1
  71. package/dist/browser/tabFocusListener.d.ts +0 -8
  72. package/dist/browser/tabFocusListener.js.map +0 -1
  73. package/dist/dateTime/dateAsIso.d.ts +0 -7
  74. package/dist/dateTime/dateAsIso.js.map +0 -1
  75. package/dist/dateTime/index.d.ts +0 -3
  76. package/dist/dateTime/index.js.map +0 -1
  77. package/dist/dateTime/interfaces/index.d.ts +0 -1
  78. package/dist/dateTime/interfaces/index.js.map +0 -1
  79. package/dist/dateTime/interfaces/parseDuration.d.ts +0 -7
  80. package/dist/dateTime/interfaces/parseDuration.js.map +0 -1
  81. package/dist/dateTime/parseDuration.d.ts +0 -8
  82. package/dist/dateTime/parseDuration.js.map +0 -1
  83. package/dist/dom/addAsyncEventListener.d.ts +0 -9
  84. package/dist/dom/addAsyncEventListener.js.map +0 -1
  85. package/dist/dom/addClickOutsideListener.d.ts +0 -8
  86. package/dist/dom/addClickOutsideListener.js.map +0 -1
  87. package/dist/dom/addEventListener.d.ts +0 -8
  88. package/dist/dom/addEventListener.js.map +0 -1
  89. package/dist/dom/appendAfter.d.ts +0 -8
  90. package/dist/dom/appendAfter.js.map +0 -1
  91. package/dist/dom/appendBefore.d.ts +0 -8
  92. package/dist/dom/appendBefore.js.map +0 -1
  93. package/dist/dom/createElement.d.ts +0 -9
  94. package/dist/dom/createElement.js.map +0 -1
  95. package/dist/dom/fireEvent.d.ts +0 -8
  96. package/dist/dom/fireEvent.js.map +0 -1
  97. package/dist/dom/index.d.ts +0 -8
  98. package/dist/dom/index.js.map +0 -1
  99. package/dist/dom/interfaces/createElement.d.ts +0 -9
  100. package/dist/dom/interfaces/createElement.js.map +0 -1
  101. package/dist/dom/interfaces/index.d.ts +0 -1
  102. package/dist/dom/interfaces/index.js.map +0 -1
  103. package/dist/general/index.d.ts +0 -3
  104. package/dist/general/index.js.map +0 -1
  105. package/dist/general/isEmpty.d.ts +0 -7
  106. package/dist/general/isEmpty.js.map +0 -1
  107. package/dist/general/isNil.d.ts +0 -7
  108. package/dist/general/isNil.js.map +0 -1
  109. package/dist/general/isValidJson.d.ts +0 -7
  110. package/dist/general/isValidJson.js.map +0 -1
  111. package/dist/index.d.ts +0 -6
  112. package/dist/index.js.map +0 -1
  113. package/dist/schedule/index.d.ts +0 -2
  114. package/dist/schedule/index.js.map +0 -1
  115. package/dist/schedule/runAnimation.d.ts +0 -11
  116. package/dist/schedule/runAnimation.js.map +0 -1
  117. package/dist/schedule/runAsync.d.ts +0 -7
  118. package/dist/schedule/runAsync.js.map +0 -1
  119. package/dist/string/escapeHTML.d.ts +0 -7
  120. package/dist/string/escapeHTML.js.map +0 -1
  121. package/dist/string/index.d.ts +0 -4
  122. package/dist/string/index.js.map +0 -1
  123. package/dist/string/removeDiacritics.d.ts +0 -7
  124. package/dist/string/removeDiacritics.js.map +0 -1
  125. package/dist/string/slugify.d.ts +0 -8
  126. package/dist/string/slugify.js.map +0 -1
  127. package/dist/string/truncate.d.ts +0 -9
  128. package/dist/string/truncate.js.map +0 -1
  129. package/dist/var/www/imeteo.local/public_html/resources/assets/ts/components/regioweather.d.ts +0 -14
  130. package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/forecast.d.ts +0 -1
  131. package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/homepage.d.ts +0 -1
  132. package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/regioweather.d.ts +0 -1
  133. package/docs/.nojekyll +0 -1
  134. package/docs/assets/highlight.css +0 -22
  135. package/docs/assets/icons.css +0 -1043
  136. package/docs/assets/icons.png +0 -0
  137. package/docs/assets/icons@2x.png +0 -0
  138. package/docs/assets/main.js +0 -52
  139. package/docs/assets/search.js +0 -1
  140. package/docs/assets/style.css +0 -1388
  141. package/docs/assets/widgets.png +0 -0
  142. package/docs/assets/widgets@2x.png +0 -0
  143. package/docs/index.html +0 -5
  144. package/docs/interfaces/dateTime.IDuration.html +0 -1
  145. package/docs/interfaces/dom.IExtendingElementProps.html +0 -1
  146. package/docs/modules/browser.html +0 -23
  147. package/docs/modules/dateTime.html +0 -11
  148. package/docs/modules/dom.html +0 -52
  149. package/docs/modules/general.html +0 -16
  150. package/docs/modules/schedule.html +0 -13
  151. package/docs/modules/string.html +0 -27
  152. package/docs/modules.html +0 -1
  153. package/tsconfig.json +0 -19
@@ -1,5 +1,7 @@
1
- export * from './isTabFocused';
2
- export * from './isTouchSupported';
3
- export * from './preferColorScheme';
4
- export * from './tabFocusListener';
1
+ export * from './isPushNotificationSupported.js';
2
+ export * from './isShareSupported.js';
3
+ export * from './isTabFocused.js';
4
+ export * from './isTouchSupported.js';
5
+ export * from './preferColorScheme.js';
6
+ export * from './tabFocusListener.js';
5
7
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if user's browser supports push notifications
3
+ *
4
+ * @returns Boolean indicating if user's browser supports push notifications
5
+ */
6
+ export const isPushNotificationSupported = () => !!(window.Notification || 'webkitNotifications' in window);
7
+ //# sourceMappingURL=isPushNotificationSupported.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if user's browser supports navigator share
3
+ *
4
+ * @returns Boolean indicating if user's browser supports navigator share
5
+ */
6
+ export const isShareSupported = () => !!('navigator' in window && 'share' in window.navigator && !!navigator.share);
7
+ //# sourceMappingURL=isShareSupported.js.map
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Check if user's browser supports touch events
3
3
  *
4
- * @returns Boolean indicating if user's browser support touch events
4
+ * @returns Boolean indicating if user's browser supports touch events
5
5
  */
6
- export const isTouchSupported = () => ('ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch));
6
+ export const isTouchSupported = () => 'ontouchstart' in window ||
7
+ (window.DocumentTouch &&
8
+ document instanceof window.DocumentTouch);
7
9
  //# sourceMappingURL=isTouchSupported.js.map
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * @returns Boolean indicating if user prefers light color scheme
5
5
  */
6
- export const preferLightColorScheme = () => !!(window.matchMedia('(prefers-color-scheme: light)').matches);
6
+ export const preferLightColorScheme = () => !!window.matchMedia('(prefers-color-scheme: light)').matches;
7
7
  /**
8
8
  * Check if user prefers dark color scheme
9
9
  *
10
10
  * @returns Boolean indicating if user prefers dark color scheme
11
11
  */
12
- export const preferDarkColorScheme = () => !!(window.matchMedia('(prefers-color-scheme: dark)').matches);
12
+ export const preferDarkColorScheme = () => !!window.matchMedia('(prefers-color-scheme: dark)').matches;
13
13
  /**
14
14
  * Check what color scheme (light or dark) is prefered by user
15
15
  *
@@ -1,4 +1,4 @@
1
- import { isTabFocused } from './isTabFocused';
1
+ import { isTabFocused } from './isTabFocused.js';
2
2
  /**
3
3
  * Set callbacks for if current browser tab is in focus
4
4
  *
@@ -9,10 +9,10 @@ import { isTabFocused } from './isTabFocused';
9
9
  export const tabFocusListener = (focusCallback, blurCallback) => {
10
10
  document.addEventListener('visibilitychange', () => {
11
11
  if (isTabFocused()) {
12
- focusCallback === null || focusCallback === void 0 ? void 0 : focusCallback.call(this);
12
+ focusCallback?.call(this);
13
13
  }
14
14
  else {
15
- blurCallback === null || blurCallback === void 0 ? void 0 : blurCallback.call(this);
15
+ blurCallback?.call(this);
16
16
  }
17
17
  });
18
18
  };
@@ -1,4 +1,4 @@
1
- export * from './interfaces';
2
- export * from './dateAsIso';
3
- export * from './parseDuration';
1
+ export * from './interfaces/index.js';
2
+ export * from './dateAsIso.js';
3
+ export * from './parseDuration.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export * from './parseDuration';
1
+ export * from './parseDuration.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -6,9 +6,9 @@
6
6
  * @returns void
7
7
  */
8
8
  export const addEventListener = (element, listeners) => {
9
- const elementList = (element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList ?
10
- Array.from(element) :
11
- [element]);
9
+ const elementList = (element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList
10
+ ? Array.from(element)
11
+ : [element]);
12
12
  elementList.forEach((element) => {
13
13
  for (let eventName in listeners) {
14
14
  const functionList = (listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]);
@@ -5,5 +5,5 @@
5
5
  * @param referenceNode Reference node element
6
6
  * @returns Result of the action
7
7
  */
8
- export const appendAfter = (newNode, referenceNode) => { var _a; return !!((_a = referenceNode.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(newNode, referenceNode.nextSibling)); };
8
+ export const appendAfter = (newNode, referenceNode) => !!referenceNode.parentElement?.insertBefore(newNode, referenceNode.nextSibling);
9
9
  //# sourceMappingURL=appendAfter.js.map
@@ -5,5 +5,5 @@
5
5
  * @param referenceNode Reference node element
6
6
  * @returns Result of the action
7
7
  */
8
- export const appendBefore = (newNode, referenceNode) => { var _a; return !!((_a = referenceNode.parentElement) === null || _a === void 0 ? void 0 : _a.insertBefore(newNode, referenceNode)); };
8
+ export const appendBefore = (newNode, referenceNode) => !!referenceNode.parentElement?.insertBefore(newNode, referenceNode);
9
9
  //# sourceMappingURL=appendBefore.js.map
package/dist/dom/index.js CHANGED
@@ -1,9 +1,9 @@
1
- export * from './interfaces';
2
- export * from './addAsyncEventListener';
3
- export * from './addClickOutsideListener';
4
- export * from './addEventListener';
5
- export * from './appendAfter';
6
- export * from './appendBefore';
7
- export * from './createElement';
8
- export * from './fireEvent';
1
+ export * from './interfaces/index.js';
2
+ export * from './addAsyncEventListener.js';
3
+ export * from './addClickOutsideListener.js';
4
+ export * from './addEventListener.js';
5
+ export * from './appendAfter.js';
6
+ export * from './appendBefore.js';
7
+ export * from './createElement.js';
8
+ export * from './fireEvent.js';
9
9
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export * from './createElement';
1
+ export * from './createElement.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- export * from './isEmpty';
2
- export * from './isNil';
3
- export * from './isValidJson';
1
+ export * from './isEmpty.js';
2
+ export * from './isNil.js';
3
+ export * from './isValidJson.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { isNil } from './isNil';
1
+ import { isNil } from './isNil.js';
2
2
  /**
3
3
  * Check if given value is empty
4
4
  *
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export * from './browser';
2
- export * from './dateTime';
3
- export * from './dom';
4
- export * from './general';
5
- export * from './schedule';
6
- export * from './string';
1
+ export * from './browser/index.js';
2
+ export * from './dateTime/index.js';
3
+ export * from './dom/index.js';
4
+ export * from './general/index.js';
5
+ export * from './schedule/index.js';
6
+ export * from './string/index.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- export * from './runAnimation';
2
- export * from './runAsync';
1
+ export * from './runAnimation.js';
2
+ export * from './runAsync.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -11,7 +11,7 @@ export const runAsync = (fn) => {
11
11
  res(data);
12
12
  worker.terminate();
13
13
  };
14
- worker.onerror = err => {
14
+ worker.onerror = (err) => {
15
15
  rej(err);
16
16
  worker.terminate();
17
17
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Return size of string in bytes
3
+ *
4
+ * @param value String to be sized
5
+ * @returns Byte size of given string
6
+ */
7
+ export const byteSize = (value) => new Blob([value]).size;
8
+ //# sourceMappingURL=byteSize.js.map
@@ -1,5 +1,6 @@
1
- export * from './escapeHTML';
2
- export * from './removeDiacritics';
3
- export * from './slugify';
4
- export * from './truncate';
1
+ export * from './byteSize.js';
2
+ export * from './escapeHTML.js';
3
+ export * from './removeDiacritics.js';
4
+ export * from './slugify.js';
5
+ export * from './truncate.js';
5
6
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { removeDiacritics } from './removeDiacritics';
1
+ import { removeDiacritics } from './removeDiacritics.js';
2
2
  /**
3
3
  * Create slug from given string
4
4
  *
package/package.json CHANGED
@@ -1,29 +1,42 @@
1
1
  {
2
2
  "name": "tool-shack",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "Collection of usefull functions to ease work",
5
- "main": "dist",
6
- "author": "David Myška",
5
+ "author": {
6
+ "name": "David Myška",
7
+ "url": "https://www.davidmyska.com/"
8
+ },
7
9
  "license": "MIT",
8
10
  "bugs": {
9
11
  "url": "https://github.com/miskith/tool-shack/issues"
10
12
  },
11
- "homepage": "https://github.com/miskith/tool-shack#readme",
13
+ "homepage": "https://www.davidmyska.com/tool-shack/",
12
14
  "repository": {
13
15
  "type": "git",
14
16
  "url": "git+https://github.com/miskith/tool-shack.git"
15
17
  },
18
+ "type": "module",
19
+ "module": "dist/index.js",
20
+ "main": "dist/index.js",
21
+ "exports": {
22
+ "default": "./dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist/**/*.js",
26
+ "src/**/*.ts"
27
+ ],
16
28
  "scripts": {
17
- "build": "tsc -p .",
29
+ "build": "rm -rf dist && tsc-esm .",
18
30
  "format": "pretty-quick",
19
- "generate-docs": "typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
31
+ "generate-docs": "rm -rf docs && typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
20
32
  "prepare": "husky install"
21
33
  },
22
34
  "devDependencies": {
35
+ "@digitak/tsc-esm": "^3.1.2",
23
36
  "husky": "^7.0.4",
24
- "prettier": "^2.5.1",
25
- "pretty-quick": "^3.1.2",
26
- "typedoc": "^0.22.10",
27
- "typescript": "^4.5.2"
37
+ "prettier": "^2.6.2",
38
+ "pretty-quick": "^3.1.3",
39
+ "typedoc": "^0.22.13",
40
+ "typescript": "^4.6.3"
28
41
  }
29
42
  }
@@ -1,4 +1,6 @@
1
- export * from './isTabFocused';
2
- export * from './isTouchSupported';
3
- export * from './preferColorScheme';
4
- export * from './tabFocusListener';
1
+ export * from './isPushNotificationSupported';
2
+ export * from './isShareSupported';
3
+ export * from './isTabFocused';
4
+ export * from './isTouchSupported';
5
+ export * from './preferColorScheme';
6
+ export * from './tabFocusListener';
@@ -1,3 +1,3 @@
1
- export interface IExtendedWindow extends Window {
2
- DocumentTouch: any;
3
- }
1
+ export interface IExtendedWindow extends Window {
2
+ DocumentTouch: any;
3
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if user's browser supports push notifications
3
+ *
4
+ * @returns Boolean indicating if user's browser supports push notifications
5
+ */
6
+ export const isPushNotificationSupported = (): boolean =>
7
+ !!(window.Notification || 'webkitNotifications' in window);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if user's browser supports navigator share
3
+ *
4
+ * @returns Boolean indicating if user's browser supports navigator share
5
+ */
6
+ export const isShareSupported = (): boolean =>
7
+ !!('navigator' in window && 'share' in window.navigator && !!navigator.share);
@@ -1,6 +1,6 @@
1
- /**
2
- * Check if current browser tab is in focus
3
- *
4
- * @returns Boolean indicating if current browser tab is in focus
5
- */
6
- export const isTabFocused = (): boolean => !document.hidden;
1
+ /**
2
+ * Check if current browser tab is in focus
3
+ *
4
+ * @returns Boolean indicating if current browser tab is in focus
5
+ */
6
+ export const isTabFocused = (): boolean => !document.hidden;
@@ -1,12 +1,11 @@
1
- import { IExtendedWindow } from './interfaces/isTouchSupported';
2
-
3
- /**
4
- * Check if user's browser supports touch events
5
- *
6
- * @returns Boolean indicating if user's browser support touch events
7
- */
8
- export const isTouchSupported = (): boolean => (
9
- 'ontouchstart' in window || (
10
- (window as unknown as IExtendedWindow).DocumentTouch && document instanceof (window as unknown as IExtendedWindow).DocumentTouch
11
- )
12
- );
1
+ import { IExtendedWindow } from './interfaces/isTouchSupported';
2
+
3
+ /**
4
+ * Check if user's browser supports touch events
5
+ *
6
+ * @returns Boolean indicating if user's browser supports touch events
7
+ */
8
+ export const isTouchSupported = (): boolean =>
9
+ 'ontouchstart' in window ||
10
+ ((window as unknown as IExtendedWindow).DocumentTouch &&
11
+ document instanceof (window as unknown as IExtendedWindow).DocumentTouch);
@@ -1,20 +1,23 @@
1
- /**
2
- * Check if user prefers light color scheme
3
- *
4
- * @returns Boolean indicating if user prefers light color scheme
5
- */
6
- export const preferLightColorScheme = (): boolean => !!(window.matchMedia('(prefers-color-scheme: light)').matches);
7
-
8
- /**
9
- * Check if user prefers dark color scheme
10
- *
11
- * @returns Boolean indicating if user prefers dark color scheme
12
- */
13
- export const preferDarkColorScheme = (): boolean => !!(window.matchMedia('(prefers-color-scheme: dark)').matches);
14
-
15
- /**
16
- * Check what color scheme (light or dark) is prefered by user
17
- *
18
- * @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
19
- */
20
- export const preferColorScheme = (): 'light'|'dark' => preferLightColorScheme() ? 'light' : 'dark';
1
+ /**
2
+ * Check if user prefers light color scheme
3
+ *
4
+ * @returns Boolean indicating if user prefers light color scheme
5
+ */
6
+ export const preferLightColorScheme = (): boolean =>
7
+ !!window.matchMedia('(prefers-color-scheme: light)').matches;
8
+
9
+ /**
10
+ * Check if user prefers dark color scheme
11
+ *
12
+ * @returns Boolean indicating if user prefers dark color scheme
13
+ */
14
+ export const preferDarkColorScheme = (): boolean =>
15
+ !!window.matchMedia('(prefers-color-scheme: dark)').matches;
16
+
17
+ /**
18
+ * Check what color scheme (light or dark) is prefered by user
19
+ *
20
+ * @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
21
+ */
22
+ export const preferColorScheme = (): 'light' | 'dark' =>
23
+ preferLightColorScheme() ? 'light' : 'dark';
@@ -1,18 +1,18 @@
1
- import { isTabFocused } from './isTabFocused';
2
-
3
- /**
4
- * Set callbacks for if current browser tab is in focus
5
- *
6
- * @param focusCallback Function to be called when current browser tab goes into focus
7
- * @param blurCallback Function to be called when current browser tab goes out of focus
8
- * @returns void
9
- */
10
- export const tabFocusListener = (focusCallback?: () => void, blurCallback?: () => void): void => {
11
- document.addEventListener('visibilitychange', () => {
12
- if (isTabFocused()) {
13
- focusCallback?.call(this);
14
- } else {
15
- blurCallback?.call(this);
16
- }
17
- });
18
- }
1
+ import { isTabFocused } from './isTabFocused';
2
+
3
+ /**
4
+ * Set callbacks for if current browser tab is in focus
5
+ *
6
+ * @param focusCallback Function to be called when current browser tab goes into focus
7
+ * @param blurCallback Function to be called when current browser tab goes out of focus
8
+ * @returns void
9
+ */
10
+ export const tabFocusListener = (focusCallback?: () => void, blurCallback?: () => void): void => {
11
+ document.addEventListener('visibilitychange', () => {
12
+ if (isTabFocused()) {
13
+ focusCallback?.call(this);
14
+ } else {
15
+ blurCallback?.call(this);
16
+ }
17
+ });
18
+ };
@@ -1,18 +1,24 @@
1
- /**
2
- * Return date in ISO format with timezone
3
- *
4
- * @param date Date to be converted
5
- * @returns ISO format with timezone
6
- */
7
- export const dateAsIso = (date: Date) => {
8
- const timezoneOffset = date.getTimezoneOffset();
9
-
10
- let isoFormat = '';
11
- isoFormat += `${date.getFullYear()}-${padNumber(date.getMonth() + 1)}-${padNumber(date.getDate())}`;
12
- isoFormat += `T${padNumber(date.getHours())}:${padNumber(date.getMinutes())}:${padNumber(date.getSeconds())}`;
13
- isoFormat += `${timezoneOffset <= 0 ? '+' : '-'}${padNumber(Math.floor(Math.abs(timezoneOffset) / 60))}:${padNumber(Math.abs(timezoneOffset) % 60)}`;
14
-
15
- return isoFormat;
16
- };
17
-
18
- const padNumber = (number: number): string => `${number}`.padStart(2, '0');
1
+ /**
2
+ * Return date in ISO format with timezone
3
+ *
4
+ * @param date Date to be converted
5
+ * @returns ISO format with timezone
6
+ */
7
+ export const dateAsIso = (date: Date) => {
8
+ const timezoneOffset = date.getTimezoneOffset();
9
+
10
+ let isoFormat = '';
11
+ isoFormat += `${date.getFullYear()}-${padNumber(date.getMonth() + 1)}-${padNumber(
12
+ date.getDate(),
13
+ )}`;
14
+ isoFormat += `T${padNumber(date.getHours())}:${padNumber(date.getMinutes())}:${padNumber(
15
+ date.getSeconds(),
16
+ )}`;
17
+ isoFormat += `${timezoneOffset <= 0 ? '+' : '-'}${padNumber(
18
+ Math.floor(Math.abs(timezoneOffset) / 60),
19
+ )}:${padNumber(Math.abs(timezoneOffset) % 60)}`;
20
+
21
+ return isoFormat;
22
+ };
23
+
24
+ const padNumber = (number: number): string => `${number}`.padStart(2, '0');
@@ -1,4 +1,4 @@
1
- export * from './interfaces';
2
-
3
- export * from './dateAsIso';
4
- export * from './parseDuration';
1
+ export * from './interfaces';
2
+
3
+ export * from './dateAsIso';
4
+ export * from './parseDuration';
@@ -1 +1 @@
1
- export * from './parseDuration';
1
+ export * from './parseDuration';
@@ -1,7 +1,7 @@
1
- export interface IDuration {
2
- days: number;
3
- hours: number;
4
- minutes: number;
5
- seconds: number;
6
- milliseconds: number;
7
- }
1
+ export interface IDuration {
2
+ days: number;
3
+ hours: number;
4
+ minutes: number;
5
+ seconds: number;
6
+ milliseconds: number;
7
+ }
@@ -1,19 +1,19 @@
1
- import { IDuration } from './interfaces/parseDuration';
2
-
3
- /**
4
- * Parse duration in milliseconds into days, hours, minutes, seconds, milliseconds
5
- *
6
- * @param durationInMs Integer of duration in milliseconds
7
- * @returns Object containing days, hours, minutes, seconds and milliseconds of provided duration
8
- */
9
- export const parseDuration = (durationInMs: number): IDuration => {
10
- durationInMs = Math.abs(durationInMs);
11
-
12
- return {
13
- days: Math.floor(durationInMs / (24 * 60 * 60 * 1000)),
14
- hours: Math.floor(durationInMs / (60 * 60 * 1000)) % 24,
15
- minutes: Math.floor(durationInMs / (60 * 1000)) % 60,
16
- seconds: Math.floor(durationInMs / 1000) % 60,
17
- milliseconds: Math.floor(durationInMs) % 1000,
18
- };
19
- }
1
+ import { IDuration } from './interfaces/parseDuration';
2
+
3
+ /**
4
+ * Parse duration in milliseconds into days, hours, minutes, seconds, milliseconds
5
+ *
6
+ * @param durationInMs Integer of duration in milliseconds
7
+ * @returns Object containing days, hours, minutes, seconds and milliseconds of provided duration
8
+ */
9
+ export const parseDuration = (durationInMs: number): IDuration => {
10
+ durationInMs = Math.abs(durationInMs);
11
+
12
+ return {
13
+ days: Math.floor(durationInMs / (24 * 60 * 60 * 1000)),
14
+ hours: Math.floor(durationInMs / (60 * 60 * 1000)) % 24,
15
+ minutes: Math.floor(durationInMs / (60 * 1000)) % 60,
16
+ seconds: Math.floor(durationInMs / 1000) % 60,
17
+ milliseconds: Math.floor(durationInMs) % 1000,
18
+ };
19
+ };
@@ -1,32 +1,34 @@
1
- /**
2
- * Listen to events fired on elements that may currently not exist in the DOM
3
- *
4
- * @param elementSelector Selector for element(s) to match event target
5
- * @param listeners List of event types and related callback(s)
6
- * @param acceptBubbling Boolean switch to allow bubbling or accept only direct element match
7
- * @returns void
8
- */
9
- export const addAsyncEventListener = (
10
- elementSelector: string,
11
- listeners: Record<string, EventListener | EventListener[]>,
12
- acceptBubbling = true
13
- ): void => {
14
- for (let eventName in listeners) {
15
- const functionList = (
16
- listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
17
- ) as EventListener[];
18
-
19
- functionList.forEach((fn: EventListener) => document.addEventListener(eventName, (event: Event) => {
20
- const target = event.target as HTMLElement;
21
- if (!target) {
22
- return;
23
- }
24
-
25
- if (!acceptBubbling && target.matches(elementSelector)) {
26
- fn.call(this, event);
27
- } else if (acceptBubbling && target.closest(elementSelector)) {
28
- fn.call(this, event);
29
- }
30
- }));
31
- }
32
- }
1
+ /**
2
+ * Listen to events fired on elements that may currently not exist in the DOM
3
+ *
4
+ * @param elementSelector Selector for element(s) to match event target
5
+ * @param listeners List of event types and related callback(s)
6
+ * @param acceptBubbling Boolean switch to allow bubbling or accept only direct element match
7
+ * @returns void
8
+ */
9
+ export const addAsyncEventListener = (
10
+ elementSelector: string,
11
+ listeners: Record<string, EventListener | EventListener[]>,
12
+ acceptBubbling = true,
13
+ ): void => {
14
+ for (let eventName in listeners) {
15
+ const functionList = (
16
+ listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
17
+ ) as EventListener[];
18
+
19
+ functionList.forEach((fn: EventListener) =>
20
+ document.addEventListener(eventName, (event: Event) => {
21
+ const target = event.target as HTMLElement;
22
+ if (!target) {
23
+ return;
24
+ }
25
+
26
+ if (!acceptBubbling && target.matches(elementSelector)) {
27
+ fn.call(this, event);
28
+ } else if (acceptBubbling && target.closest(elementSelector)) {
29
+ fn.call(this, event);
30
+ }
31
+ }),
32
+ );
33
+ }
34
+ };