@thednp/shorty 2.0.0-alpha4 → 2.0.0-alpha5

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 (83) hide show
  1. package/README.md +6 -2
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +57 -51
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +160 -162
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +10 -4
  10. package/src/attr/getAttribute.ts +3 -1
  11. package/src/attr/getAttributeNS.ts +3 -1
  12. package/src/attr/hasAttribute.ts +1 -0
  13. package/src/attr/hasAttributeNS.ts +3 -1
  14. package/src/attr/removeAttribute.ts +1 -0
  15. package/src/attr/removeAttributeNS.ts +3 -1
  16. package/src/attr/setAttribute.ts +3 -1
  17. package/src/attr/setAttributeNS.ts +1 -0
  18. package/src/boolean/isMobile.ts +1 -1
  19. package/src/boolean/support3DTransform.ts +1 -1
  20. package/src/boolean/supportAnimation.ts +1 -1
  21. package/src/boolean/supportPassive.ts +1 -1
  22. package/src/boolean/supportTouch.ts +2 -1
  23. package/src/boolean/supportTransform.ts +1 -1
  24. package/src/boolean/supportTransition.ts +1 -1
  25. package/src/event/off.ts +5 -3
  26. package/src/event/on.ts +5 -3
  27. package/src/event/one.ts +6 -1
  28. package/src/get/getBoundingClientRect.ts +5 -1
  29. package/src/get/getDocument.ts +4 -3
  30. package/src/get/getDocumentBody.ts +1 -1
  31. package/src/get/getElementAnimationDelay.ts +2 -1
  32. package/src/get/getElementAnimationDuration.ts +2 -1
  33. package/src/get/getElementTransitionDelay.ts +2 -1
  34. package/src/get/getElementTransitionDuration.ts +2 -1
  35. package/src/get/getParentNode.ts +2 -1
  36. package/src/get/getRectRelativeToOffsetParent.ts +1 -0
  37. package/src/get/getUID.ts +2 -2
  38. package/src/get/getWindow.ts +1 -0
  39. package/src/index.ts +10 -2
  40. package/src/interface/originalEvent.ts +2 -1
  41. package/src/is/isCanvas.ts +2 -2
  42. package/src/is/isCustomElement.ts +2 -2
  43. package/src/is/isDocument.ts +2 -1
  44. package/src/is/isElement.ts +3 -2
  45. package/src/is/isElementsArray.ts +2 -1
  46. package/src/is/isFunction.ts +2 -1
  47. package/src/is/isHTMLCollection.ts +1 -1
  48. package/src/is/isHTMLElement.ts +3 -1
  49. package/src/is/isHTMLImageElement.ts +2 -1
  50. package/src/is/isJSON.ts +1 -1
  51. package/src/is/isMap.ts +2 -1
  52. package/src/is/isMedia.ts +5 -2
  53. package/src/is/isNode.ts +2 -2
  54. package/src/is/isNodeList.ts +2 -1
  55. package/src/is/isNumber.ts +1 -1
  56. package/src/is/isObject.ts +1 -1
  57. package/src/is/isRTL.ts +1 -0
  58. package/src/is/isSVGElement.ts +1 -1
  59. package/src/is/isScaledElement.ts +5 -2
  60. package/src/is/isShadowRoot.ts +1 -1
  61. package/src/is/isString.ts +1 -1
  62. package/src/is/isTableElement.ts +3 -1
  63. package/src/is/isWeakMap.ts +2 -1
  64. package/src/is/isWindow.ts +2 -1
  65. package/src/misc/Float32ArrayFrom.ts +1 -0
  66. package/src/misc/Float64ArrayFrom.ts +1 -0
  67. package/src/misc/ObjectAssign.ts +35 -3
  68. package/src/misc/ObjectEntries.ts +3 -1
  69. package/src/misc/ObjectKeys.ts +2 -1
  70. package/src/misc/ObjectValues.ts +3 -1
  71. package/src/misc/{OriginalEvent.ts → createCustomEvent.ts} +9 -5
  72. package/src/misc/createElement.ts +10 -7
  73. package/src/misc/createElementNS.ts +9 -5
  74. package/src/misc/data.ts +31 -16
  75. package/src/misc/distinct.ts +1 -0
  76. package/src/misc/normalizeValue.ts +9 -7
  77. package/src/misc/setElementStyle.ts +3 -2
  78. package/src/misc/timer.ts +16 -13
  79. package/src/selectors/getCustomElements.ts +1 -0
  80. package/src/selectors/getElementsByClassName.ts +7 -2
  81. package/src/selectors/getElementsByTagName.ts +4 -1
  82. package/src/selectors/querySelector.ts +2 -2
  83. package/src/strings/mouseHoverEvents.ts +3 -1
