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.
- package/dist/browser/index.js +6 -4
- package/dist/browser/isPushNotificationSupported.js +7 -0
- package/dist/browser/isShareSupported.js +7 -0
- package/dist/browser/isTouchSupported.js +4 -2
- package/dist/browser/preferColorScheme.js +2 -2
- 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/addEventListener.js +3 -3
- 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/schedule/runAsync.js +1 -1
- package/dist/string/byteSize.js +8 -0
- package/dist/string/index.js +5 -4
- package/dist/string/slugify.js +1 -1
- package/package.json +23 -10
- package/src/browser/index.ts +6 -4
- package/src/browser/interfaces/isTouchSupported.ts +3 -3
- package/src/browser/isPushNotificationSupported.ts +7 -0
- package/src/browser/isShareSupported.ts +7 -0
- package/src/browser/isTabFocused.ts +6 -6
- package/src/browser/isTouchSupported.ts +11 -12
- package/src/browser/preferColorScheme.ts +23 -20
- package/src/browser/tabFocusListener.ts +18 -18
- package/src/dateTime/dateAsIso.ts +24 -18
- package/src/dateTime/index.ts +4 -4
- package/src/dateTime/interfaces/index.ts +1 -1
- package/src/dateTime/interfaces/parseDuration.ts +7 -7
- package/src/dateTime/parseDuration.ts +19 -19
- package/src/dom/addAsyncEventListener.ts +34 -32
- package/src/dom/addClickOutsideListener.ts +16 -16
- package/src/dom/addEventListener.ts +32 -27
- package/src/dom/appendAfter.ts +9 -9
- package/src/dom/appendBefore.ts +9 -9
- package/src/dom/createElement.ts +55 -55
- package/src/dom/fireEvent.ts +9 -8
- package/src/dom/index.ts +9 -9
- package/src/dom/interfaces/createElement.ts +36 -36
- package/src/dom/interfaces/index.ts +1 -1
- package/src/general/index.ts +3 -3
- package/src/general/isEmpty.ts +21 -21
- package/src/general/isNil.ts +7 -7
- package/src/general/isValidJson.ts +15 -15
- package/src/index.ts +6 -6
- package/src/schedule/index.ts +2 -2
- package/src/schedule/runAnimation.ts +51 -51
- package/src/schedule/runAsync.ts +21 -23
- package/src/string/byteSize.ts +7 -0
- package/src/string/escapeHTML.ts +12 -12
- package/src/string/index.ts +5 -4
- package/src/string/removeDiacritics.ts +11 -11
- package/src/string/slugify.ts +17 -17
- package/src/string/truncate.ts +21 -21
- package/.editorconfig +0 -16
- package/dist/browser/index.d.ts +0 -4
- 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/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/escapeHTML.d.ts +0 -7
- package/dist/string/escapeHTML.js.map +0 -1
- package/dist/string/index.d.ts +0 -4
- 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 -1388
- 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 -23
- 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 -27
- package/docs/modules.html +0 -1
- package/tsconfig.json +0 -19
package/dist/browser/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
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
|
|
4
|
+
* @returns Boolean indicating if user's browser supports touch events
|
|
5
5
|
*/
|
|
6
|
-
export const isTouchSupported = () =>
|
|
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 = () => !!
|
|
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 = () => !!
|
|
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
|
|
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
|
|
@@ -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]]);
|
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,5 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
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
|
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.
|
|
25
|
-
"pretty-quick": "^3.1.
|
|
26
|
-
"typedoc": "^0.22.
|
|
27
|
-
"typescript": "^4.
|
|
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
|
}
|
package/src/browser/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
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
|
|
7
|
-
*/
|
|
8
|
-
export const isTouchSupported = (): boolean =>
|
|
9
|
-
'ontouchstart' in window ||
|
|
10
|
-
|
|
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 =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
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(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
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');
|
package/src/dateTime/index.ts
CHANGED
|
@@ -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) =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
};
|