tool-shack 0.0.13 → 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.
- package/dist/browser/index.js +6 -6
- package/dist/browser/tabFocusListener.js +3 -3
- package/dist/dateTime/index.js +3 -3
- package/dist/dateTime/interfaces/index.js +1 -1
- package/dist/dom/appendAfter.js +1 -1
- package/dist/dom/appendBefore.js +1 -1
- package/dist/dom/index.js +8 -8
- package/dist/dom/interfaces/index.js +1 -1
- package/dist/general/index.js +3 -3
- package/dist/general/isEmpty.js +1 -1
- package/dist/index.js +6 -6
- package/dist/schedule/index.js +2 -2
- package/dist/string/index.js +5 -5
- package/dist/string/slugify.js +1 -1
- package/package.json +22 -9
- package/src/browser/index.ts +6 -6
- package/src/browser/isPushNotificationSupported.ts +7 -7
- package/src/browser/isShareSupported.ts +7 -7
- package/src/browser/isTouchSupported.ts +11 -11
- package/src/browser/preferColorScheme.ts +23 -23
- package/src/browser/tabFocusListener.ts +18 -18
- package/src/dateTime/dateAsIso.ts +24 -24
- package/src/dateTime/parseDuration.ts +19 -19
- package/src/dom/addAsyncEventListener.ts +34 -34
- package/src/dom/addEventListener.ts +32 -32
- package/src/dom/fireEvent.ts +9 -9
- package/src/schedule/runAsync.ts +21 -21
- package/src/string/byteSize.ts +7 -7
- package/src/string/escapeHTML.ts +12 -12
- package/src/string/index.ts +5 -5
- package/.editorconfig +0 -16
- package/dist/browser/index.d.ts +0 -6
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/interfaces/isTouchSupported.d.ts +0 -3
- package/dist/browser/interfaces/isTouchSupported.js.map +0 -1
- package/dist/browser/isPushNotificationSupported.d.ts +0 -6
- package/dist/browser/isPushNotificationSupported.js.map +0 -1
- package/dist/browser/isShareSupported.d.ts +0 -6
- package/dist/browser/isShareSupported.js.map +0 -1
- package/dist/browser/isTabFocused.d.ts +0 -6
- package/dist/browser/isTabFocused.js.map +0 -1
- package/dist/browser/isTouchSupported.d.ts +0 -6
- package/dist/browser/isTouchSupported.js.map +0 -1
- package/dist/browser/preferColorScheme.d.ts +0 -18
- package/dist/browser/preferColorScheme.js.map +0 -1
- package/dist/browser/tabFocusListener.d.ts +0 -8
- package/dist/browser/tabFocusListener.js.map +0 -1
- package/dist/dateTime/dateAsIso.d.ts +0 -7
- package/dist/dateTime/dateAsIso.js.map +0 -1
- package/dist/dateTime/index.d.ts +0 -3
- package/dist/dateTime/index.js.map +0 -1
- package/dist/dateTime/interfaces/index.d.ts +0 -1
- package/dist/dateTime/interfaces/index.js.map +0 -1
- package/dist/dateTime/interfaces/parseDuration.d.ts +0 -7
- package/dist/dateTime/interfaces/parseDuration.js.map +0 -1
- package/dist/dateTime/parseDuration.d.ts +0 -8
- package/dist/dateTime/parseDuration.js.map +0 -1
- package/dist/dom/addAsyncEventListener.d.ts +0 -9
- package/dist/dom/addAsyncEventListener.js.map +0 -1
- package/dist/dom/addClickOutsideListener.d.ts +0 -8
- package/dist/dom/addClickOutsideListener.js.map +0 -1
- package/dist/dom/addEventListener.d.ts +0 -8
- package/dist/dom/addEventListener.js.map +0 -1
- package/dist/dom/appendAfter.d.ts +0 -8
- package/dist/dom/appendAfter.js.map +0 -1
- package/dist/dom/appendBefore.d.ts +0 -8
- package/dist/dom/appendBefore.js.map +0 -1
- package/dist/dom/createElement.d.ts +0 -9
- package/dist/dom/createElement.js.map +0 -1
- package/dist/dom/fireEvent.d.ts +0 -8
- package/dist/dom/fireEvent.js.map +0 -1
- package/dist/dom/index.d.ts +0 -8
- package/dist/dom/index.js.map +0 -1
- package/dist/dom/interfaces/createElement.d.ts +0 -9
- package/dist/dom/interfaces/createElement.js.map +0 -1
- package/dist/dom/interfaces/index.d.ts +0 -1
- package/dist/dom/interfaces/index.js.map +0 -1
- package/dist/general/index.d.ts +0 -3
- package/dist/general/index.js.map +0 -1
- package/dist/general/isEmpty.d.ts +0 -7
- package/dist/general/isEmpty.js.map +0 -1
- package/dist/general/isNil.d.ts +0 -7
- package/dist/general/isNil.js.map +0 -1
- package/dist/general/isValidJson.d.ts +0 -7
- package/dist/general/isValidJson.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js.map +0 -1
- package/dist/schedule/index.d.ts +0 -2
- package/dist/schedule/index.js.map +0 -1
- package/dist/schedule/runAnimation.d.ts +0 -11
- package/dist/schedule/runAnimation.js.map +0 -1
- package/dist/schedule/runAsync.d.ts +0 -7
- package/dist/schedule/runAsync.js.map +0 -1
- package/dist/string/byteSize.d.ts +0 -7
- package/dist/string/byteSize.js.map +0 -1
- package/dist/string/escapeHTML.d.ts +0 -7
- package/dist/string/escapeHTML.js.map +0 -1
- package/dist/string/index.d.ts +0 -5
- package/dist/string/index.js.map +0 -1
- package/dist/string/removeDiacritics.d.ts +0 -7
- package/dist/string/removeDiacritics.js.map +0 -1
- package/dist/string/slugify.d.ts +0 -8
- package/dist/string/slugify.js.map +0 -1
- package/dist/string/truncate.d.ts +0 -9
- package/dist/string/truncate.js.map +0 -1
- package/dist/var/www/imeteo.local/public_html/resources/assets/ts/components/regioweather.d.ts +0 -14
- package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/forecast.d.ts +0 -1
- package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/homepage.d.ts +0 -1
- package/dist/var/www/imeteo.local/public_html/resources/assets/ts/pages/regioweather.d.ts +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/icons.css +0 -1043
- package/docs/assets/icons.png +0 -0
- package/docs/assets/icons@2x.png +0 -0
- package/docs/assets/main.js +0 -52
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1413
- package/docs/assets/widgets.png +0 -0
- package/docs/assets/widgets@2x.png +0 -0
- package/docs/index.html +0 -5
- package/docs/interfaces/dateTime.IDuration.html +0 -1
- package/docs/interfaces/dom.IExtendingElementProps.html +0 -1
- package/docs/modules/browser.html +0 -29
- package/docs/modules/dateTime.html +0 -11
- package/docs/modules/dom.html +0 -52
- package/docs/modules/general.html +0 -16
- package/docs/modules/schedule.html +0 -13
- package/docs/modules/string.html +0 -32
- package/docs/modules.html +0 -1
- package/tsconfig.json +0 -19
package/dist/browser/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
+
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';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -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
|
|
12
|
+
focusCallback?.call(this);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
blurCallback
|
|
15
|
+
blurCallback?.call(this);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
};
|
package/dist/dateTime/index.js
CHANGED
|
@@ -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
|
package/dist/dom/appendAfter.js
CHANGED
|
@@ -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) =>
|
|
8
|
+
export const appendAfter = (newNode, referenceNode) => !!referenceNode.parentElement?.insertBefore(newNode, referenceNode.nextSibling);
|
|
9
9
|
//# sourceMappingURL=appendAfter.js.map
|
package/dist/dom/appendBefore.js
CHANGED
|
@@ -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) =>
|
|
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
|
package/dist/general/index.js
CHANGED
|
@@ -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
|
package/dist/general/isEmpty.js
CHANGED
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
|
package/dist/schedule/index.js
CHANGED
|
@@ -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
|
package/dist/string/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './byteSize';
|
|
2
|
-
export * from './escapeHTML';
|
|
3
|
-
export * from './removeDiacritics';
|
|
4
|
-
export * from './slugify';
|
|
5
|
-
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';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/string/slugify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tool-shack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Collection of usefull functions to ease work",
|
|
5
|
-
"
|
|
6
|
-
|
|
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://
|
|
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": "
|
|
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.
|
|
37
|
+
"prettier": "^2.6.2",
|
|
25
38
|
"pretty-quick": "^3.1.3",
|
|
26
|
-
"typedoc": "^0.22.
|
|
27
|
-
"typescript": "^4.
|
|
39
|
+
"typedoc": "^0.22.13",
|
|
40
|
+
"typescript": "^4.6.3"
|
|
28
41
|
}
|
|
29
42
|
}
|
package/src/browser/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
+
export * from './isPushNotificationSupported';
|
|
2
|
+
export * from './isShareSupported';
|
|
3
|
+
export * from './isTabFocused';
|
|
4
|
+
export * from './isTouchSupported';
|
|
5
|
+
export * from './preferColorScheme';
|
|
6
|
+
export * from './tabFocusListener';
|
|
@@ -1,7 +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);
|
|
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);
|
|
@@ -1,7 +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
|
+
/**
|
|
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,11 +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 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
|
+
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,23 +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 =>
|
|
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
|
+
/**
|
|
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,24 +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(
|
|
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
|
+
/**
|
|
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,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,34 +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) =>
|
|
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
|
-
};
|
|
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
|
+
};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add event listener(s) to one or more Node elements
|
|
3
|
-
*
|
|
4
|
-
* @param element One or multiple Node element(s) to set listener(s) for
|
|
5
|
-
* @param listeners List of event types and related callback(s)
|
|
6
|
-
* @returns void
|
|
7
|
-
*/
|
|
8
|
-
export const addEventListener = (
|
|
9
|
-
element: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollectionOf<HTMLElement>,
|
|
10
|
-
listeners: Record<
|
|
11
|
-
string,
|
|
12
|
-
EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
|
|
13
|
-
>,
|
|
14
|
-
): void => {
|
|
15
|
-
const elementList = (
|
|
16
|
-
element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList
|
|
17
|
-
? Array.from(element)
|
|
18
|
-
: [element]
|
|
19
|
-
) as HTMLElement[];
|
|
20
|
-
|
|
21
|
-
elementList.forEach((element: HTMLElement) => {
|
|
22
|
-
for (let eventName in listeners) {
|
|
23
|
-
const functionList = (
|
|
24
|
-
listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
|
|
25
|
-
) as EventListenerOrEventListenerObject[];
|
|
26
|
-
|
|
27
|
-
functionList.forEach((fn: EventListenerOrEventListenerObject) =>
|
|
28
|
-
element.addEventListener(eventName, fn),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Add event listener(s) to one or more Node elements
|
|
3
|
+
*
|
|
4
|
+
* @param element One or multiple Node element(s) to set listener(s) for
|
|
5
|
+
* @param listeners List of event types and related callback(s)
|
|
6
|
+
* @returns void
|
|
7
|
+
*/
|
|
8
|
+
export const addEventListener = (
|
|
9
|
+
element: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollectionOf<HTMLElement>,
|
|
10
|
+
listeners: Record<
|
|
11
|
+
string,
|
|
12
|
+
EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
|
|
13
|
+
>,
|
|
14
|
+
): void => {
|
|
15
|
+
const elementList = (
|
|
16
|
+
element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList
|
|
17
|
+
? Array.from(element)
|
|
18
|
+
: [element]
|
|
19
|
+
) as HTMLElement[];
|
|
20
|
+
|
|
21
|
+
elementList.forEach((element: HTMLElement) => {
|
|
22
|
+
for (let eventName in listeners) {
|
|
23
|
+
const functionList = (
|
|
24
|
+
listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
|
|
25
|
+
) as EventListenerOrEventListenerObject[];
|
|
26
|
+
|
|
27
|
+
functionList.forEach((fn: EventListenerOrEventListenerObject) =>
|
|
28
|
+
element.addEventListener(eventName, fn),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
package/src/dom/fireEvent.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manually fire event on Node element
|
|
3
|
-
*
|
|
4
|
-
* @param element Node element on which should be fired event
|
|
5
|
-
* @param eventType Type name of event that should be fired
|
|
6
|
-
* @returns Result of the action
|
|
7
|
-
*/
|
|
8
|
-
export const fireEvent = (element: HTMLElement, eventType: string): boolean =>
|
|
9
|
-
element.dispatchEvent(new Event(eventType));
|
|
1
|
+
/**
|
|
2
|
+
* Manually fire event on Node element
|
|
3
|
+
*
|
|
4
|
+
* @param element Node element on which should be fired event
|
|
5
|
+
* @param eventType Type name of event that should be fired
|
|
6
|
+
* @returns Result of the action
|
|
7
|
+
*/
|
|
8
|
+
export const fireEvent = (element: HTMLElement, eventType: string): boolean =>
|
|
9
|
+
element.dispatchEvent(new Event(eventType));
|
package/src/schedule/runAsync.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Run function in asynchronously in Worker
|
|
3
|
-
*
|
|
4
|
-
* @param fn Function to be run asynchronously
|
|
5
|
-
* @returns Promise of expected result
|
|
6
|
-
*/
|
|
7
|
-
export const runAsync = <T>(fn: () => any): Promise<T> => {
|
|
8
|
-
const worker = new Worker(URL.createObjectURL(new Blob([`postMessage((${fn})());`])));
|
|
9
|
-
|
|
10
|
-
return new Promise((res, rej) => {
|
|
11
|
-
worker.onmessage = ({ data }) => {
|
|
12
|
-
res(data);
|
|
13
|
-
worker.terminate();
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
worker.onerror = (err) => {
|
|
17
|
-
rej(err);
|
|
18
|
-
worker.terminate();
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Run function in asynchronously in Worker
|
|
3
|
+
*
|
|
4
|
+
* @param fn Function to be run asynchronously
|
|
5
|
+
* @returns Promise of expected result
|
|
6
|
+
*/
|
|
7
|
+
export const runAsync = <T>(fn: () => any): Promise<T> => {
|
|
8
|
+
const worker = new Worker(URL.createObjectURL(new Blob([`postMessage((${fn})());`])));
|
|
9
|
+
|
|
10
|
+
return new Promise((res, rej) => {
|
|
11
|
+
worker.onmessage = ({ data }) => {
|
|
12
|
+
res(data);
|
|
13
|
+
worker.terminate();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
worker.onerror = (err) => {
|
|
17
|
+
rej(err);
|
|
18
|
+
worker.terminate();
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
};
|