tool-shack 0.0.27 → 0.0.29

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 (44) hide show
  1. package/dist/browser/index.d.ts +1 -0
  2. package/dist/browser/interfaces/isTouchSupported.d.ts +1 -0
  3. package/dist/browser/isPushNotificationSupported.d.ts +1 -0
  4. package/dist/browser/isScrollBehaviorSupported.d.ts +1 -0
  5. package/dist/browser/isShareSupported.d.ts +1 -0
  6. package/dist/browser/isTabFocused.d.ts +1 -0
  7. package/dist/browser/isTouchSupported.d.ts +1 -0
  8. package/dist/browser/preferColorScheme.d.ts +1 -0
  9. package/dist/browser/scrollToElement.d.ts +1 -0
  10. package/dist/browser/scrollToPosition.d.ts +1 -0
  11. package/dist/browser/tabFocusListener.d.ts +1 -0
  12. package/dist/dateTime/dateAsIso.d.ts +1 -0
  13. package/dist/dateTime/index.d.ts +1 -0
  14. package/dist/dateTime/interfaces/index.d.ts +1 -0
  15. package/dist/dateTime/interfaces/parseDuration.d.ts +1 -0
  16. package/dist/dateTime/parseDuration.d.ts +1 -0
  17. package/dist/dom/addAsyncEventListener.d.ts +1 -0
  18. package/dist/dom/addClickOutsideListener.d.ts +1 -0
  19. package/dist/dom/addEventListener.d.ts +1 -0
  20. package/dist/dom/appendAfter.d.ts +1 -0
  21. package/dist/dom/appendBefore.d.ts +1 -0
  22. package/dist/dom/createElement.d.ts +1 -0
  23. package/dist/dom/fireEvent.d.ts +1 -0
  24. package/dist/dom/getElementOffset.d.ts +1 -0
  25. package/dist/dom/index.d.ts +1 -0
  26. package/dist/dom/interfaces/createElement.d.ts +2 -1
  27. package/dist/dom/interfaces/index.d.ts +1 -0
  28. package/dist/general/index.d.ts +1 -0
  29. package/dist/general/isEmpty.d.ts +1 -0
  30. package/dist/general/isNil.d.ts +1 -0
  31. package/dist/general/isValidJson.d.ts +1 -0
  32. package/dist/index.d.ts +1 -0
  33. package/dist/schedule/index.d.ts +1 -0
  34. package/dist/schedule/runAnimation.d.ts +1 -0
  35. package/dist/schedule/runAsync.d.ts +1 -0
  36. package/dist/string/byteSize.d.ts +1 -0
  37. package/dist/string/escapeHTML.d.ts +1 -0
  38. package/dist/string/index.d.ts +1 -0
  39. package/dist/string/removeDiacritics.d.ts +1 -0
  40. package/dist/string/slugify.d.ts +1 -0
  41. package/dist/string/truncate.d.ts +1 -0
  42. package/package.json +6 -5
  43. package/src/dom/createElement.ts +59 -59
  44. package/src/dom/interfaces/createElement.ts +36 -36
@@ -7,3 +7,4 @@ export * from './preferColorScheme.js';
7
7
  export * from './scrollToElement.js';
8
8
  export * from './scrollToPosition.js';
9
9
  export * from './tabFocusListener.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export interface IExtendedWindow extends Window {
2
2
  DocumentTouch: any;
3
3
  }
4
+ //# sourceMappingURL=isTouchSupported.d.ts.map
@@ -4,3 +4,4 @@
4
4
  * @returns Boolean indicating if user's browser supports push notifications
5
5
  */
6
6
  export declare const isPushNotificationSupported: () => boolean;
7
+ //# sourceMappingURL=isPushNotificationSupported.d.ts.map
@@ -4,3 +4,4 @@
4
4
  * @returns Boolean indicating if user's browser supports setting scroll behavior
5
5
  */
