@thednp/shorty 2.0.5 → 2.0.6

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 (220) hide show
  1. package/README.md +0 -2
  2. package/dist/shorty.cjs +6 -5
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +13 -12
  5. package/dist/shorty.js +6 -5
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +90 -59
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +7 -17
  10. package/src/attr/hasAttribute.ts +2 -1
  11. package/src/attr/hasAttributeNS.ts +5 -2
  12. package/src/attr/removeAttribute.ts +2 -1
  13. package/src/attr/removeAttributeNS.ts +5 -2
  14. package/src/attr/setAttributeNS.ts +6 -2
  15. package/src/boolean/isApple.ts +6 -4
  16. package/src/boolean/isFirefox.ts +2 -2
  17. package/src/boolean/isMobile.ts +3 -3
  18. package/src/boolean/support3DTransform.ts +4 -2
  19. package/src/boolean/supportAnimation.ts +4 -2
  20. package/src/boolean/supportPassive.ts +5 -5
  21. package/src/boolean/supportTouch.ts +3 -2
  22. package/src/boolean/supportTransform.ts +4 -2
  23. package/src/boolean/supportTransition.ts +4 -2
  24. package/src/event/off.ts +5 -1
  25. package/src/event/on.ts +5 -1
  26. package/src/event/one.ts +5 -5
  27. package/src/get/getBoundingClientRect.ts +10 -5
  28. package/src/get/getDocument.ts +4 -4
  29. package/src/get/getDocumentBody.ts +1 -1
  30. package/src/get/getDocumentElement.ts +1 -1
  31. package/src/get/getDocumentHead.ts +4 -2
  32. package/src/get/getElementAnimationDelay.ts +9 -6
  33. package/src/get/getElementAnimationDuration.ts +9 -6
  34. package/src/get/getElementStyle.ts +2 -2
  35. package/src/get/getElementTransitionDelay.ts +9 -8
  36. package/src/get/getElementTransitionDuration.ts +9 -8
  37. package/src/get/getNodeScroll.ts +4 -2
  38. package/src/get/getParentNode.ts +5 -5
  39. package/src/get/getRectRelativeToOffsetParent.ts +8 -5
  40. package/src/get/getUID.ts +1 -1
  41. package/src/get/getWindow.ts +2 -2
  42. package/src/index.ts +424 -420
  43. package/src/interface/event.d.ts +49 -41
  44. package/src/interface/fn.ts +1 -0
  45. package/src/interface/originalEvent.d.ts +1 -1
  46. package/src/is/isArray.ts +2 -1
  47. package/src/is/isCanvas.ts +2 -2
  48. package/src/is/isCustomElement.ts +5 -3
  49. package/src/is/isDocument.ts +3 -2
  50. package/src/is/isElement.ts +3 -2
  51. package/src/is/isElementInScrollRange.ts +3 -3
  52. package/src/is/isElementInViewport.ts +5 -4
  53. package/src/is/isElementsArray.ts +2 -2
  54. package/src/is/isFunction.ts +4 -2
  55. package/src/is/isHTMLCollection.ts +2 -2
  56. package/src/is/isHTMLElement.ts +1 -1
  57. package/src/is/isHTMLImageElement.ts +2 -2
  58. package/src/is/isJSON.ts +2 -2
  59. package/src/is/isMap.ts +3 -3
  60. package/src/is/isMedia.ts +9 -3
  61. package/src/is/isNode.ts +5 -3
  62. package/src/is/isNodeList.ts +2 -2
  63. package/src/is/isNumber.ts +2 -1
  64. package/src/is/isObject.ts +1 -1
  65. package/src/is/isRTL.ts +2 -2
  66. package/src/is/isSVGElement.ts +2 -2
  67. package/src/is/isScaledElement.ts +4 -3
  68. package/src/is/isShadowRoot.ts +2 -2
  69. package/src/is/isString.ts +2 -1
  70. package/src/is/isTableElement.ts +6 -3
  71. package/src/is/isWeakMap.ts +3 -3
  72. package/src/is/isWindow.ts +2 -2
  73. package/src/misc/Float32ArrayFrom.ts +3 -2
  74. package/src/misc/Float64ArrayFrom.ts +3 -2
  75. package/src/misc/ObjectAssign.ts +15 -4
  76. package/src/misc/ObjectEntries.ts +1 -1
  77. package/src/misc/ObjectHasOwn.ts +3 -2
  78. package/src/misc/ObjectKeys.ts +2 -1
  79. package/src/misc/ObjectValues.ts +3 -2
  80. package/src/misc/createCustomEvent.ts +7 -4
  81. package/src/misc/createElement.ts +6 -4
  82. package/src/misc/createElementNS.ts +3 -3
  83. package/src/misc/data.ts +2 -2
  84. package/src/misc/dispatchEvent.ts +2 -1
  85. package/src/misc/distinct.ts +2 -1
  86. package/src/misc/emulateAnimationEnd.ts +8 -5
  87. package/src/misc/emulateTransitionEnd.ts +8 -5
  88. package/src/misc/focus.ts +2 -1
  89. package/src/misc/focusTrap.ts +17 -14
  90. package/src/misc/getInstance.ts +1 -1
  91. package/src/misc/normalizeOptions.ts +15 -12
  92. package/src/misc/normalizeValue.ts +8 -6
  93. package/src/misc/setElementStyle.ts +9 -6
  94. package/src/misc/timer.ts +12 -5
  95. package/src/selectors/closest.ts +2 -2
  96. package/src/selectors/getCustomElements.ts +3 -3
  97. package/src/selectors/getElementById.ts +1 -1
  98. package/src/selectors/getElementsByClassName.ts +9 -4
  99. package/src/selectors/getElementsByTagName.ts +9 -4
  100. package/src/selectors/matches.ts +2 -1
  101. package/src/selectors/querySelector.ts +3 -3
  102. package/src/selectors/querySelectorAll.ts +2 -2
  103. package/src/strings/DOMContentLoadedEvent.ts +1 -1
  104. package/src/strings/DOMMouseScrollEvent.ts +1 -1
  105. package/src/strings/abortEvent.ts +1 -1
  106. package/src/strings/addEventListener.ts +1 -1
  107. package/src/strings/animationDelay.ts +1 -1
  108. package/src/strings/animationDuration.ts +1 -1
  109. package/src/strings/animationEndEvent.ts +1 -1
  110. package/src/strings/animationName.ts +1 -1
  111. package/src/strings/ariaChecked.ts +1 -1
  112. package/src/strings/ariaDescribedBy.ts +1 -1
  113. package/src/strings/ariaDescription.ts +1 -1
  114. package/src/strings/ariaExpanded.ts +1 -1
  115. package/src/strings/ariaHasPopup.ts +1 -1
  116. package/src/strings/ariaHidden.ts +1 -1
  117. package/src/strings/ariaLabel.ts +1 -1
  118. package/src/strings/ariaLabelledBy.ts +1 -1
  119. package/src/strings/ariaModal.ts +1 -1
  120. package/src/strings/ariaPressed.ts +1 -1
  121. package/src/strings/ariaSelected.ts +1 -1
  122. package/src/strings/ariaValueMax.ts +1 -1
  123. package/src/strings/ariaValueMin.ts +1 -1
  124. package/src/strings/ariaValueNow.ts +1 -1
  125. package/src/strings/ariaValueText.ts +1 -1
  126. package/src/strings/beforeunloadEvent.ts +1 -1
  127. package/src/strings/bezierEasings.ts +25 -25
  128. package/src/strings/blurEvent.ts +1 -1
  129. package/src/strings/changeEvent.ts +1 -1
  130. package/src/strings/contextmenuEvent.ts +1 -1
  131. package/src/strings/dragEvent.ts +1 -1
  132. package/src/strings/dragendEvent.ts +1 -1
  133. package/src/strings/dragenterEvent.ts +1 -1
  134. package/src/strings/dragleaveEvent.ts +1 -1
  135. package/src/strings/dragoverEvent.ts +1 -1
  136. package/src/strings/dragstartEvent.ts +1 -1
  137. package/src/strings/errorEvent.ts +1 -1
  138. package/src/strings/focusEvent.ts +1 -1
  139. package/src/strings/focusEvents.ts +1 -1
  140. package/src/strings/focusinEvent.ts +1 -1
  141. package/src/strings/focusoutEvent.ts +1 -1
  142. package/src/strings/gesturechangeEvent.ts +1 -1
  143. package/src/strings/gestureendEvent.ts +1 -1
  144. package/src/strings/gesturestartEvent.ts +1 -1
  145. package/src/strings/keyAlt.ts +1 -1
  146. package/src/strings/keyArrowDown.ts +1 -1
  147. package/src/strings/keyArrowLeft.ts +1 -1
  148. package/src/strings/keyArrowRight.ts +1 -1
  149. package/src/strings/keyArrowUp.ts +1 -1
  150. package/src/strings/keyBackspace.ts +1 -1
  151. package/src/strings/keyCapsLock.ts +1 -1
  152. package/src/strings/keyControl.ts +1 -1
  153. package/src/strings/keyDelete.ts +1 -1
  154. package/src/strings/keyEnter.ts +1 -1
  155. package/src/strings/keyEscape.ts +1 -1
  156. package/src/strings/keyInsert.ts +1 -1
  157. package/src/strings/keyMeta.ts +1 -1
  158. package/src/strings/keyNumpadEnter.ts +1 -1
  159. package/src/strings/keyPause.ts +1 -1
  160. package/src/strings/keyScrollLock.ts +1 -1
  161. package/src/strings/keyShift.ts +1 -1
  162. package/src/strings/keySpace.ts +1 -1
  163. package/src/strings/keyTab.ts +1 -1
  164. package/src/strings/keyboardEventKeys.ts +19 -19
  165. package/src/strings/keydownEvent.ts +1 -1
  166. package/src/strings/keypressEvent.ts +1 -1
  167. package/src/strings/keyupEvent.ts +1 -1
  168. package/src/strings/loadEvent.ts +1 -1
  169. package/src/strings/loadstartEvent.ts +1 -1
  170. package/src/strings/mouseClickEvents.ts +1 -1
  171. package/src/strings/mouseHoverEvents.ts +3 -4
  172. package/src/strings/mouseSwipeEvents.ts +4 -4
  173. package/src/strings/mouseclickEvent.ts +1 -1
  174. package/src/strings/mousedblclickEvent.ts +1 -1
  175. package/src/strings/mousedownEvent.ts +1 -1
  176. package/src/strings/mouseenterEvent.ts +1 -1
  177. package/src/strings/mousehoverEvent.ts +1 -1
  178. package/src/strings/mouseinEvent.ts +1 -1
  179. package/src/strings/mouseleaveEvent.ts +1 -1
  180. package/src/strings/mousemoveEvent.ts +1 -1
  181. package/src/strings/mouseoutEvent.ts +1 -1
  182. package/src/strings/mouseoverEvent.ts +1 -1
  183. package/src/strings/mouseupEvent.ts +1 -1
  184. package/src/strings/mousewheelEvent.ts +1 -1
  185. package/src/strings/moveEvent.ts +1 -1
  186. package/src/strings/nativeEvents.ts +50 -50
  187. package/src/strings/offsetHeight.ts +1 -1
  188. package/src/strings/offsetWidth.ts +1 -1
  189. package/src/strings/orientationchangeEvent.ts +1 -1
  190. package/src/strings/pointercancelEvent.ts +1 -1
  191. package/src/strings/pointerdownEvent.ts +1 -1
  192. package/src/strings/pointerleaveEvent.ts +1 -1
  193. package/src/strings/pointermoveEvent.ts +1 -1
  194. package/src/strings/pointerupEvent.ts +1 -1
  195. package/src/strings/readystatechangeEvent.ts +1 -1
  196. package/src/strings/removeEventListener.ts +1 -1
  197. package/src/strings/resetEvent.ts +1 -1
  198. package/src/strings/resizeEvent.ts +1 -1
  199. package/src/strings/scrollEvent.ts +1 -1
  200. package/src/strings/scrollHeight.ts +1 -1
  201. package/src/strings/scrollWidth.ts +1 -1
  202. package/src/strings/selectEvent.ts +1 -1
  203. package/src/strings/selectendEvent.ts +1 -1
  204. package/src/strings/selectstartEvent.ts +1 -1
  205. package/src/strings/submitEvent.ts +1 -1
  206. package/src/strings/tabindex.ts +1 -1
  207. package/src/strings/touchEvents.ts +4 -4
  208. package/src/strings/touchcancelEvent.ts +1 -1
  209. package/src/strings/touchendEvent.ts +1 -1
  210. package/src/strings/touchmoveEvent.ts +1 -1
  211. package/src/strings/touchstartEvent.ts +1 -1
  212. package/src/strings/transitionDelay.ts +1 -1
  213. package/src/strings/transitionDuration.ts +1 -1
  214. package/src/strings/transitionEndEvent.ts +1 -1
  215. package/src/strings/transitionProperty.ts +1 -1
  216. package/src/strings/unloadEvent.ts +1 -1
  217. package/src/strings/userAgentData.ts +2 -2
  218. package/vite.config.mts +1 -0
  219. package/vitest.config-ui.mts +5 -0
  220. package/vitest.config.mts +5 -0
