tool-shack 0.0.22 → 0.0.24

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 (42) hide show
  1. package/README.md +0 -0
  2. package/dist/browser/preferColorScheme.d.ts +1 -1
  3. package/dist/dom/createElement.d.ts +1 -1
  4. package/dist/dom/createElement.js +15 -10
  5. package/dist/dom/interfaces/createElement.d.ts +1 -1
  6. package/package.json +7 -7
  7. package/src/browser/interfaces/isTouchSupported.ts +0 -0
  8. package/src/browser/isPushNotificationSupported.ts +0 -0
  9. package/src/browser/isScrollBehaviorSupported.ts +0 -0
  10. package/src/browser/isShareSupported.ts +0 -0
  11. package/src/browser/isTabFocused.ts +0 -0
  12. package/src/browser/isTouchSupported.ts +0 -0
  13. package/src/browser/preferColorScheme.ts +0 -0
  14. package/src/browser/tabFocusListener.ts +0 -0
  15. package/src/dateTime/dateAsIso.ts +0 -0
  16. package/src/dateTime/index.ts +0 -0
  17. package/src/dateTime/interfaces/index.ts +0 -0
  18. package/src/dateTime/interfaces/parseDuration.ts +0 -0
  19. package/src/dateTime/parseDuration.ts +0 -0
  20. package/src/dom/addAsyncEventListener.ts +0 -0
  21. package/src/dom/addClickOutsideListener.ts +0 -0
  22. package/src/dom/addEventListener.ts +0 -0
  23. package/src/dom/appendAfter.ts +0 -0
  24. package/src/dom/appendBefore.ts +0 -0
  25. package/src/dom/createElement.ts +14 -10
  26. package/src/dom/fireEvent.ts +0 -0
  27. package/src/dom/interfaces/createElement.ts +1 -1
  28. package/src/dom/interfaces/index.ts +0 -0
  29. package/src/general/index.ts +0 -0
  30. package/src/general/isEmpty.ts +0 -0
  31. package/src/general/isNil.ts +0 -0
  32. package/src/general/isValidJson.ts +0 -0
  33. package/src/index.ts +0 -0
  34. package/src/schedule/index.ts +0 -0
  35. package/src/schedule/runAnimation.ts +0 -0
  36. package/src/schedule/runAsync.ts +0 -0
  37. package/src/string/byteSize.ts +0 -0
  38. package/src/string/escapeHTML.ts +0 -0
  39. package/src/string/index.ts +0 -0
  40. package/src/string/removeDiacritics.ts +0 -0
  41. package/src/string/slugify.ts +0 -0
  42. package/src/string/truncate.ts +0 -0
package/README.md CHANGED
File without changes
@@ -15,4 +15,4 @@ export declare const preferDarkColorScheme: () => boolean;
15
15
  *
16
16
  * @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
17
17
  */
18
- export declare const preferColorScheme: () => 'light' | 'dark';
18
+ export declare const preferColorScheme: () => "light" | "dark";
@@ -6,4 +6,4 @@ import { IExtendingElementProps } from './interfaces/createElement.js';
6
6
  * @param props List of attributes, event listeners or/and children to assign to the newly created element
7
7
  * @returns Resulting Node element
8
8
  */
9
- export declare const createElement: <T = HTMLElement>(tagName: string, props?: (Partial<Omit<T, "style" | "children" | "dataset">> & IExtendingElementProps) | undefined) => T;
9
+ export declare const createElement: <T = HTMLElement>(tagName: string, props?: Partial<Omit<T, "children" | "dataset" | "style">> & IExtendingElementProps) => T;
@@ -14,17 +14,24 @@ export const createElement = (tagName, props) => {
14
14
  element.setAttribute(key, value);
15
15
  }