6
6
  export declare const isScrollBehaviorSupported: () => boolean;
7
+ //# sourceMappingURL=isScrollBehaviorSupported.d.ts.map
@@ -4,3 +4,4 @@
4
4
  * @returns Boolean indicating if user's browser supports navigator share
5
5
  */
6
6
  export declare const isShareSupported: () => boolean;
7
+ //# sourceMappingURL=isShareSupported.d.ts.map
@@ -4,3 +4,4 @@
4
4
  * @returns Boolean indicating if current browser tab is in focus
5
5
  */
6
6
  export declare const isTabFocused: () => boolean;
7
+ //# sourceMappingURL=isTabFocused.d.ts.map
@@ -4,3 +4,4 @@
4
4
  * @returns Boolean indicating if user's browser supports touch events
5
5
  */
6
6
  export declare const isTouchSupported: () => boolean;
7
+ //# sourceMappingURL=isTouchSupported.d.ts.map
@@ -16,3 +16,4 @@ export declare const preferDarkColorScheme: () => boolean;
16
16
  * @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
17
17
  */
18
18
  export declare const preferColorScheme: () => "light" | "dark";
19
+ //# sourceMappingURL=preferColorScheme.d.ts.map
@@ -7,3 +7,4 @@
7
7
  * @returns void
8
8
  */
9
9
  export declare const scrollToElement: (element: HTMLElement, offset?: number, smoothScroll?: boolean) => void;
10
+ //# sourceMappingURL=scrollToElement.d.ts.map
@@ -8,3 +8,4 @@
8
8
  * @returns void
9
9
  */
10
10
  export declare const scrollToPosition: (x: number, y: number, smoothScroll?: boolean, target?: Window | HTMLElement) => void;
11
+ //# sourceMappingURL=scrollToPosition.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns void
7
7
  */
8
8
  export declare const tabFocusListener: (focusCallback?: () => void, blurCallback?: () => void) => void;
9
+ //# sourceMappingURL=tabFocusListener.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns ISO format with timezone
6
6
  */
7
7
  export declare const dateAsIso: (date: Date) => string;
8
+ //# sourceMappingURL=dateAsIso.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export * from './interfaces/index.js';
2
2
  export * from './dateAsIso.js';
3
3
  export * from './parseDuration.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1,2 @@
1
1
  export * from './parseDuration.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -5,3 +5,4 @@ export interface IDuration {
5
5
  seconds: number;
6
6
  milliseconds: number;
7
7
  }
8
+ //# sourceMappingURL=parseDuration.d.ts.map
@@ -6,3 +6,4 @@ import { IDuration } from './interfaces/parseDuration.js';
6
6
  * @returns Object containing days, hours, minutes, seconds and milliseconds of provided duration
7
7
  */
8
8
  export declare const parseDuration: (durationInMs: number) => IDuration;
9
+ //# sourceMappingURL=parseDuration.d.ts.map
@@ -7,3 +7,4 @@
7
7
  * @returns void
8
8
  */
9
9
  export declare const addAsyncEventListener: (elementSelector: string, listeners: Record<string, EventListener | EventListener[]>, acceptBubbling?: boolean) => void;
10
+ //# sourceMappingURL=addAsyncEventListener.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns void
7
7
  */
8
8
  export declare const addClickOutsideListener: (element: HTMLElement, fn: () => any) => void;
9
+ //# sourceMappingURL=addClickOutsideListener.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns void
7
7
  */
8
8
  export declare const addEventListener: (element: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollectionOf<HTMLElement>, listeners: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>) => void;
9
+ //# sourceMappingURL=addEventListener.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns Result of the action
7
7
  */
8
8
  export declare const appendAfter: (newNode: HTMLElement, referenceNode: HTMLElement) => boolean;
9
+ //# sourceMappingURL=appendAfter.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns Result of the action
7
7
  */
8
8
  export declare const appendBefore: (newNode: HTMLElement, referenceNode: HTMLElement) => boolean;