@@ -5,6 +5,7 @@
5
5
  * @returns an array with object keys
6
6
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
7
  */
8
- const ObjectKeys = <O extends Record<string, any>>(obj: O) => Object.keys(obj) as (keyof O)[];
8
+ const ObjectKeys = <O extends Record<keyof O, unknown>>(obj: O) =>
9
+ Object.keys(obj) as (keyof O)[];
9
10
 
10
11
  export default ObjectKeys;
@@ -5,7 +5,8 @@
5
5
  * @returns an array with the object values
6
6
  * @see https://github.com/devinrhode2/ObjectTyped/blob/master/src/index.ts
7
7
  */
8
- const ObjectValues = <O extends Record<string, unknown>>(obj: O): O[keyof O][] =>
9
- Object.values(obj) as O[keyof O][];
8
+ const ObjectValues = <O extends Record<string, unknown>>(
9
+ obj: O,
10
+ ): O[keyof O][] => Object.values(obj) as O[keyof O][];
10
11
 
11
12
  export default ObjectValues;
@@ -1,6 +1,6 @@
1
- import type { OriginalEvent } from '../interface/originalEvent';
2
- import isObject from '../is/isObject';
3
- import ObjectAssign from './ObjectAssign';
1
+ import type { OriginalEvent } from "../interface/originalEvent";
2
+ import isObject from "../is/isObject";
3
+ import ObjectAssign from "./ObjectAssign";
4
4
 