@@ -4,6 +4,6 @@
4
4
  * @param obj the target object
5
5
  * @returns the query result
6
6
  */
7
- const isObject = (obj?: any): obj is object => typeof obj === 'object' || false;
7
+ const isObject = (obj?: object): obj is object => typeof obj === 'object' || false;
8
8
 
9
9
  export default isObject;
package/src/is/isRTL.ts CHANGED
@@ -2,6 +2,7 @@ import getDocumentElement from '../get/getDocumentElement';
2
2
 
3
3
  /**
4
4
  * Checks if a page is Right To Left.
5
+ *
5
6
  * @param node the target
6
7
  * @returns the query result
7
8
  */
@@ -5,7 +5,7 @@
5
5
  * @param element the target element
6
6
  * @returns the query result
7
7
  */
8
- const isSVGElement = (element?: any): element is SVGElement =>
8
+ const isSVGElement = (element?: SVGElement): element is SVGElement =>
9
9
  (element && element.constructor.name.includes('SVG')) || false;
10
10
 
11
11
  export default isSVGElement;
@@ -3,14 +3,17 @@ import getBoundingClientRect from '../get/getBoundingClientRect';
3
3
 
4
4
  /**
5
5
  * Checks if a target `HTMLElement` is affected by scale.
6
+ *
6
7
  * @see https://github.com/floating-ui/floating-ui
7
8
  *
8
9
  * @param element target
9
10
  * @returns the query result
10
11
  */
11
- export default function isScaledElement(element?: HTMLElement): boolean {
12
+ const isScaledElement = (element?: HTMLElement): boolean => {
12
13
  if (!isHTMLElement(element)) return false;
13
14
  const { width, height } = getBoundingClientRect(element);
14
15
  const { offsetWidth, offsetHeight } = element;
15
16
  return Math.round(width) !== offsetWidth || Math.round(height) !== offsetHeight;
16
- }
17
+ };
18
+
19
+ export default isScaledElement;
@@ -4,7 +4,7 @@
4
4
  * @param element target
5
5
  * @returns the query result
6
6
  */
7
- const isShadowRoot = (element?: any): element is ShadowRoot =>
7
+ const isShadowRoot = (element?: Node | ShadowRoot): element is ShadowRoot =>
8
8
  (element && element.constructor.name === 'ShadowRoot') || false;
9
9
 
10
10
  export default isShadowRoot;
@@ -4,6 +4,6 @@
4
4
  * @param str input value
5
5
  * @returns the query result
6
6
  */
7
- const isString = (str?: any): str is string => typeof str === 'string' || false;
7
+ const isString = (str?: string): str is string => typeof str === 'string' || false;
8
8
 
9
9
  export default isString;
@@ -6,7 +6,9 @@
6
6
  * @param element the target element
7
7
  * @returns the query result
8
8
  */
9
- const isTableElement = (element?: any): element is HTMLTableElement | HTMLTableCellElement =>
9
+ const isTableElement = (
10
+ element?: HTMLTableElement | HTMLTableCellElement,
11
+ ): element is HTMLTableElement | HTMLTableCellElement =>
10
12
  (element && ['TABLE', 'TD', 'TH'].includes(element.tagName)) || false;
11
13
 
12
14
  export default isTableElement;
@@ -4,5 +4,6 @@
4
4
  * @param obj the target object
5
5
  * @returns the query result
6
6
  */
7
- const isWeakMap = (obj?: any): obj is WeakMap<any, any> => (obj && obj.constructor.name === 'WeakMap') || false;
7
+ const isWeakMap = <T extends WeakMap<any, unknown>>(obj?: T): obj is T =>
8
+ (obj && obj.constructor.name === 'WeakMap') || false;
8
9
  export default isWeakMap;
@@ -5,6 +5,7 @@
5
5
  * @param obj the target object
6
6
  * @returns the query result
7
7
  */
8
- const isWindow = (obj?: any): obj is Window => (obj && obj.constructor.name === 'Window') || false;
8
+ const isWindow = (obj?: Node | Window): obj is Window =>
9
+ (obj && obj.constructor.name === 'Window') || false;
9
10
 