9
+ //# sourceMappingURL=appendBefore.d.ts.map
@@ -7,3 +7,4 @@ import { IExtendingElementProps } from './interfaces/createElement.js';
7
7
  * @returns Resulting Node element
8
8
  */
9
9
  export declare const createElement: <T = HTMLElement>(tagName: string, props?: Partial<Omit<T, "children" | "dataset" | "style">> & IExtendingElementProps) => T;
10
+ //# sourceMappingURL=createElement.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns Result of the action
7
7
  */
8
8
  export declare const fireEvent: (element: HTMLElement, eventType: string) => boolean;
9
+ //# sourceMappingURL=fireEvent.d.ts.map
@@ -8,3 +8,4 @@ export declare const getElementOffset: (element: HTMLElement) => {
8
8
  top: number;
9
9
  left: number;
10
10
  };
11
+ //# sourceMappingURL=getElementOffset.d.ts.map
@@ -7,3 +7,4 @@ export * from './appendBefore.js';
7
7
  export * from './createElement.js';
8
8
  export * from './fireEvent.js';
9
9
  export * from './getElementOffset.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,10 @@
1
1
  export 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
2
  export interface IExtendingElementProps {
3
- children?: (HTMLElement | string)[];
3
+ children?: (HTMLElement | string | SVGElement)[];
4
4
  listeners?: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>;
5
5
  role?: string;
6
6
  aria?: Partial<Record<TAriaLabelKey, string>>;
7
7
  dataset?: Record<string, string>;
8
8
  style?: Record<string, string | number>;
9
9
  }
10
+ //# sourceMappingURL=createElement.d.ts.map
@@ -1 +1,2 @@
1
1
  export * from './createElement.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export * from './isEmpty.js';
2
2
  export * from './isNil.js';
3
3
  export * from './isValidJson.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Boolean indicating if given value is empty
6
6
  */
7
7
  export declare const isEmpty: (value: any) => boolean;
8
+ //# sourceMappingURL=isEmpty.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Boolean indicating if value is equal to null or undefined
6
6
  */
7
7
  export declare const isNil: (value: any) => boolean;
8
+ //# sourceMappingURL=isNil.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Boolean indicating if string value is a valid JSON
6
6
  */
7
7
  export declare const isValidJson: (value: string) => boolean;
8
+ //# sourceMappingURL=isValidJson.d.ts.map
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './dom/index.js';
4
4
  export * from './general/index.js';
5
5
  export * from './schedule/index.js';
6
6
  export * from './string/index.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export * from './runAnimation.js';
2
2
  export * from './runAsync.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -9,3 +9,4 @@ export declare const runAnimation: (fn: () => any, autoStart?: boolean) => {
9
9
  startAnimation: () => void;
10
10
  stopAnimation: () => void;
11
11
  };
12
+ //# sourceMappingURL=runAnimation.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Promise of expected result
6
6
  */
7
7
  export declare const runAsync: <T>(fn: () => any) => Promise<T>;
8
+ //# sourceMappingURL=runAsync.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Byte size of given string
6
6
  */
7
7
  export declare const byteSize: (value: string) => number;
8
+ //# sourceMappingURL=byteSize.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns Safe string with escaped HTML related characters
6
6
  */
7
7
  export declare const escapeHTML: (html: string) => string;
8
+ //# sourceMappingURL=escapeHTML.d.ts.map
@@ -3,3 +3,4 @@ export * from './escapeHTML.js';
3
3
  export * from './removeDiacritics.js';
4
4
  export * from './slugify.js';
5
5
  export * from './truncate.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -5,3 +5,4 @@
5
5
  * @returns ASCII string with removed diacritics & accents
6
6
  */
7
7
  export declare const removeDiacritics: (value: string) => string;
8
+ //# sourceMappingURL=removeDiacritics.d.ts.map
@@ -6,3 +6,4 @@
6
6
  * @returns Slugified string
