tool-shack 0.0.24 → 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.
@@ -19,7 +19,9 @@ export const createElement = (tagName, props) => {
19
19
  }
20
20
  }
21
21
  else if (props.style) {
22
- Object.assign(element.style, props.style);
22
+ for (const [styleKey, styleValue] of Object.entries(props.style)) {
23
+ element.style[styleKey] = styleValue;
24
+ }
23
25
  }
24
26
  else if (key === 'children') {
25
27
  const fragment = document.createDocumentFragment();
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "tool-shack",
3
- "version": "0.0.24",
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
- }
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
+ }
@@ -1,59 +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 (const [ariaKey, ariaValue] of Object.entries(props.aria!)) {
24
- element.setAttribute(`aria-${ariaKey}`, ariaValue);
25
- }
26
- } else if (props.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 (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
+ };
@@ -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)[];
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
+ }