10
11
  export default isWindow;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Shortcut for `Float32Array.from()` static method.
3
+ *
3
4
  * @param arr array-like iterable object
4
5
  * @returns a new Float32Array
5
6
  */
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Shortcut for `Float64Array.from()` static method.
3
+ *
3
4
  * @param arr array-like iterable object
4
5
  * @returns a new Float64Array
5
6
  */
@@ -1,11 +1,43 @@
1
+ /**
2
+ * Overloads for Object.assign.
3
+ *
4
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/object-assign/index.d.ts
5
+ */
6
+ declare function ObjectAssignTyped<T, U>(target: T, source: U): T & U;
7
+ declare function ObjectAssignTyped<T, U, V>(target: T, source1: U, source2: V): T & U & V;
8
+ declare function ObjectAssignTyped<T, U, V, W>(
9
+ target: T,
10
+ source1: U,
11
+ source2: V,
12
+ source3: W,
13
+ ): T & U & V & W;
14
+ declare function ObjectAssignTyped<T, U, V, W, Q>(
15
+ target: T,
16
+ source1: U,
17
+ source2: V,
18
+ source3: W,
19
+ source4: Q,
20
+ ): T & U & V & W & Q;
21
+ declare function ObjectAssignTyped<T, U, V, W, Q, R>(
22
+ target: T,
23
+ source1: U,
24
+ source2: V,
25
+ source3: W,
26
+ source4: Q,
27
+ source5: R,
28
+ ): T & U & V & W & Q & R;
29
+ declare function ObjectAssignTyped(target: any, ...sources: any[]): any;
30
+
1
31
  /**
2
32
  * Shortcut for `Object.assign()` static method.
33
+ *
3
34
  * @param obj a target object
4
35
  * @param source source object(s)
5
36
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
6
37
  */
7
-
8
- const ObjectAssign = <A extends {}, B>(obj: A, ...source: B[]): B extends any[] ? any : A & B =>
9
- Object.assign(obj, ...source);
38
+ const ObjectAssign: typeof ObjectAssignTyped = <A extends Record<string, any>, B>(
39
+ obj: A,
40
+ ...source: B[]
41
+ ): B extends Record<string, any>[] ? any : A & B => Object.assign(obj, ...source);
10
42
 
11
43
  export default ObjectAssign;
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Shortcut for `Object.entries()` static method.
3
+ *
3
4
  * @param obj a target object
4
5
  * @returns the entries of an object in an array format [key, value][]
5
6
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
6
7
  */
7
- const ObjectEntries = <O extends {}>(obj: O) => Object.entries(obj) as [keyof O, O[keyof O]][];
8
+ const ObjectEntries = <O extends Record<string, any>>(obj: O) =>
9
+ Object.entries(obj) as [keyof O, O[keyof O]][];
8
10
 
9
11
  export default ObjectEntries;
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Shortcut for `Object.keys()` static method.
3
+ *
3
4
  * @param obj a target object
4
5
  * @returns an array with object keys
5
6
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
6
7
  */
7
- const ObjectKeys = <O extends {}>(obj: O) => Object.keys(obj) as (keyof O)[];
8
+ const ObjectKeys = <O extends Record<string, any>>(obj: O) => Object.keys(obj) as (keyof O)[];
8
9
 
9
10
  export default ObjectKeys;
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Shortcut for `Object.values()` static method.
3
+ *
3
4
  * @param obj a target object
4
5
  * @returns an array with the object values
5
6
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
6
7
  */
7
- const ObjectValues = <O extends {}>(obj: O) => Object.values(obj) as (O[keyof O])[];
8
+ const ObjectValues = <O extends Record<string, unknown>>(obj: O): O[keyof O][] =>
9
+ Object.values(obj) as O[keyof O][];
8
10
 
9
11
  export default ObjectValues;
@@ -4,15 +4,19 @@ import ObjectAssign from './ObjectAssign';
4
4
 
5
5
  /**
6
6
  * Returns a namespaced `CustomEvent` specific to each component.
7
- * @param EventType Event.type
7
+ *
8
+ * @param eventType Event.type
8
9
  * @param config Event.options | Event.properties
9
10
  * @returns a new namespaced event
10
11
  */
