tool-shack 0.0.14 → 0.0.17
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.d.ts +7 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/interfaces/isTouchSupported.d.ts +3 -0
- package/dist/browser/isPushNotificationSupported.d.ts +6 -0
- package/dist/browser/isScrollBehaviorSupported.d.ts +6 -0
- package/dist/browser/isScrollBehaviorSupported.js +7 -0
- package/dist/browser/isShareSupported.d.ts +6 -0
- package/dist/browser/isTabFocused.d.ts +6 -0
- package/dist/browser/isTouchSupported.d.ts +6 -0
- package/dist/browser/preferColorScheme.d.ts +18 -0
- package/dist/browser/tabFocusListener.d.ts +8 -0
- package/dist/dateTime/dateAsIso.d.ts +7 -0
- package/dist/dateTime/index.d.ts +3 -0
- package/dist/dateTime/interfaces/index.d.ts +1 -0
- package/dist/dateTime/interfaces/parseDuration.d.ts +7 -0
- package/dist/dateTime/parseDuration.d.ts +8 -0
- package/dist/dom/addAsyncEventListener.d.ts +9 -0
- package/dist/dom/addClickOutsideListener.d.ts +8 -0
- package/dist/dom/addEventListener.d.ts +8 -0
- package/dist/dom/appendAfter.d.ts +8 -0
- package/dist/dom/appendBefore.d.ts +8 -0
- package/dist/dom/createElement.d.ts +9 -0
- package/dist/dom/fireEvent.d.ts +8 -0
- package/dist/dom/index.d.ts +8 -0
- package/dist/dom/interfaces/createElement.d.ts +9 -0
- package/dist/dom/interfaces/index.d.ts +1 -0
- package/dist/general/index.d.ts +3 -0
- package/dist/general/isEmpty.d.ts +7 -0
- package/dist/general/isNil.d.ts +7 -0
- package/dist/general/isValidJson.d.ts +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/schedule/index.d.ts +2 -0
- package/dist/schedule/runAnimation.d.ts +11 -0
- package/dist/schedule/runAsync.d.ts +7 -0
- package/dist/string/byteSize.d.ts +7 -0
- package/dist/string/escapeHTML.d.ts +7 -0
- package/dist/string/index.d.ts +5 -0
- package/dist/string/removeDiacritics.d.ts +7 -0
- package/dist/string/slugify.d.ts +8 -0
- package/dist/string/truncate.d.ts +9 -0
- package/package.json +14 -8
- package/src/browser/index.ts +7 -6
- package/src/browser/isScrollBehaviorSupported.ts +7 -0
- package/src/browser/isTouchSupported.ts +1 -1
- package/src/browser/tabFocusListener.ts +1 -1
- package/src/dateTime/index.ts +3 -3
- package/src/dateTime/interfaces/index.ts +1 -1
- package/src/dateTime/parseDuration.ts +1 -1
- package/src/dom/createElement.ts +1 -1
- package/src/dom/index.ts +8 -8
- package/src/dom/interfaces/index.ts +1 -1
- package/src/general/index.ts +3 -3
- package/src/general/isEmpty.ts +1 -1
- package/src/index.ts +6 -6
- package/src/schedule/index.ts +2 -2
- package/src/string/index.ts +5 -5
- package/src/string/slugify.ts +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './isPushNotificationSupported.js';
|
|
2
|
+
export * from './isScrollBehaviorSupported.js';
|
|
3
|
+
export * from './isShareSupported.js';
|
|
4
|
+
export * from './isTabFocused.js';
|
|
5
|
+
export * from './isTouchSupported.js';
|
|
6
|
+
export * from './preferColorScheme.js';
|
|
7
|
+
export * from './tabFocusListener.js';
|
package/dist/browser/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if user's browser supports setting scroll behavior
|
|
3
|
+
*
|
|
4
|
+
* @returns Boolean indicating if user's browser supports setting scroll behavior
|
|
5
|
+
*/
|
|
6
|
+
export const isScrollBehaviorSupported = () => !!('scrollBehavior' in document.documentElement.style);
|
|
7
|
+
//# sourceMappingURL=isScrollBehaviorSupported.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if user prefers light color scheme
|
|
3
|
+
*
|
|
4
|
+
* @returns Boolean indicating if user prefers light color scheme
|
|
5
|
+
*/
|
|
6
|
+
export declare const preferLightColorScheme: () => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Check if user prefers dark color scheme
|
|
9
|
+
*
|
|
10
|
+
* @returns Boolean indicating if user prefers dark color scheme
|
|
11
|
+
*/
|
|
12
|
+
export declare const preferDarkColorScheme: () => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check what color scheme (light or dark) is prefered by user
|
|
15
|
+
*
|
|
16
|
+
* @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
|
|
17
|
+
*/
|
|
18
|
+
export declare const preferColorScheme: () => 'light' | 'dark';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set callbacks for if current browser tab is in focus
|
|
3
|
+
*
|
|
4
|
+
* @param focusCallback Function to be called when current browser tab goes into focus
|
|
5
|
+
* @param blurCallback Function to be called when current browser tab goes out of focus
|
|
6
|
+
* @returns void
|
|
7
|
+
*/
|
|
8
|
+
export declare const tabFocusListener: (focusCallback?: () => void, blurCallback?: () => void) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './parseDuration.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDuration } from './interfaces/parseDuration.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse duration in milliseconds into days, hours, minutes, seconds, milliseconds
|
|
4
|
+
*
|
|
5
|
+
* @param durationInMs Integer of duration in milliseconds
|
|
6
|
+
* @returns Object containing days, hours, minutes, seconds and milliseconds of provided duration
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseDuration: (durationInMs: number) => IDuration;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare const addAsyncEventListener: (elementSelector: string, listeners: Record<string, EventListener | EventListener[]>, acceptBubbling?: boolean) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add event listener to listen to clicks outside of given element
|
|
3
|
+
*
|
|
4
|
+
* @param element Node element outside which to listen to clicks
|
|
5
|
+
* @param fn Function to trigger when clicked outside
|
|
6
|
+
* @returns void
|
|
7
|
+
*/
|
|
8
|
+
export declare const addClickOutsideListener: (element: HTMLElement, fn: () => any) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare const addEventListener: (element: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollectionOf<HTMLElement>, listeners: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append given node after reference node in the DOM
|
|
3
|
+
*
|
|
4
|
+
* @param newNode New node element to be appended
|
|
5
|
+
* @param referenceNode Reference node element
|
|
6
|
+
* @returns Result of the action
|
|
7
|
+
*/
|
|
8
|
+
export declare const appendAfter: (newNode: HTMLElement, referenceNode: HTMLElement) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append given node before reference node in the DOM
|
|
3
|
+
*
|
|
4
|
+
* @param newNode New node element to be appended
|
|
5
|
+
* @param referenceNode Reference node element
|
|
6
|
+
* @returns Result of the action
|
|
7
|
+
*/
|
|
8
|
+
export declare const appendBefore: (newNode: HTMLElement, referenceNode: HTMLElement) => boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IExtendingElementProps } from './interfaces/createElement.js';
|
|
2
|
+
/**
|
|
3
|
+
* Method for creating Node element and assigning multiple parameters, event listeners & children in one method call
|
|
4
|
+
*
|
|
5
|
+
* @param tagName Node tag name
|
|
6
|
+
* @param props List of attributes, event listeners or/and children to assign to the newly created element
|
|
7
|
+
* @returns Resulting Node element
|
|
8
|
+
*/
|
|
9
|
+
export declare const createElement: <T = HTMLElement>(tagName: string, props?: (Partial<Omit<T, "style" | "children" | "dataset">> & IExtendingElementProps) | undefined) => T;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 declare const fireEvent: (element: HTMLElement, eventType: string) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
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';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare type TAriaLabelKey = 'atomic' | 'busy' | 'controls' | 'current' | 'describedby' | 'details' | 'disables' | 'dropeffect' | 'errormessage' | 'expanded' | 'flowto' | 'grabbed' | 'haspopup' | 'hidden' | 'invalid' | 'keyshortcuts' | 'label' | 'labelledby' | 'live' | 'modal' | 'owns' | 'relevant' | 'roledescription';
|
|
2
|
+
export interface IExtendingElementProps {
|
|
3
|
+
children?: HTMLElement[];
|
|
4
|
+
listeners?: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>;
|
|
5
|
+
role?: string;
|
|
6
|
+
aria?: Partial<Record<TAriaLabelKey, string>>;
|
|
7
|
+
dataset?: Record<string, string>;
|
|
8
|
+
style?: Record<string, string | number>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createElement.js';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run function as animation using requestAnimationFrame
|
|
3
|
+
*
|
|
4
|
+
* @param fn Function to be run as animation
|
|
5
|
+
* @param autoStart If animation should start right away or just return callbacks
|
|
6
|
+
* @returns Callbacks to start animation (startAnimation) and stop animation (stopAnimation)
|
|
7
|
+
*/
|
|
8
|
+
export declare const runAnimation: (fn: () => any, autoStart?: boolean) => {
|
|
9
|
+
startAnimation: () => void;
|
|
10
|
+
stopAnimation: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create slug from given string
|
|
3
|
+
*
|
|
4
|
+
* @param value String to be slugified
|
|
5
|
+
* @param separator One character to be used as separator (if provided longer than one character, will be automatically shortened), dash ('-') by default
|
|
6
|
+
* @returns Slugified string
|
|
7
|
+
*/
|
|
8
|
+
export declare const slugify: (value: string, separator?: string) => string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate string to maximum given length if needed and append string at the end (by default "...")
|
|
3
|
+
*
|
|
4
|
+
* @param value String value to be truncated
|
|
5
|
+
* @param maxLength Maximum allowed length
|
|
6
|
+
* @param appendedString String to append at the end, be default "..."
|
|
7
|
+
* @returns Truncated value if needed otherwise original value
|
|
8
|
+
*/
|
|
9
|
+
export declare const truncate: (value: string, maxLength: number, appendedString?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tool-shack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Collection of usefull functions to ease work",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Myška",
|
|
@@ -19,24 +19,30 @@
|
|
|
19
19
|
"module": "dist/index.js",
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"exports": {
|
|
22
|
-
"
|
|
22
|
+
"./package.json": {
|
|
23
|
+
"default": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
23
29
|
},
|
|
24
30
|
"files": [
|
|
25
31
|
"dist/**/*.js",
|
|
32
|
+
"dist/**/*.d.ts",
|
|
26
33
|
"src/**/*.ts"
|
|
27
34
|
],
|
|
28
35
|
"scripts": {
|
|
29
|
-
"build": "rm -rf dist && tsc-
|
|
36
|
+
"build": "rm -rf dist && tsc -b .",
|
|
30
37
|
"format": "pretty-quick",
|
|
31
38
|
"generate-docs": "rm -rf docs && typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
|
|
32
39
|
"prepare": "husky install"
|
|
33
40
|
},
|
|
34
41
|
"devDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"prettier": "^2.6.2",
|
|
42
|
+
"husky": "^8.0.1",
|
|
43
|
+
"prettier": "^2.7.1",
|
|
38
44
|
"pretty-quick": "^3.1.3",
|
|
39
|
-
"typedoc": "^0.
|
|
40
|
-
"typescript": "^4.
|
|
45
|
+
"typedoc": "^0.23.11",
|
|
46
|
+
"typescript": "^4.8.2"
|
|
41
47
|
}
|
|
42
48
|
}
|
package/src/browser/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from './isPushNotificationSupported';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
1
|
+
export * from './isPushNotificationSupported.js';
|
|
2
|
+
export * from './isScrollBehaviorSupported.js';
|
|
3
|
+
export * from './isShareSupported.js';
|
|
4
|
+
export * from './isTabFocused.js';
|
|
5
|
+
export * from './isTouchSupported.js';
|
|
6
|
+
export * from './preferColorScheme.js';
|
|
7
|
+
export * from './tabFocusListener.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if user's browser supports setting scroll behavior
|
|
3
|
+
*
|
|
4
|
+
* @returns Boolean indicating if user's browser supports setting scroll behavior
|
|
5
|
+
*/
|
|
6
|
+
export const isScrollBehaviorSupported = (): boolean =>
|
|
7
|
+
!!('scrollBehavior' in document.documentElement.style);
|
package/src/dateTime/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './interfaces';
|
|
1
|
+
export * from './interfaces/index.js';
|
|
2
2
|
|
|
3
|
-
export * from './dateAsIso';
|
|
4
|
-
export * from './parseDuration';
|
|
3
|
+
export * from './dateAsIso.js';
|
|
4
|
+
export * from './parseDuration.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './parseDuration';
|
|
1
|
+
export * from './parseDuration.js';
|
package/src/dom/createElement.ts
CHANGED
package/src/dom/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './interfaces';
|
|
1
|
+
export * from './interfaces/index.js';
|
|
2
2
|
|
|
3
|
-
export * from './addAsyncEventListener';
|
|
4
|
-
export * from './addClickOutsideListener';
|
|
5
|
-
export * from './addEventListener';
|
|
6
|
-
export * from './appendAfter';
|
|
7
|
-
export * from './appendBefore';
|
|
8
|
-
export * from './createElement';
|
|
9
|
-
export * from './fireEvent';
|
|
3
|
+
export * from './addAsyncEventListener.js';
|
|
4
|
+
export * from './addClickOutsideListener.js';
|
|
5
|
+
export * from './addEventListener.js';
|
|
6
|
+
export * from './appendAfter.js';
|
|
7
|
+
export * from './appendBefore.js';
|
|
8
|
+
export * from './createElement.js';
|
|
9
|
+
export * from './fireEvent.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './createElement';
|
|
1
|
+
export * from './createElement.js';
|
package/src/general/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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';
|
package/src/general/isEmpty.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
package/src/schedule/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './runAnimation';
|
|
2
|
-
export * from './runAsync';
|
|
1
|
+
export * from './runAnimation.js';
|
|
2
|
+
export * from './runAsync.js';
|
package/src/string/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
package/src/string/slugify.ts
CHANGED