5
5
  /**
6
6
  * Returns a namespaced `CustomEvent` specific to each component.
@@ -9,7 +9,10 @@ import ObjectAssign from './ObjectAssign';
9
9
  * @param config Event.options | Event.properties
10
10
  * @returns a new namespaced event
11
11
  */
12
- const createCustomEvent = <O extends unknown & Record<string, unknown>, T extends OriginalEvent>(
12
+ const createCustomEvent = <
13
+ O extends unknown & Record<string, unknown>,
14
+ T extends OriginalEvent,
15
+ >(
13
16
  eventType: string,
14
17
  config?: O,
15
18
  ): T => {
@@ -1,6 +1,6 @@
1
- import isString from '../is/isString';
2
- import getDocument from '../get/getDocument';
3
- import ObjectAssign from './ObjectAssign';
1
+ import isString from "../is/isString";
2
+ import getDocument from "../get/getDocument";
3
+ import ObjectAssign from "./ObjectAssign";
4
4
 
5
5
  /**
6
6
  * Shortie for `document.createElement` method
@@ -13,7 +13,9 @@ import ObjectAssign from './ObjectAssign';
13
13
  * @param param `tagName` or object
14
14
  * @return a new `HTMLElement`
15
15
  */
16
- const createElement = <T extends HTMLElement>(param?: string | Partial<T>): T | undefined => {
16
+ const createElement = <T extends HTMLElement>(
17
+ param?: string | Partial<T>,
18
+ ): T | undefined => {
17
19
  if (!param) return undefined;
18
20
 
19
21
  if (isString(param)) {
@@ -1,6 +1,6 @@
1
- import getDocument from '../get/getDocument';
2
- import ObjectAssign from './ObjectAssign';
3
- import isString from '../is/isString';
1
+ import getDocument from "../get/getDocument";
2
+ import ObjectAssign from "./ObjectAssign";
3
+ import isString from "../is/isString";
4
4
 
5
5
  /**
6
6
  * Shortie for `document.createElementNS` method
package/src/misc/data.ts CHANGED
@@ -1,6 +1,6 @@
1
- import isHTMLElement from '../is/isHTMLElement';
1
+ import isHTMLElement from "../is/isHTMLElement";
2
2
 
3
- const componentData = new Map<string, Map<HTMLElement, any>>();
3
+ const componentData = new Map<string, Map<HTMLElement, unknown>>();
4
4
 
5
5
  /**
6
6
  * An interface for web components background data.
@@ -4,6 +4,7 @@
4
4
  * @param element is the target
5
5
  * @param event is the `Event` object
6
6
  */
7
- const dispatchEvent = (element: EventTarget, event: Event): boolean => element.dispatchEvent(event);
7
+ const dispatchEvent = (element: EventTarget, event: Event): boolean =>
8
+ element.dispatchEvent(event);
8
9
 
9
10
  export default dispatchEvent;
@@ -13,6 +13,7 @@
13
13
  * @param arr a clone of the target array
14
14
  * @returns the query result
15
15
  */
16
- const distinct = <T>(value: T, index: number, arr: T[]): boolean => arr.indexOf(value) === index;
16
+ const distinct = <T>(value: T, index: number, arr: T[]): boolean =>
17
+ arr.indexOf(value) === index;
17
18
 
18
19
  export default distinct;
@@ -1,7 +1,7 @@
1
- import animationEndEvent from '../strings/animationEndEvent';
2
- import getElementAnimationDelay from '../get/getElementAnimationDelay';
3
- import getElementAnimationDuration from '../get/getElementAnimationDuration';
4
- import dispatchEvent from './dispatchEvent';
1
+ import animationEndEvent from "../strings/animationEndEvent";
2
+ import getElementAnimationDelay from "../get/getElementAnimationDelay";
3
+ import getElementAnimationDuration from "../get/getElementAnimationDuration";
4
+ import dispatchEvent from "./dispatchEvent";
5
5
 
6
6
  /**
7
7
  * Utility to make sure callbacks are consistently
@@ -10,7 +10,10 @@ import dispatchEvent from './dispatchEvent';
10
10
  * @param element target
11
11
  * @param handler `animationend` callback
12
12
  */
13
- const emulateAnimationEnd = (element: HTMLElement, handler: EventListener): void => {
13
+ const emulateAnimationEnd = (
14
+ element: HTMLElement,
15
+ handler: EventListener,
16
+ ): void => {
14
17
  let called = 0;
15
18
  const endEvent = new Event(animationEndEvent);
16
19
  const duration = getElementAnimationDuration(element);
@@ -1,7 +1,7 @@
1
- import transitionEndEvent from '../strings/transitionEndEvent';
2
- import getElementTransitionDelay from '../get/getElementTransitionDelay';
3
- import getElementTransitionDuration from '../get/getElementTransitionDuration';
4
- import dispatchEvent from './dispatchEvent';
1
+ import transitionEndEvent from "../strings/transitionEndEvent";
2
+ import getElementTransitionDelay from "../get/getElementTransitionDelay";
3
+ import getElementTransitionDuration from "../get/getElementTransitionDuration";
4
+ import dispatchEvent from "./dispatchEvent";
5
5
 
6
6
  /**
7
7
  * Utility to make sure callbacks are consistently
@@ -10,7 +10,10 @@ import dispatchEvent from './dispatchEvent';
10
10
  * @param element event target
11
11
  * @param handler `transitionend` callback
12
12
  */
13
- const emulateTransitionEnd = (element: HTMLElement, handler: EventListener): void => {
13
+ const emulateTransitionEnd = (
14
+ element: HTMLElement,
15
+ handler: EventListener,
16
+ ): void => {
14
17
  let called = 0;
15
18
  const endEvent = new Event(transitionEndEvent);
16
19
  const duration = getElementTransitionDuration(element);
package/src/misc/focus.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * @param element is the target
5
5
  * @param options allows to pass additional options such as `preventScroll: boolean`
6
6
  */
7
- const focus = (element: HTMLOrSVGElement, options?: FocusOptions): void => element.focus(options);
7
+ const focus = (element: HTMLOrSVGElement, options?: FocusOptions): void =>
8
+ element.focus(options);
8
9
 
9
10
  export default focus;
@@ -1,12 +1,12 @@
1
- import ariaHidden from '../strings/ariaHidden';
2
- import focusableSelector from '../strings/focusableSelector';
3
- import querySelectorAll from '../selectors/querySelectorAll';
4
- import getAttribute from '../attr/getAttribute';
5
- import hasAttribute from '../attr/hasAttribute';
6
- import off from '../event/off';
7
- import on from '../event/on';
8
- import getDocument from '../get/getDocument';
9
- import { KeyboardEvent } from '../interface/event';
1
+ import ariaHidden from "../strings/ariaHidden";
2
+ import focusableSelector from "../strings/focusableSelector";
3
+ import querySelectorAll from "../selectors/querySelectorAll";
4
+ import getAttribute from "../attr/getAttribute";
5
+ import hasAttribute from "../attr/hasAttribute";
6
+ import off from "../event/off";
7
+ import on from "../event/on";
8
+ import getDocument from "../get/getDocument";
9
+ import { KeyboardEvent } from "../interface/event";
10
10
 
11
11
  const focusTrapMap = new Map<HTMLElement, boolean>();
12
12
 
@@ -25,8 +25,10 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
25
25
  ) {
26
26
  const { shiftKey, code } = event;
27
27
  const doc = getDocument(this);
28
- const focusableElements = [...querySelectorAll<FocusableElement>(focusableSelector, this)].filter(
29
- el => !hasAttribute(el, 'disabled') && !getAttribute(el, ariaHidden),
28
+ const focusableElements = [
29
+ ...querySelectorAll<FocusableElement>(focusableSelector, this),
30
+ ].filter(
31
+ (el) => !hasAttribute(el, "disabled") && !getAttribute(el, ariaHidden),
30
32
  );
31
33
 
32
34
  if (!focusableElements.length) return;
@@ -34,7 +36,7 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
34
36
  const lastFocusable = focusableElements[focusableElements.length - 1];
35
37
 
36
38
  // istanbul ignore else @preserve
37
- if (code === 'Tab') {
39
+ if (code === "Tab") {
38
40
  if (shiftKey && doc.activeElement === firstFocusable) {
39
41
  lastFocusable.focus();
40
42
  event.preventDefault();
@@ -49,7 +51,8 @@ function handleKeyboardNavigation<T extends HTMLElement & EventTarget>(
49
51
  * Utility to check if a designated element is affected by focus trap;
50
52
  * @param target
51
53
  */
52
- export const hasFocusTrap = (target: HTMLElement) => focusTrapMap.has(target) === true;
54
+ export const hasFocusTrap = (target: HTMLElement) =>
55
+ focusTrapMap.has(target) === true;
53
56
 
54
57
  /**
55
58
  * Utility to toggle focus trap inside a designated target element;
@@ -58,7 +61,7 @@ export const hasFocusTrap = (target: HTMLElement) => focusTrapMap.has(target) ==
58
61
  export const toggleFocusTrap = (target: HTMLElement) => {
59
62
  const isCurrentlyTrapped = hasFocusTrap(target);
60
63
  const action = !isCurrentlyTrapped ? on : off;
61
- action(target, 'keydown', handleKeyboardNavigation);
64
+ action(target, "keydown", handleKeyboardNavigation);
62
65
  if (isCurrentlyTrapped) focusTrapMap.delete(target);
63
66
  else focusTrapMap.set(target, true);
64
67
  };
@@ -1,4 +1,4 @@
1
- import Data from './data';
1
+ import Data from "./data";
2
2
 
3
3
  /**
4
4
  * An alias for `Data.get()`.
@@ -1,7 +1,7 @@
1
- import getAttribute from '../attr/getAttribute';
2
- import normalizeValue from './normalizeValue';
3
- import ObjectEntries from './ObjectEntries';
4
- import toLowerCase from './toLowerCase';
1
+ import getAttribute from "../attr/getAttribute";
2
+ import normalizeValue from "./normalizeValue";
3
+ import ObjectEntries from "./ObjectEntries";
4
+ import toLowerCase from "./toLowerCase";
5
5
  // import { optionValues } from '../types';
6
6
 
7
7
  /**
@@ -13,23 +13,25 @@ import toLowerCase from './toLowerCase';
13
13
  * @param ns component namespace
14
14
  * @return normalized component options object
15
15
  */
16
- const normalizeOptions = <T extends { [key: string]: any }>(
16
+ const normalizeOptions = <T extends { [key: string]: unknown }>(
17
17
  element: HTMLElement,
18
18
  defaultOps: T,
19
19
  inputOps: Partial<T>,
20
20
  ns?: string,
21
21
  ): T => {
22
- const INPUT = { ...inputOps };
22
+ const INPUT = { ...inputOps } as T;
23
23
  const data = { ...element.dataset };
24
24
  const normalOps = { ...defaultOps };
25
25
  const dataOps: Partial<T> = {};
26
- const title = 'title';
26
+ const title = "title";
27
27
 
28
28
  ObjectEntries(data).forEach(([k, v]) => {
29
- const key: keyof T =
30
- ns && typeof k === 'string' && k.includes(ns)
31
- ? k.replace(ns, '').replace(/[A-Z]/g, (match: string) => toLowerCase(match))
32
- : /* istanbul ignore next @preserve */ k;
29
+ const key: keyof T = ns && typeof k === "string" && k.includes(ns)
30
+ ? k.replace(ns, "").replace(
31
+ /[A-Z]/g,
32
+ (match: string) => toLowerCase(match),
33
+ )
34
+ : /* istanbul ignore next @preserve */ k;
33
35
 
34
36
  dataOps[key] = normalizeValue(v) as T[keyof T];
35
37
  });
@@ -45,7 +47,8 @@ const normalizeOptions = <T extends { [key: string]: any }>(
45
47
  } else if (k in dataOps) {
46
48
  normalOps[k] = dataOps[k] as T[keyof T];
47
49
  } else {
48
- normalOps[k] = (k === title ? getAttribute(element, title) : v) as T[keyof T];
50
+ normalOps[k] =
51
+ (k === title ? getAttribute(element, title) : v) as T[keyof T];
49
52
  }
50
53
  });
51
54
 
@@ -1,4 +1,6 @@
1
- type NormalValue = boolean | number | string | ((...args: any[]) => any) | null;
1
+ import { Fn } from "../interface/fn";
2
+
3
+ type NormalValue = boolean | number | string | Fn | null;
2
4
 
3
5
  /**
4
6
  * Utility to normalize component options
@@ -6,20 +8,20 @@ type NormalValue = boolean | number | string | ((...args: any[]) => any) | null;
6
8
  * @param value the input value
7
9
  * @return the normalized value
8
10
  */
9
- const normalizeValue = (value?: boolean | number | string): NormalValue => {
10
- if (['true', true].includes(value as boolean)) {
11
+ const normalizeValue = (value?: unknown): NormalValue => {
12
+ if (["true", true].includes(value as boolean)) {
11
13
  return true;
12
14
  }
13
15
 
14
- if (['false', false].includes(value as boolean)) {
16
+ if (["false", false].includes(value as boolean)) {
15
17
  return false;
16
18
  }
17
19
 
18
- if (['null', '', null, undefined].includes(value as string | undefined)) {
20
+ if (["null", "", null, undefined].includes(value as string | undefined)) {
19
21
  return null;
20
22
  }
21
23
 
22
- if (value !== '' && !Number.isNaN(+(value as string))) {
24
+ if (value !== "" && !Number.isNaN(+(value as string))) {
23
25
  return +(value as string);
24
26
  }
25
27
 
@@ -1,7 +1,7 @@
1
- import ObjectAssign from './ObjectAssign';
2
- import ObjectEntries from './ObjectEntries';
3
- import isString from '../is/isString';
4
- import type { CSS4Declaration } from '../interface/css4Declaration';
1
+ import ObjectAssign from "./ObjectAssign";
2
+ import ObjectEntries from "./ObjectEntries";
3
+ import isString from "../is/isString";
4
+ import type { CSS4Declaration } from "../interface/css4Declaration";
5
5
 
6
6
  /**
7
7
  * Shortcut for multiple uses of `HTMLElement.style.propertyName` method.
@@ -9,9 +9,12 @@ import type { CSS4Declaration } from '../interface/css4Declaration';
9
9
  * @param element target element
10
10
  * @param styles attribute value
11
11
  */
12
- const setElementStyle = (element: HTMLElement, styles: Partial<CSS4Declaration>): void => {
12
+ const setElementStyle = (
13
+ element: HTMLElement,
14
+ styles: Partial<CSS4Declaration>,
15
+ ): void => {
13
16
  ObjectEntries(styles).forEach(([key, value]) => {
14
- if (value && isString(key as string) && (key as string).includes('--')) {
17
+ if (value && isString(key as string) && (key as string).includes("--")) {
15
18
  element.style.setProperty(key as string, value);
16
19
  } else {
17
20
  const propObject: Partial<CSS4Declaration> = {};
package/src/misc/timer.ts CHANGED
@@ -1,6 +1,6 @@
1
- import isMap from '../is/isMap';
2
- import isHTMLElement from '../is/isHTMLElement';
3
- import isNumber from '../is/isNumber';
1
+ import isMap from "../is/isMap";
2
+ import isHTMLElement from "../is/isHTMLElement";
3
+ import isNumber from "../is/isNumber";
4
4
 
5
5
  type KeyMap = Map<string, number>;
6
6
  type TimeMap = Map<HTMLElement, number | KeyMap>;
@@ -20,7 +20,12 @@ const Timer = {
20
20
  * @param delay the execution delay
21
21
  * @param key a unique key
22
22
  */
23
- set: (element: HTMLElement, callback: TimerHandler, delay: number, key?: string): void => {
23
+ set: (
24
+ element: HTMLElement,
25
+ callback: TimerHandler,
26
+ delay: number,
27
+ key?: string,
28
+ ): void => {
24
29
  if (!isHTMLElement(element)) return;
25
30
 
26
31
  // istanbul ignore else @preserve
@@ -49,7 +54,9 @@ const Timer = {
49
54
  const keyTimers = TimeCache.get(element);
50
55
 
51
56
  if (key && keyTimers && isMap(keyTimers as KeyMap)) {
52
- return (keyTimers as KeyMap).get(key) || /* istanbul ignore next */ null;
57
+ return (keyTimers as KeyMap).get(key) ||
58
+ /* istanbul ignore next @preserve */
59
+ null;
53
60
  } else if (isNumber(keyTimers as number)) {
54
61
  return keyTimers as number;
55
62
  }
@@ -15,8 +15,8 @@ const closest = <T extends Element = HTMLElement>(
15
15
  ): HTMLElement | null => {
16
16
  return element
17
17
  ? element.closest(selector) ||
18
- // break out of `ShadowRoot`
19
- closest((element.getRootNode() as ShadowRoot).host, selector)
18
+ // break out of `ShadowRoot`
19
+ closest((element.getRootNode() as ShadowRoot).host, selector)
20
20
  : null;
21
21
  };
22
22
 
@@ -1,5 +1,5 @@
1
- import isCustomElement from '../is/isCustomElement';
2
- import getElementsByTagName from './getElementsByTagName';
1
+ import isCustomElement from "../is/isCustomElement";
2
+ import getElementsByTagName from "./getElementsByTagName";
3
3
 
4
4
  /**
5
5
  * Returns an `Array` of `Node` elements that are registered as
@@ -11,7 +11,7 @@ import getElementsByTagName from './getElementsByTagName';
11
11
  * @returns the query result
12
12
  */
13
13
  const getCustomElements = (parent?: ParentNode) => {
14
- const collection = getElementsByTagName('*', parent);
14
+ const collection = getElementsByTagName("*", parent);
15
15
 
16
16
  return [...collection].filter(isCustomElement);
17
17
  };
@@ -1,4 +1,4 @@
1
- import getDocument from '../get/getDocument';
1
+ import getDocument from "../get/getDocument";
2
2
 
3
3
  /**
4
4
  * Returns an `HTMLElement` that matches the id in the document.
@@ -1,5 +1,5 @@
1
- import getDocument from '../get/getDocument';
2
- import isNode from '../is/isNode';
1
+ import getDocument from "../get/getDocument";
2
+ import isNode from "../is/isNode";
3
3
 
4
4
  /**
5
5
  * Shortcut for `HTMLElement.getElementsByClassName` method. Some `Node` elements
@@ -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 = <T extends HTMLElement>(selector: string, parent?: ParentNode) => {
12
+ const getElementsByClassName = <T extends HTMLElement>(
13
+ selector: string,
14
+ parent?: ParentNode,
15
+ ) => {
13
16
  const lookUp = parent && isNode(parent) ? parent : getDocument();
14
- return (lookUp as HTMLElement | Document).getElementsByClassName(selector) as HTMLCollectionOf<T>;
17
+ return (lookUp as HTMLElement | Document).getElementsByClassName(
18
+ selector,
19
+ ) as HTMLCollectionOf<T>;
15
20
  };
16
21
 
17
22
  export default getElementsByClassName;
@@ -1,5 +1,5 @@
1
- import getDocument from '../get/getDocument';
2
- import isNode from '../is/isNode';
1
+ import getDocument from "../get/getDocument";
2
+ import isNode from "../is/isNode";
3
3
 
4
4
  /**
5
5
  * Shortcut for `HTMLElement.getElementsByTagName` method. Some `Node` elements
@@ -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 getElementsByTagName = <T extends HTMLElement>(selector: string, parent?: ParentNode) => {
12
+ const getElementsByTagName = <T extends HTMLElement>(
13
+ selector: string,
14
+ parent?: ParentNode,
15
+ ) => {
13
16
  const lookUp = isNode(parent) ? parent : getDocument();
14
- return (lookUp as Document).getElementsByTagName(selector) as HTMLCollectionOf<T>;
17
+ return (lookUp as Document).getElementsByTagName(
18
+ selector,
19
+ ) as HTMLCollectionOf<T>;
15
20
  };
16
21
 
17
22
  export default getElementsByTagName;
@@ -5,6 +5,7 @@
5
5
  * @param selector the selector to match
6
6
  * @returns the query result
7
7
  */
8
- const matches = (target: Element, selector: string): boolean => target.matches(selector);
8
+ const matches = (target: Element, selector: string): boolean =>
9
+ target.matches(selector);
9
10
 
10
11
  export default matches;
@@ -1,6 +1,6 @@
1
- import getDocument from '../get/getDocument';
2
- import isNode from '../is/isNode';
3
- import isHTMLElement from '../is/isHTMLElement';
1
+ import getDocument from "../get/getDocument";
2
+ import isNode from "../is/isNode";
3
+ import isHTMLElement from "../is/isHTMLElement";
4
4
 
5
5
  /**
6
6
  * Utility to check if target is typeof `HTMLElement`, `Element`, `Node`
@@ -1,5 +1,5 @@
1
- import getDocument from '../get/getDocument';
2
- import isNode from '../is/isNode';
1
+ import getDocument from "../get/getDocument";
2
+ import isNode from "../is/isNode";
3
3
 
4
4
  /**
5
5
  * A shortcut for `(document|Element).querySelectorAll`.
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for `DOMContentLoaded` event.
3
3
  */
4
- const DOMContentLoadedEvent = 'DOMContentLoaded';
4
+ const DOMContentLoadedEvent = "DOMContentLoaded";
5
5
  export default DOMContentLoadedEvent;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for `DOMMouseScroll` event.
3
3
  */
4
- const DOMMouseScrollEvent = 'DOMMouseScroll';
4
+ const DOMMouseScrollEvent = "DOMMouseScroll";
5
5
  export default DOMMouseScrollEvent;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for `abort` event.
3
3
  */
4
- const abortEvent = 'abort';
4
+ const abortEvent = "abort";
5
5
  export default abortEvent;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for 'addEventListener' string.
3
3
  */
4
- const addEventListener = 'addEventListener';
4
+ const addEventListener = "addEventListener";
5
5
  export default addEventListener;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for 'animationDelay' string.
3
3
  */
4
- const animationDelay = 'animationDelay';
4
+ const animationDelay = "animationDelay";
5
5
  export default animationDelay;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for 'animationDuration' string.
3
3
  */
4
- const animationDuration = 'animationDuration';
4
+ const animationDuration = "animationDuration";
5
5
  export default animationDuration;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for 'animationend' string.
3
3
  */
4
- const animationEndEvent = 'animationend';
4
+ const animationEndEvent = "animationend";
5
5
  export default animationEndEvent;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for 'animationName' string.
3
3
  */
4
- const animationName = 'animationName';
4
+ const animationName = "animationName";
5
5
  export default animationName;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-checked.
3
3
  */
4
- const ariaChecked = 'aria-checked';
4
+ const ariaChecked = "aria-checked";
5
5
  export default ariaChecked;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-describedby.
3
3
  */
4
- const ariaDescribedBy = 'aria-describedby';
4
+ const ariaDescribedBy = "aria-describedby";
5
5
  export default ariaDescribedBy;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-description.
3
3
  */
4
- const ariaDescription = 'aria-description';
4
+ const ariaDescription = "aria-description";
5
5
  export default ariaDescription;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-expanded.
3
3
  */
4
- const ariaExpanded = 'aria-expanded';
4
+ const ariaExpanded = "aria-expanded";
5
5
  export default ariaExpanded;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-haspopup.
3
3
  */
4
- const ariaHasPopup = 'aria-haspopup';
4
+ const ariaHasPopup = "aria-haspopup";
5
5
  export default ariaHasPopup;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-hidden.
3
3
  */
4
- const ariaHidden = 'aria-hidden';
4
+ const ariaHidden = "aria-hidden";
5
5
  export default ariaHidden;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-label.
3
3
  */
4
- const ariaLabel = 'aria-label';
4
+ const ariaLabel = "aria-label";
5
5
  export default ariaLabel;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * A global namespace for aria-labelledby.
3
3
  */
4
- const ariaLabelledBy = 'aria-labelledby';
4
+ const ariaLabelledBy = "aria-labelledby";
5
5
  export default ariaLabelledBy;