11
- const OriginalEvent = <T>(EventType: string, config?: CustomEventInit<T>): OriginalEvent<T> => {
12
- const OriginalCustomEvent = new CustomEvent<T>(EventType, {
12
+ const createCustomEvent = <T extends OriginalEvent>(
13
+ eventType: string,
14
+ config?: CustomEventInit<any>,
15
+ ): T => {
16
+ const OriginalCustomEvent = new CustomEvent<any>(eventType, {
13
17
  cancelable: true,
14
18
  bubbles: true,
15
- } as CustomEventInit<T>);
19
+ } as CustomEventInit<any>) as T;
16
20
 
17
21
  /* istanbul ignore else */
18
22
  if (isObject(config)) {
@@ -21,4 +25,4 @@ const OriginalEvent = <T>(EventType: string, config?: CustomEventInit<T>): Origi
21
25
  return OriginalCustomEvent;
22
26
  };
23
27
 
24
- export default OriginalEvent;
28
+ export default createCustomEvent;
@@ -8,29 +8,32 @@ import ObjectEntries from './ObjectEntries';
8
8
  * which allows you to create a new `HTMLElement` for a given `tagName`
9
9
  * or based on an object with specific non-readonly attributes with string values:
10
10
  * `id`, `className`, `textContent`, `style`, etc.
11
+ *
11
12
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
12
13
  *
13
14
  * @param param `tagName` or object
14
- * @return a new `HTMLElement` or `Element`
15
+ * @return a new `HTMLElement`
15
16
  */
16
- const createElement = (param?: string | Partial<HTMLElement>): HTMLElement | undefined => {
17
+ const createElement = (
18
+ param?: string | Exclude<HTMLElement, ((...args: any[]) => any) | object>,
19
+ ): HTMLElement | undefined => {
17
20
  if (!param) return undefined;
18
21
 
19
- if (typeof param === 'string') {
22
+ if (isString(param)) {
20
23
  return getDocument().createElement(param);
21
24
  }
22
25
 
23
26
  const { tagName } = param;
24
- const newElement = createElement(tagName);
27
+ const newElement = createElement(tagName as string);
25
28
 
26
29
  if (!newElement) return undefined;
27
30
 
28
- const attr = { ...param };
31
+ const attr = { ...(param as Record<string, unknown>) };
29
32
  delete attr.tagName;
30
33
 
31
34
  ObjectEntries(attr).forEach(([key, value]) => {
32
- if (isString(value)) {
33
- setAttribute(newElement, key, value);
35
+ if (isString(key as string) && isString(value as string)) {
36
+ setAttribute(newElement, key as string, value as string);
34
37
  }
35
38
  });
36
39
  return newElement;
@@ -8,16 +8,20 @@ import isString from '../is/isString';
8
8
  * which allows you to create a new `HTMLElement` for a given `tagName`
9
9
  * or based on an object with specific non-readonly attributes with string values:
10
10
  * `id`, `className`, `textContent`, `style`, etc.
11
+ *
11
12
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS
12
13
  *
13
14
  * @param ns `namespaceURI` to associate with the new `HTMLElement`
14
15
  * @param param `tagName` or object
15
16
  * @return a new `HTMLElement`
16
17
  */
17
- const createElementNS = (ns: string, param?: string | Partial<HTMLElement>): HTMLElement | undefined => {
18
+ const createElementNS = (
19
+ ns: string,
20
+ param?: string | Exclude<HTMLElement, ((...args: any[]) => any) | object>,
21
+ ): HTMLElement | undefined => {
18
22
  if (!ns || !param) return undefined;
19
23
 
20
- if (typeof param === 'string') {
24
+ if (isString(param)) {
21
25
  return getDocument().createElementNS(ns, param) as HTMLElement;
22
26
  }
23
27
 
@@ -26,12 +30,12 @@ const createElementNS = (ns: string, param?: string | Partial<HTMLElement>): HTM
26
30
 
27
31
  if (!newElement) return undefined;
28
32
 
29
- const attr = { ...param };
33
+ const attr = { ...(param as Record<string, unknown>) };
30
34
  delete attr.tagName;
31
35
 
32
36
  ObjectEntries(attr).forEach(([key, value]) => {
33
- if (isString(value)) {
34
- setAttribute(newElement, key, value);
37
+ if (isString(key as string) && isString(value as string)) {
38
+ setAttribute(newElement, key as string, value as string);
35
39
  }
36
40
  });
37
41
 
package/src/misc/data.ts CHANGED
@@ -1,67 +1,79 @@
1
1
  import isHTMLElement from '../is/isHTMLElement';
2
2
 
3
- type ComponentData = Record<string, any>;
4
- type ElementComponentMap = Map<HTMLElement, ComponentData>;
5
- type ComponentDataMap = Map<string, ElementComponentMap>;
3
+ type MConstructor<T extends new (...args: any[]) => any> = new (
4
+ ...args: ConstructorParameters<T>
5
+ ) => InstanceType<T>;
6
6
 
7
- const componentData: ComponentDataMap = new Map();
7
+ const componentData = new Map<MConstructor<any>, Map<HTMLElement, InstanceType<any>>>();
8
8
 
9
9
  /**
10
10
  * An interface for web components background data.
11
+ *
11
12
  * @see https://github.com/thednp/bootstrap.native/blob/master/src/components/base-component.js
12
13
  */
13
14
  const Data = {
14
15
  /**
15
16
  * Sets web components data.
17
+ *
16
18
  * @param element target element
17
19
  * @param component the component's name or a unique key
18
20
  * @param instance the component instance
19
21
  */
20
- set: <T>(element: HTMLElement, component: string, instance: T): void => {
22
+ set: <T extends MConstructor<T>>(
23
+ element: HTMLElement,
24
+ component: T,
25
+ instance: InstanceType<T>,
26
+ ): void => {
21
27
  if (!isHTMLElement(element)) return;
22
28
 
23
29
  /* istanbul ignore else */
24
30
  if (!componentData.has(component)) {
25
- componentData.set(component, new Map());
31
+ componentData.set(component, new Map<HTMLElement, InstanceType<T>>());
26
32
  }
27
33
 
28
- const instanceMap = componentData.get(component);
34
+ const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
29
35
  // not undefined, but defined right above
30
- (instanceMap as ElementComponentMap).set(element, instance);
36
+ instanceMap.set(element, instance);
31
37
  },
32
38
 
33
39
  /**
34
40
  * Returns all instances for specified component.
41
+ *
35
42
  * @param component the component's name or a unique key
36
43
  * @returns all the component instances
37
44
  */
38
- getAllFor: (component: string): ElementComponentMap | null => {
39
- const instanceMap = componentData.get(component);
45
+ getAllFor: <T extends MConstructor<T>>(
46
+ component: T,
47
+ ): Map<HTMLElement, InstanceType<T>> | null => {
48
+ const instanceMap = componentData.get(component) as Map<HTMLElement, InstanceType<T>>;
40
49
 
41
50
  return instanceMap || null;
42
51
  },
43
52
 
44
53
  /**
45
54
  * Returns the instance associated with the target.
55
+ *
46
56
  * @param element target element
47
57
  * @param component the component's name or a unique key
48
58
  * @returns the instance
49
59
  */
50
- get: <T>(element: HTMLElement, component: string): T | null => {
60
+ get: <T extends MConstructor<T>>(element: HTMLElement, component: T): InstanceType<T> | null => {
51
61
  if (!isHTMLElement(element) || !component) return null;
52
- const instanceMap = Data.getAllFor(component);
62
+ const instanceMap = Data.getAllFor<T>(component);
53
63
  const instance = element && instanceMap && instanceMap.get(element);
54
64
 
55
- return (instance as T) || null;
65
+ // return (instance as T) || null;
66
+ return instance || null;
56
67
  },
57
68
 
58
69
  /**
59
70
  * Removes web components data.
71
+ *
60
72
  * @param element target element
61
73
  * @param component the component's name or a unique key
62
74
  */
63
- remove: (element: HTMLElement, component: string): void => {
64
- const instanceMap = Data.getAllFor(component);
75
+ remove: <T extends MConstructor<T>>(element: HTMLElement, component: T): void => {
76
+ const instanceMap = Data.getAllFor<T>(component);
65
77
  if (!instanceMap || !isHTMLElement(element)) return;
66
78
 
67
79
  instanceMap.delete(element);
@@ -76,6 +88,9 @@ const Data = {
76
88
  /**
77
89
  * An alias for `Data.get()`.
78
90
  */
79
- export const getInstance = <T>(target: HTMLElement, component: string): T | null => Data.get<T>(target, component);
91
+ export const getInstance = <T extends MConstructor<T>>(
92
+ target: HTMLElement,
93
+ component: T,
94
+ ): InstanceType<T> | null => Data.get<T>(target, component);
80
95
 
81
96
  export default Data;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * JavaScript `Array` distinct.
3
+ *
3
4
  * @see https://codeburst.io/javascript-array-distinct-5edc93501dc4
4
5
  *
5
6
  * @example
@@ -1,28 +1,30 @@
1
+ type NormalValue = boolean | number | string | ((...args: any[]) => any) | null;
2
+
1
3
  /**
2
4
  * Utility to normalize component options
3
5
  *
4
6
  * @param value the input value
5
7
  * @return the normalized value
6
8
  */
7
- const normalizeValue = (value?: any): any => {
8
- if (['true', true].includes(value)) {
9
+ const normalizeValue = (value?: boolean | number | string): NormalValue => {
10
+ if (['true', true].includes(value as boolean)) {
9
11
  return true;
10
12
  }
11
13
 
12
- if (['false', false].includes(value)) {
14
+ if (['false', false].includes(value as boolean)) {
13
15
  return false;
14
16
  }
15
17
 
16
- if (['null', '', null].includes(value)) {
18
+ if (['null', '', null, undefined].includes(value as string | undefined)) {
17
19
  return null;
18
20
  }
19
21
 
20
- if (value !== '' && !Number.isNaN(+value)) {
21
- return +value;
22
+ if (value !== '' && !Number.isNaN(+(value as string))) {
23
+ return +(value as string);
22
24
  }
23
25
 
24
26
  // string / function / HTMLElement / object / undefined
25
- return value;
27
+ return value as NormalValue;
26
28
  };
27
29
 
28
30
  export default normalizeValue;
@@ -5,13 +5,14 @@ import isString from '../is/isString';
5
5
 
6
6
  /**
7
7
  * Shortcut for multiple uses of `HTMLElement.style.propertyName` method.
8
+ *
8
9
  * @param element target element
9
10
  * @param styles attribute value
10
11
  */
11
12
  const setElementStyle = (element: HTMLElement, styles: Partial<CSS4Declaration>): void => {
12
13
  ObjectEntries(styles).forEach(([key, value]) => {
13
- if (value && isString(key) && key.includes('--')) {
14
- element.style.setProperty(key, value);
14
+ if (value && isString(key as string) && (key as string).includes('--')) {
15
+ element.style.setProperty(key as string, value);
15
16
  } else {
16
17
  const propObject: Partial<CSS4Declaration> = {};
17
18
  propObject[key] = value;
package/src/misc/timer.ts CHANGED
@@ -5,14 +5,16 @@ import isNumber from '../is/isNumber';
5
5
  type KeyMap = Map<string, number>;
6
6
  type TimeMap = Map<HTMLElement, number | KeyMap>;
7
7
 
8
- const TimeCache: TimeMap = new Map();
8
+ const TimeCache: TimeMap = new Map() as TimeMap;
9
9
  /**
10
10
  * An interface for one or more `TimerHandler`s per `Element`.
11
+ *
11
12
  * @see https://github.com/thednp/navbar/
12
13
  */
13
14
  const Timer = {
14
15
  /**
15
16
  * Sets a new timeout timer for an element, or element -> key association.
17
+ *
16
18
  * @param element target element
17
19
  * @param callback the callback
18
20
  * @param delay the execution delay
@@ -27,14 +29,17 @@ const Timer = {
27
29
  if (!TimeCache.has(element)) {
28
30
  TimeCache.set(element, new Map());
29
31
  }
32
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
30
33
  (TimeCache.get(element) as KeyMap).set(key, setTimeout(callback, delay));
31
34
  } else {
35
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
32
36
  TimeCache.set(element, setTimeout(callback, delay));
33
37
  }
34
38
  },
35
39
 
36
40
  /**
37
41
  * Returns the timer associated with the target.
42
+ *
38
43
  * @param element target element
39
44
  * @param key a unique
40
45
  * @returns the timer
@@ -43,16 +48,17 @@ const Timer = {
43
48
  if (!isHTMLElement(element)) return null;
44
49
  const keyTimers = TimeCache.get(element);
45
50
 
46
- if (key && isMap(keyTimers)) {
47
- return keyTimers.get(key) || /* istanbul ignore next */ null;
48
- } else if (isNumber(keyTimers)) {
49
- return keyTimers;
51
+ if (key && keyTimers && isMap(keyTimers as KeyMap)) {
52
+ return (keyTimers as KeyMap).get(key) || /* istanbul ignore next */ null;
53
+ } else if (isNumber(keyTimers as number)) {
54
+ return keyTimers as number;
50
55
  }
51
56
  return null;
52
57
  },
53
58
 
54
59
  /**
55
60
  * Clears the element's timer.
61
+ *
56
62
  * @param element target element
57
63
  * @param key a unique key
58
64
  */
@@ -61,15 +67,12 @@ const Timer = {
61
67
 
62
68
  const keyTimers = TimeCache.get(element);
63
69
 
64
- if (key && key.length && isMap(keyTimers)) {
70
+ if (key && key.length && isMap(keyTimers as KeyMap)) {
71
+ clearTimeout((keyTimers as KeyMap).get(key));
72
+ (keyTimers as KeyMap).delete(key);
65
73
  /* istanbul ignore else */
66
- if (isMap(keyTimers)) {
67
- clearTimeout(keyTimers.get(key));
68
- keyTimers.delete(key);
69
- /* istanbul ignore else */
70
- if (keyTimers.size === 0) {
71
- TimeCache.delete(element);
72
- }
74
+ if ((keyTimers as KeyMap).size === 0) {
75
+ TimeCache.delete(element);
73
76
  }
74
77
  } else {
75
78
  clearTimeout(keyTimers as number);
@@ -5,6 +5,7 @@ import getElementsByTagName from './getElementsByTagName';
5
5
  /**
6
6
  * Returns an `Array` of `Node` elements that are registered as
7
7
  * `CustomElement`.
8
+ *
8
9
  * @see https://stackoverflow.com/questions/27334365/how-to-get-list-of-registered-custom-elements
9
10
  *
10
11
  * @param parent parent to look into
@@ -9,9 +9,14 @@ import isNode from '../is/isNode';
9
9
  * @param parent optional Element to look into
10
10
  * @return the 'HTMLCollection'
11
11
  */
12
- const getElementsByClassName = (selector: string, parent?: ParentNode): HTMLCollectionOf<HTMLElement> => {
12
+ const getElementsByClassName = (
13
+ selector: string,
14
+ parent?: ParentNode,
15
+ ): HTMLCollectionOf<HTMLElement> => {
13
16
  const lookUp = parent && isNode(parent) ? parent : getDocument();
14
- return (lookUp as HTMLElement | Document).getElementsByClassName(selector) as HTMLCollectionOf<HTMLElement>;
17
+ return (lookUp as HTMLElement | Document).getElementsByClassName(
18
+ selector,
19
+ ) as HTMLCollectionOf<HTMLElement>;
15
20
  };
16
21
 
17
22
  export default getElementsByClassName;
@@ -9,7 +9,10 @@ import isNode from '../is/isNode';
9
9
  * @param parent optional Element to look into
10
10
  * @return the 'HTMLCollection'
11
11
  */
12
- const getElementsByTagName = (selector: string, parent?: ParentNode): HTMLCollectionOf<HTMLElement> => {
12
+ const getElementsByTagName = (
13
+ selector: string,
14
+ parent?: ParentNode,
15
+ ): HTMLCollectionOf<HTMLElement> => {
13
16
  const lookUp = isNode(parent) ? parent : getDocument();
14
17
  return (lookUp as Document).getElementsByTagName(selector) as HTMLCollectionOf<HTMLElement>;
15
18
  };
@@ -10,12 +10,12 @@ import isNode from '../is/isNode';
10
10
  * @return the `HTMLElement` or `querySelector` result
11
11
  */
12
12
  const querySelector = (selector: Node | string, parent?: ParentNode): HTMLElement | null => {
13
- if (isNode(selector)) {
13
+ if (isNode(selector as Node)) {
14
14
  return selector as HTMLElement;
15
15
  }
16
16
  const lookUp = parent && isNode(parent) ? parent : getDocument();
17
17
 
18
- return lookUp.querySelector(selector);
18
+ return lookUp.querySelector(selector as string);
19
19
  };
20
20
 
21
21
  export default querySelector;
@@ -2,5 +2,7 @@
2
2
  * A global namespace for mouse hover events.
3
3
  */
4
4
  const mouseHoverEvents =
5
- 'onmouseleave' in document ? ['mouseenter', 'mouseleave'] : /* istanbul ignore next */ ['mouseover', 'mouseout'];
5
+ 'onmouseleave' in document
6
+ ? ['mouseenter', 'mouseleave']
7
+ : /* istanbul ignore next */ ['mouseover', 'mouseout'];
6
8
  export default mouseHoverEvents;