7
7
  */
8
8
  export declare const slugify: (value: string, separator?: string) => string;
9
+ //# sourceMappingURL=slugify.d.ts.map
@@ -7,3 +7,4 @@
7
7
  * @returns Truncated value if needed otherwise original value
8
8
  */
9
9
  export declare const truncate: (value: string, maxLength: number, appendedString?: string) => string;
10
+ //# sourceMappingURL=truncate.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tool-shack",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "Collection of usefull functions to ease work",
5
5
  "author": {
6
6
  "name": "David Myška",
@@ -41,9 +41,10 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "husky": "^9.1.7",
44
- "prettier": "^3.3.3",
44
+ "prettier": "^3.4.2",
45
45
  "pretty-quick": "^4.0.0",
46
- "typedoc": "^0.26.11",
47
- "typescript": "^5.6.3"
48
- }
46
+ "typedoc": "^0.27.3",
47
+ "typescript": "^5.7.2"
48
+ },
49
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
49
50
  }
@@ -1,59 +1,59 @@
1
- import { IExtendingElementProps } from './interfaces/createElement.js';
2
-
3
- /**
4
- * Method for creating Node element and assigning multiple parameters, event listeners & children in one method call
5
- *
6
- * @param tagName Node tag name
7
- * @param props List of attributes, event listeners or/and children to assign to the newly created element
8
- * @returns Resulting Node element
9
- */
10
- export const createElement = <T = HTMLElement>(
11
- tagName: string,
12
- props?: Partial<Omit<T, 'children' | 'dataset' | 'style'>> & IExtendingElementProps,
13
- ): T => {
14
- const element: HTMLElement = document.createElement(tagName);
15
-
16
- if (props) {
17
- for (let key in props) {
18
- const value = (props as any)[key];
19
-
20
- if (key === 'role') {
21
- element.setAttribute(key, value);
22
- } else if (key === 'aria') {
23
- for (const [ariaKey, ariaValue] of Object.entries(props.aria!)) {
24
- element.setAttribute(`aria-${ariaKey}`, ariaValue);
25
- }
26
- } else if (key === 'style') {
27
- Object.assign(element.style, props.style);
28
- } else if (key === 'children') {
29
- const fragment = document.createDocumentFragment();
30
- for (const child of props.children!) {
31
- if (typeof child === 'string') {
32
- fragment.appendChild(document.createTextNode(child));
33
- } else {
34
- fragment.appendChild(child);
35
- }
36
- }
37
- element.appendChild(fragment);
38
- } else if (key === 'listeners') {
39
- for (let eventName in props.listeners!) {
40
- const functionList = (
41
- props.listeners![eventName] instanceof Array
42
- ? props.listeners![eventName]
43
- : [props.listeners![eventName]]
44
- ) as EventListenerOrEventListenerObject[];
45
-
46
- functionList.forEach((fn: EventListenerOrEventListenerObject) =>
47
- element.addEventListener(eventName, fn),
48
- );
49
- }
50
- } else if (key === 'dataset') {
51
- Object.assign(element.dataset, props.dataset);
52
- } else {
53
- (element as any)[key] = value;
54
- }
55
- }
56
- }
57
-
58
- return element as unknown as T;
59
- };
1
+ import { IExtendingElementProps } from './interfaces/createElement.js';
2
+
3
+ /**
4
+ * Method for creating Node element and assigning multiple parameters, event listeners & children in one method call
5
+ *
6
+ * @param tagName Node tag name
7
+ * @param props List of attributes, event listeners or/and children to assign to the newly created element
8
+ * @returns Resulting Node element
9
+ */
10
+ export const createElement = <T = HTMLElement>(
11
+ tagName: string,
12
+ props?: Partial<Omit<T, 'children' | 'dataset' | 'style'>> & IExtendingElementProps,
13
+ ): T => {
14
+ const element: HTMLElement = document.createElement(tagName);
15
+
16
+ if (props) {
17
+ for (let key in props) {
18
+ const value = (props as any)[key];
19
+
20
+ if (key === 'role') {
21
+ element.setAttribute(key, value);
22
+ } else if (key === 'aria') {
23
+ for (const [ariaKey, ariaValue] of Object.entries(props.aria!)) {
24
+ element.setAttribute(`aria-${ariaKey}`, ariaValue);
25
+ }
26
+ } else if (key === 'style') {
27
+ Object.assign(element.style, props.style);
28
+ } else if (key === 'children') {
29
+ const fragment = document.createDocumentFragment();
30
+ for (const child of props.children!) {
31
+ if (typeof child === 'string') {
32
+ fragment.appendChild(document.createTextNode(child));
33
+ } else {
34
+ fragment.appendChild(child);
35
+ }
36
+ }
37
+ element.appendChild(fragment);
38
+ } else if (key === 'listeners') {
39
+ for (let eventName in props.listeners!) {
40
+ const functionList = (
41
+ props.listeners![eventName] instanceof Array
42
+ ? props.listeners![eventName]
43
+ : [props.listeners![eventName]]
44
+ ) as EventListenerOrEventListenerObject[];
45
+
46
+ functionList.forEach((fn: EventListenerOrEventListenerObject) =>
47
+ element.addEventListener(eventName, fn),
48
+ );
49
+ }
50
+ } else if (key === 'dataset') {
51
+ Object.assign(element.dataset, props.dataset);
52
+ } else {
53
+ (element as any)[key] = value;
54
+ }
55
+ }
56
+ }
57
+
58
+ return element as unknown as T;
59
+ };
@@ -1,36 +1,36 @@
1
- export type TAriaLabelKey =
2
- | 'atomic'
3
- | 'busy'
4
- | 'controls'
5
- | 'current'
6
- | 'describedby'
7
- | 'details'
8
- | 'disables'
9
- | 'dropeffect'
10
- | 'errormessage'
11
- | 'expanded'
12
- | 'flowto'
13
- | 'grabbed'
14
- | 'haspopup'
15
- | 'hidden'
16
- | 'invalid'
17
- | 'keyshortcuts'
18
- | 'label'
19
- | 'labelledby'
20
- | 'live'
21
- | 'modal'
22
- | 'owns'
23
- | 'relevant'
24
- | 'roledescription';
25
-
26
- export interface IExtendingElementProps {
27
- children?: (HTMLElement | string)[];
28
- listeners?: Record<
29
- string,
30
- EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
31
- >;
32
- role?: string;
33
- aria?: Partial<Record<TAriaLabelKey, string>>;
34
- dataset?: Record<string, string>;
35
- style?: Record<string, string | number>;
36
- }
1
+ export type TAriaLabelKey =
2
+ | 'atomic'
3
+ | 'busy'
4
+ | 'controls'
5
+ | 'current'
6
+ | 'describedby'
7
+ | 'details'
8
+ | 'disables'
9
+ | 'dropeffect'
10
+ | 'errormessage'
11
+ | 'expanded'
12
+ | 'flowto'
13
+ | 'grabbed'
14
+ | 'haspopup'
15
+ | 'hidden'
16
+ | 'invalid'
17
+ | 'keyshortcuts'
18
+ | 'label'
19
+ | 'labelledby'
20
+ | 'live'
21
+ | 'modal'
22
+ | 'owns'
23
+ | 'relevant'
24
+ | 'roledescription';
25
+
26
+ export interface IExtendingElementProps {
27
+ children?: (HTMLElement | string | SVGElement)[];
28
+ listeners?: Record<
29
+ string,
30
+ EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
31
+ >;
32
+ role?: string;
33
+ aria?: Partial<Record<TAriaLabelKey, string>>;
34
+ dataset?: Record<string, string>;
35
+ style?: Record<string, string | number>;
36
+ }