tool-shack 0.0.23 → 0.0.25

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 +16 -9
  5. package/dist/dom/interfaces/createElement.d.ts +1 -1
  6. package/package.json +49 -49
  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 +61 -55
  26. package/src/dom/fireEvent.ts +0 -0
  27. package/src/dom/interfaces/createElement.ts +36 -36
  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,26 @@ 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];
21
+ else if (props.style) {
22
+ for (const [styleKey, styleValue] of Object.entries(props.style)) {
23
+ element.style[styleKey] = styleValue;
24
24
  }
25
25
  }
26
26
  else if (key === 'children') {
27
- props.children.forEach((child) => element.appendChild(child));
27
+ const fragment = document.createDocumentFragment();
28
+ for (const child of props.children) {
29
+ if (typeof child === 'string') {
30
+ fragment.appendChild(document.createTextNode(child));
31
+ }
32
+ else {
33
+ fragment.appendChild(child);
34
+ }
35
+ }
36
+ element.appendChild(fragment);
28
37
  }
29
38
  else if (key === 'listeners') {
30
39
  for (let eventName in props.listeners) {
@@ -35,9 +44,7 @@ export const createElement = (tagName, props) => {
35
44
  }
36
45
  }
37
46
  else if (key === 'dataset') {
38
- for (let datasetKey in props.dataset) {
39
- element.dataset[datasetKey] = props.dataset[datasetKey];
40
- }
47
+ Object.assign(element.dataset, props.dataset);
41
48
  }
42
49
  else {
43
50
  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,49 +1,49 @@
1
- {
2
- "name": "tool-shack",
3
- "version": "0.0.23",
4
- "description": "Collection of usefull functions to ease work",
5
- "author": {
6
- "name": "David Myška",
7
- "url": "https://www.davidmyska.com/"
8
- },
9
- "license": "MIT",
10
- "bugs": {
11
- "url": "https://github.com/miskith/tool-shack/issues"
12
- },
13
- "homepage": "https://www.davidmyska.com/tool-shack/",
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/miskith/tool-shack.git"
17
- },
18
- "type": "module",
19
- "module": "dist/index.js",
20
- "main": "dist/index.js",
21
- "exports": {
22
- "./package.json": {
23
- "default": "./package.json"
24
- },
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "default": "./dist/index.js"
28
- }
29
- },
30
- "files": [
31
- "dist/**/*.js",
32
- "dist/**/*.d.ts",
33
- "src/**/*.ts"
34
- ],
35
- "sideEffects": false,
36
- "scripts": {
37
- "build": "rm -rf dist && tsc -b .",
38
- "format": "pretty-quick",
39
- "generate-docs": "rm -rf docs && typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
40
- "prepare": "husky install"
41
- },
42
- "devDependencies": {
43
- "husky": "^8.0.3",
44
- "prettier": "^2.8.8",
45
- "pretty-quick": "^3.1.3",
46
- "typedoc": "^0.24.8",
47
- "typescript": "^5.1.3"
48
- }
49
- }
1
+ {
2
+ "name": "tool-shack",
3
+ "version": "0.0.25",
4
+ "description": "Collection of usefull functions to ease work",
5
+ "author": {
6
+ "name": "David Myška",
7
+ "url": "https://www.davidmyska.com/"
8
+ },
9
+ "license": "MIT",
10
+ "bugs": {
11
+ "url": "https://github.com/miskith/tool-shack/issues"
12
+ },
13
+ "homepage": "https://www.davidmyska.com/tool-shack/",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/miskith/tool-shack.git"
17
+ },
18
+ "type": "module",
19
+ "module": "dist/index.js",
20
+ "main": "dist/index.js",
21
+ "exports": {
22
+ "./package.json": {
23
+ "default": "./package.json"
24
+ },
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist/**/*.js",
32
+ "dist/**/*.d.ts",
33
+ "src/**/*.ts"
34
+ ],
35
+ "sideEffects": false,
36
+ "scripts": {
37
+ "build": "rm -rf dist && tsc -b .",
38
+ "format": "pretty-quick",
39
+ "generate-docs": "rm -rf docs && typedoc --name \"Tool-Shack\" --readme README.md src/*/index.ts",
40
+ "prepare": "husky"
41
+ },
42
+ "devDependencies": {
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
+ }
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
@@ -1,55 +1,61 @@
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 (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];
29
- }
30
- } else if (key === 'children') {
31
- props.children!.forEach((child: HTMLElement) => element.appendChild(child));
32
- } else if (key === 'listeners') {
33
- for (let eventName in props.listeners!) {
34
- const functionList = (
35
- props.listeners![eventName] instanceof Array
36
- ? props.listeners![eventName]
37
- : [props.listeners![eventName]]
38
- ) as EventListenerOrEventListenerObject[];
39
-
40
- functionList.forEach((fn: EventListenerOrEventListenerObject) =>
41
- element.addEventListener(eventName, fn),
42
- );
43
- }
44
- } else if (key === 'dataset') {
45
- for (let datasetKey in props.dataset) {
46
- element.dataset[datasetKey] = props.dataset[datasetKey];
47
- }
48
- } else {
49
- (element as any)[key] = value;
50
- }
51
- }
52
- }
53
-
54
- return element as unknown as T;
55
- };
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 (props.style) {
27
+ for (const [styleKey, styleValue] of Object.entries(props.style)) {
28
+ (element.style as any)[styleKey] = styleValue;
29
+ }
30
+ } else if (key === 'children') {
31
+ const fragment = document.createDocumentFragment();
32
+ for (const child of props.children!) {
33
+ if (typeof child === 'string') {
34
+ fragment.appendChild(document.createTextNode(child));
35
+ } else {
36
+ fragment.appendChild(child);
37
+ }
38
+ }
39
+ element.appendChild(fragment);
40
+ } else if (key === 'listeners') {
41
+ for (let eventName in props.listeners!) {
42
+ const functionList = (
43
+ props.listeners![eventName] instanceof Array
44
+ ? props.listeners![eventName]
45
+ : [props.listeners![eventName]]
46
+ ) as EventListenerOrEventListenerObject[];
47
+
48
+ functionList.forEach((fn: EventListenerOrEventListenerObject) =>
49
+ element.addEventListener(eventName, fn),
50
+ );
51
+ }
52
+ } else if (key === 'dataset') {
53
+ Object.assign(element.dataset, props.dataset);
54
+ } else {
55
+ (element as any)[key] = value;
56
+ }
57
+ }
58
+ }
59
+
60
+ return element as unknown as T;
61
+ };
File without changes
@@ -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[];
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)[];
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
+ }
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