16
16
  else if (key === 'aria') {
17
- for (let ariaKey in props.aria) {
18
- element.setAttribute(`aria-${ariaKey}`, value[ariaKey]);
17
+ for (const [ariaKey, ariaValue] of Object.entries(props.aria)) {
18
+ element.setAttribute(`aria-${ariaKey}`, ariaValue);
19
19
  }
20
20
  }
21
- else if (key === 'style') {
22
- for (let styleKey in props.style) {
23
- element.style[styleKey] = value[styleKey];
24
- }
21
+ else if (props.style) {
22
+ Object.assign(element.style, props.style);
25
23
  }
26
24
  else if (key === 'children') {
27
- props.children.forEach((child) => element.appendChild(child));
25
+ const fragment = document.createDocumentFragment();
26
+ for (const child of props.children) {
27
+ if (typeof child === 'string') {
28
+ fragment.appendChild(document.createTextNode(child));
29
+ }
30
+ else {
31
+ fragment.appendChild(child);
32
+ }
33
+ }
34
+ element.appendChild(fragment);
28
35
  }
29
36
  else if (key === 'listeners') {
30
37
  for (let eventName in props.listeners) {
@@ -35,9 +42,7 @@ export const createElement = (tagName, props) => {
35
42
  }
36
43
  }
37
44
  else if (key === 'dataset') {
38
- for (let datasetKey in props.dataset) {
39
- element.dataset[datasetKey] = props.dataset[datasetKey];
40
- }
45
+ Object.assign(element.dataset, props.dataset);
41
46
  }
42
47
  else {
43
48
  element[key] = value;
@@ -1,6 +1,6 @@
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[];
3
+ children?: (HTMLElement | string)[];
4
4
  listeners?: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>;
5
5
  role?: string;
6
6
  aria?: Partial<Record<TAriaLabelKey, string>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tool-shack",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Collection of usefull functions to ease work",
5
5
  "author": {
6
6
  "name": "David Myška",
@@ -37,13 +37,13 @@
37
37
  "build": "rm -rf dist && tsc -b .",
38
38
  "format": "pretty-quick",
39
39
  "generate-docs": "rm -rf docs && typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
40
- "prepare": "husky install"
40
+ "prepare": "husky"
41
41
  },
42
42
  "devDependencies": {
43
- "husky": "^8.0.3",
44
- "prettier": "^2.8.8",
45
- "pretty-quick": "^3.1.3",
46
- "typedoc": "^0.24.7",
47
- "typescript": "^5.0.4"
43
+ "husky": "^9.1.7",
44
+ "prettier": "^3.3.3",
45
+ "pretty-quick": "^4.0.0",
46
+ "typedoc": "^0.26.11",
47
+ "typescript": "^5.6.3"
48
48
  }
49
49
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -20,15 +20,21 @@ export const createElement = <T = HTMLElement>(
20
20
  if (key === 'role') {
21
21
  element.setAttribute(key, value);
22
22
  } else if (key === 'aria') {
23
- for (let ariaKey in props.aria!) {
24
- element.setAttribute(`aria-${ariaKey}`, value[ariaKey]);
25
- }
26
- } else if (key === 'style') {
27
- for (let styleKey in props.style!) {
28
- (element.style as any)[styleKey] = value[styleKey];
23
+ for (const [ariaKey, ariaValue] of Object.entries(props.aria!)) {
24
+ element.setAttribute(`aria-${ariaKey}`, ariaValue);
29
25
  }
26
+ } else if (props.style) {
27
+ Object.assign(element.style, props.style);
30
28
  } else if (key === 'children') {
31
- props.children!.forEach((child: HTMLElement) => element.appendChild(child));
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);
32
38
  } else if (key === 'listeners') {
33
39
  for (let eventName in props.listeners!) {
34
40
  const functionList = (
@@ -42,9 +48,7 @@ export const createElement = <T = HTMLElement>(
42
48
  );
43
49
  }
44
50
  } else if (key === 'dataset') {
45
- for (let datasetKey in props.dataset) {
46
- element.dataset[datasetKey] = props.dataset[datasetKey];
47
- }
51
+ Object.assign(element.dataset, props.dataset);
48
52
  } else {
49
53
  (element as any)[key] = value;
50
54
  }
File without changes
@@ -24,7 +24,7 @@ export type TAriaLabelKey =
24
24
  | 'roledescription';
25
25
 
26
26
  export interface IExtendingElementProps {
27
- children?: HTMLElement[];
27
+ children?: (HTMLElement | string)[];
28
28
  listeners?: Record<
29
29
  string,
30
30
  EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/index.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes