@thednp/shorty 2.0.0-alpha4 → 2.0.0-alpha6

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 (86) hide show
  1. package/README.md +8 -3
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +59 -53
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +305 -306
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +12 -6
  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 +7 -2
  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 +4 -1
  34. package/src/get/getElementTransitionDuration.ts +4 -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 +12 -2
  40. package/src/interface/customElement.ts +1 -1
  41. package/src/interface/originalEvent.ts +2 -1
  42. package/src/is/isArray.ts +1 -1
  43. package/src/is/isCanvas.ts +4 -2
  44. package/src/is/isCustomElement.ts +3 -2
  45. package/src/is/isDocument.ts +4 -1
  46. package/src/is/isElement.ts +5 -2
  47. package/src/is/isElementsArray.ts +2 -1
  48. package/src/is/isFunction.ts +2 -1
  49. package/src/is/isHTMLCollection.ts +4 -2
  50. package/src/is/isHTMLElement.ts +5 -1
  51. package/src/is/isHTMLImageElement.ts +5 -2
  52. package/src/is/isJSON.ts +1 -1
  53. package/src/is/isMap.ts +4 -1
  54. package/src/is/isMedia.ts +8 -4
  55. package/src/is/isNode.ts +9 -3
  56. package/src/is/isNodeList.ts +4 -1
  57. package/src/is/isNumber.ts +1 -1
  58. package/src/is/isObject.ts +2 -1
  59. package/src/is/isRTL.ts +1 -0
  60. package/src/is/isSVGElement.ts +4 -2
  61. package/src/is/isScaledElement.ts +5 -2
  62. package/src/is/isShadowRoot.ts +4 -2
  63. package/src/is/isString.ts +1 -1
  64. package/src/is/isTableElement.ts +4 -2
  65. package/src/is/isWeakMap.ts +4 -1
  66. package/src/is/isWindow.ts +4 -1
  67. package/src/misc/Float32ArrayFrom.ts +1 -0
  68. package/src/misc/Float64ArrayFrom.ts +1 -0
  69. package/src/misc/ObjectAssign.ts +35 -3
  70. package/src/misc/ObjectEntries.ts +3 -1
  71. package/src/misc/ObjectKeys.ts +2 -1
  72. package/src/misc/ObjectValues.ts +3 -1
  73. package/src/misc/{OriginalEvent.ts → createCustomEvent.ts} +9 -5
  74. package/src/misc/createElement.ts +7 -6
  75. package/src/misc/createElementNS.ts +9 -5
  76. package/src/misc/data.ts +22 -15
  77. package/src/misc/distinct.ts +1 -0
  78. package/src/misc/hasOwn.ts +17 -0
  79. package/src/misc/normalizeValue.ts +9 -7
  80. package/src/misc/setElementStyle.ts +3 -2
  81. package/src/misc/timer.ts +16 -13
  82. package/src/selectors/getCustomElements.ts +1 -0
  83. package/src/selectors/getElementsByClassName.ts +7 -2
  84. package/src/selectors/getElementsByTagName.ts +4 -1
  85. package/src/selectors/querySelector.ts +5 -4
  86. package/src/strings/mouseHoverEvents.ts +3 -1
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@thednp/shorty",
3
- "version": "2.0.0alpha4",
3
+ "version": "2.0.0alpha6",
4
4
  "description": "TypeScript shorties for the web",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/shorty.js",
7
7
  "types": "./dist/shorty.d.ts",
8
8
  "module": "./dist/shorty.mjs",
9
- "exports": {
9
+ "*exports": {
10
10
  ".": {
11
11
  "import": "./dist/shorty.mjs",
12
12
  "require": "./dist/shorty.cjs",
@@ -25,7 +25,8 @@
25
25
  "cypress": "npm run pre-test && npx cypress open",
26
26
  "coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
27
27
  "format": "prettier --write \"src/**/*.ts\"",
28
- "lint:ts": "tslint -p tsconfig.json",
28
+ "lint:ts": "eslint -c .eslintrc.js --ext .ts src",
29
+ "fix:ts": "eslint -c .eslintrc.js --ext .ts src --fix",
29
30
  "build": "npm run clean && tsc && vite build && dts-bundle-generator --config ./dts.config.ts"
30
31
  },
31
32
  "publishConfig": {
@@ -52,17 +53,22 @@
52
53
  "@cypress/code-coverage": "^3.10.0",
53
54
  "@testing-library/cypress": "^8.0.3",
54
55
  "@types/istanbul-lib-instrument": "^1.7.4",
55
- "cypress": "^10.6.0",
56
+ "@typescript-eslint/eslint-plugin": "^5.35.1",
57
+ "@typescript-eslint/parser": "^5.35.1",
58
+ "cypress": "^11.2.0",
56
59
  "dts-bundle-generator": "^6.12.0",
57
60
  "esbuild": "^0.14.30",
61
+ "eslint": "^8.23.0",
62
+ "eslint-plugin-jsdoc": "^39.3.6",
63
+ "eslint-plugin-prefer-arrow": "^1.2.3",
64
+ "eslint-plugin-prettier": "^4.2.1",
58
65
  "istanbul-lib-coverage": "^3.2.0",
59
66
  "istanbul-lib-instrument": "^5.2.0",
67
+ "ncp": "^2.0.0",
60
68
  "npm-run-all": "^4.1.5",
61
69
  "nyc": "^15.1.0",
62
70
  "prettier": "^2.7.1",
63
71
  "rimraf": "^3.0.2",
64
- "tslint": "^6.1.3",
65
- "tslint-config-prettier": "^1.18.0",
66
72
  "typescript": "^4.7.4",
67
73
  "vite": "^3.0.9"
68
74
  }
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.getAttribute()` method.
3
+ *
3
4
  * @param element target element
4
5
  * @param att attribute name
5
6
  * @returns attribute value
6
7
  */
7
- const getAttribute = (element: HTMLElement, att: string): string | null => element.getAttribute(att);
8
+ const getAttribute = (element: HTMLElement, att: string): string | null =>
9
+ element.getAttribute(att);
8
10
 
9
11
  export default getAttribute;
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.getAttributeNS()` method.
3
+ *
3
4
  * @param ns attribute namespace
4
5
  * @param element target element
5
6
  * @param att attribute name
6
7
  * @returns attribute value
7
8
  */
8
- const getAttributeNS = (ns: string, element: HTMLElement, att: string) => element.getAttributeNS(ns, att);
9
+ const getAttributeNS = (ns: string, element: HTMLElement, att: string) =>
10
+ element.getAttributeNS(ns, att);
9
11
 
10
12
  export default getAttributeNS;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.hasAttribute()` method.
3
+ *
3
4
  * @param element target element
4
5
  * @param att attribute name
5
6
  * @returns the query result
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.hasAttributeNS()` method.
3
+ *
3
4
  * @param ns attribute namespace
4
5
  * @param element target element
5
6
  * @param att attribute name
6
7
  * @returns the query result
7
8
  */
8
- const hasAttributeNS = (ns: string, element: HTMLElement, att: string): boolean => element.hasAttributeNS(ns, att);
9
+ const hasAttributeNS = (ns: string, element: HTMLElement, att: string): boolean =>
10
+ element.hasAttributeNS(ns, att);
9
11
 
10
12
  export default hasAttributeNS;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.removeAttribute()` method.
3
+ *
3
4
  * @param element target element
4
5
  * @param att attribute name
5
6
  */
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.removeAttributeNS()` method.
3
+ *
3
4
  * @param ns attribute namespace
4
5
  * @param element target element
5
6
  * @param att attribute name
6
7
  */
7
- const removeAttributeNS = (ns: string, element: HTMLElement, att: string): void => element.removeAttributeNS(ns, att);
8
+ const removeAttributeNS = (ns: string, element: HTMLElement, att: string): void =>
9
+ element.removeAttributeNS(ns, att);
8
10
 
9
11
  export default removeAttributeNS;
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Shortcut for `HTMLElement.setAttribute()` method.
3
+ *
3
4
  * @param element target element
4
5
  * @param att attribute name
5
6
  * @param value attribute value
6
7
  */
7
- const setAttribute = (element: HTMLElement, att: string, value: string) => element.setAttribute(att, value);
8
+ const setAttribute = (element: HTMLElement, att: string, value: string) =>
9
+ element.setAttribute(att, value);
8
10
 
9
11
  export default setAttribute;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Shortcut for `SVGElement.setAttributeNS()` method.
3
+ *
3
4
  * @param ns attribute namespace
4
5
  * @param element target element
5
6
  * @param att attribute name
@@ -6,7 +6,7 @@ let isMobileCheck = false;
6
6
 
7
7
  /* istanbul ignore else */
8
8
  if (userAgentData) {
9
- isMobileCheck = userAgentData.brands.some((x) => mobileBrands.test(x.brand));
9
+ isMobileCheck = userAgentData.brands.some(x => mobileBrands.test(x.brand));
10
10
  } else {
11
11
  isMobileCheck = mobileBrands.test(userAgent);
12
12
  }
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
3
3
  /**
4
4
  * A global `boolean` for CSS3 3D transform support.
5
5
  */
6
- const support3DTransform = ['webkitPerspective', 'perspective'].some((p) => p in documentHead.style);
6
+ const support3DTransform = ['webkitPerspective', 'perspective'].some(p => p in documentHead.style);
7
7
 
8
8
  export default support3DTransform;
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
3
3
  /**
4
4
  * A global `boolean` for CSS3 animation support.
5
5
  */
6
- const supportAnimation = ['webkitAnimation', 'animation'].some((p) => p in documentHead.style);
6
+ const supportAnimation = ['webkitAnimation', 'animation'].some(p => p in documentHead.style);
7
7
 
8
8
  export default supportAnimation;
@@ -12,7 +12,7 @@ const supportPassive = (() => {
12
12
  let result = false;
13
13
  try {
14
14
  const opts = Object.defineProperty({}, 'passive', {
15
- get() {
15
+ get: () => {
16
16
  result = true;
17
17
  return result;
18
18
  },
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * A global `boolean` for touch events support.
3
3
  */
4
- const supportTouch = 'ontouchstart' in window || /* istanbul ignore next */ 'msMaxTouchPoints' in navigator;
4
+ const supportTouch =
5
+ 'ontouchstart' in window || /* istanbul ignore next */ 'msMaxTouchPoints' in navigator;
5
6
 
6
7
  export default supportTouch;
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
3
3
  /**
4
4
  * A global `boolean` for CSS3 transform support.
5
5
  */
6
- const supportTransform = ['webkitTransform', 'transform'].some((p) => p in documentHead.style);
6
+ const supportTransform = ['webkitTransform', 'transform'].some(p => p in documentHead.style);
7
7
 
8
8
  export default supportTransform;
@@ -3,6 +3,6 @@ import documentHead from '../blocks/documentHead';
3
3
  /**
4
4
  * A global `boolean` for CSS3 transition support.
5
5
  */
6
- const supportTransition = ['webkitTransition', 'transition'].some((p) => p in documentHead.style);
6
+ const supportTransition = ['webkitTransition', 'transition'].some(p => p in documentHead.style);
7
7
 
8
8
  export default supportTransition;
package/src/event/off.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Remove eventListener from an `EventTarget` object.
3
3
  */
4
- export default function off(
4
+ const off = (
5
5
  element: EventTarget,
6
6
  eventName: string,
7
7
  listener: EventListener,
8
8
  options?: AddEventListenerOptions,
9
- ) {
9
+ ) => {
10
10
  const ops = options || false;
11
11
  element.removeEventListener(eventName, listener, ops);
12
- }
12
+ };
13
+
14
+ export default off;
package/src/event/on.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Add eventListener to an `EventTarget` object.
3
3
  */
4
- export default function on(
4
+ const on = (
5
5
  element: EventTarget,
6
6
  eventName: string,
7
7
  listener: EventListener,
8
8
  options?: AddEventListenerOptions,
9
- ) {
9
+ ) => {
10
10
  const ops = options || false;
11
11
  element.addEventListener(eventName, listener, ops);
12
- }
12
+ };
13
+
14
+ export default on;
package/src/event/one.ts CHANGED
@@ -5,11 +5,16 @@ import off from './off';
5
5
  * Add an `eventListener` to an `EventTarget`
6
6
  * element and remove it once callback is called.
7
7
  */
8
- const one = (element: EventTarget, eventName: string, listener: EventListener, options?: AddEventListenerOptions) => {
8
+ const one = (
9
+ element: EventTarget,
10
+ eventName: string,
11
+ listener: EventListener,
12
+ options?: AddEventListenerOptions,
13
+ ) => {
9
14
  /** Wrap the listener for easy on -> off */
10
15
  const handlerWrapper = (e: Event): void => {
11
16
  /* istanbul ignore else */
12
- if (e.target === element) {
17
+ if (e.target === element || e.currentTarget === element) {
13
18
  listener.apply(element, [e]);
14
19
  off(element, eventName, handlerWrapper, options);
15
20
  }
@@ -3,13 +3,17 @@ import { BoundingClientRect } from '../interface/boundingClientRect';
3
3
 
4
4
  /**
5
5
  * Returns the bounding client rect of a target `HTMLElement`.
6
+ *
6
7
  * @see https://github.com/floating-ui/floating-ui
7
8
  *
8
9
  * @param element event.target
9
10
  * @param includeScale when *true*, the target scale is also computed
10
11
  * @returns the bounding client rect object
11
12
  */
12
- const getBoundingClientRect = (element: HTMLElement, includeScale?: boolean): BoundingClientRect => {
13
+ const getBoundingClientRect = (
14
+ element: HTMLElement,
15
+ includeScale?: boolean,
16
+ ): BoundingClientRect => {
13
17
  const { width, height, top, right, bottom, left } = element.getBoundingClientRect();
14
18
  let scaleX = 1;
15
19
  let scaleY = 1;
@@ -4,18 +4,19 @@ import isDocument from '../is/isDocument';
4
4
 
5
5
  /**
6
6
  * Returns the `document` or the `#document` element.
7
+ *
7
8
  * @see https://github.com/floating-ui/floating-ui
8
9
  *
9
10
  * @param node the reference node
10
11
  * @returns the parent document of the given node
11
12
  */
12
- const getDocument = (node?: any): Document => {
13
+ const getDocument = (node?: Node | Document | Window): Document => {
14
+ // node instanceof Window
15
+ if (isWindow(node)) return node.document;
13
16
  // node instanceof Document
14
17
  if (isDocument(node)) return node;
15
18
  // node instanceof Node
16
19
  if (isNode(node)) return node.ownerDocument as Document;
17
- // node instanceof Window
18
- if (isWindow(node)) return node.document;
19
20
  // node is undefined | NULL
20
21
  return window.document;
21
22
  };
@@ -6,7 +6,7 @@ import getDocument from './getDocument';
6
6
  * @param node the reference node
7
7
  * @returns the parent `<body>` of the specified node
8
8
  */
9
- const getDocumentBody = (node?: any): HTMLElement => {
9
+ const getDocumentBody = (node?: Node): HTMLElement => {
10
10
  return getDocument(node).body;
11
11
  };
12
12
 
@@ -13,7 +13,8 @@ const getElementAnimationDelay = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, animationName);
14
14
  const durationValue = getElementStyle(element, animationDelay);
15
15
  const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
17
18
 
18
19
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
19
20
  };
@@ -13,7 +13,8 @@ const getElementAnimationDuration = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, animationName);
14
14
  const durationValue = getElementStyle(element, animationDuration);
15
15
  const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
17
18
 
18
19
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
19
20
  };
@@ -13,7 +13,10 @@ const getElementTransitionDelay = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, transitionProperty);
14
14
  const delayValue = getElementStyle(element, transitionDelay);
15
15
  const delayScale = delayValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none' ? parseFloat(delayValue) * delayScale : 0;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(delayValue) * delayScale
19
+ : /* istanbul ignore next */ 0;
17
20
 
18
21
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
19
22
  };
@@ -13,7 +13,10 @@ const getElementTransitionDuration = (element: HTMLElement): number => {
13
13
  const propertyValue = getElementStyle(element, transitionProperty);
14
14
  const durationValue = getElementStyle(element, transitionDuration);
15
15
  const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
- const duration = propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
16
+ const duration =
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale
19
+ : /* istanbul ignore next */ 0;
17
20
 
18
21
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
19
22
  };
@@ -5,12 +5,13 @@ import isNode from '../is/isNode';
5
5
 
6
6
  /**
7
7
  * Returns the `parentNode` also going through `ShadowRoot`.
8
+ *
8
9
  * @see https://github.com/floating-ui/floating-ui
9
10
  *
10
11
  * @param {Node} node the target node
11
12
  * @returns {Node} the apropriate parent node
12
13
  */
13
- const getParentNode = (node: Node): Node => {
14
+ const getParentNode = (node: Node): Node | ParentNode => {
14
15
  if (node.nodeName === 'HTML') {
15
16
  return node;
16
17
  }
@@ -5,6 +5,7 @@ import getBoundingClientRect from './getBoundingClientRect';
5
5
 
6
6
  /**
7
7
  * Returns the rect relative to a given offset parent and its scroll position.
8
+ *
8
9
  * @see https://github.com/floating-ui/floating-ui
9
10
  *
10
11
  * @param element target
package/src/get/getUID.ts CHANGED
@@ -24,8 +24,8 @@ const getUID = (element: HTMLElement, key?: string): number => {
24
24
  if (!elementIDMap.has(elID)) {
25
25
  elementIDMap.set(elID, elMap);
26
26
  }
27
- if (isMap(elMap) && !elMap.has(key)) {
28
- elMap.set(key, result);
27
+ if (isMap(elMap as KeyIdMap) && !(elMap as KeyIdMap).has(key)) {
28
+ (elMap as KeyIdMap).set(key, result);
29
29
  elementUID += 1;
30
30
  } else result = (elMap as KeyIdMap).get(key) as number;
31
31
  } else {
@@ -3,6 +3,7 @@ import isNode from '../is/isNode';
3
3
 
4
4
  /**
5
5
  * Returns the `Window` object of a target node.
6
+ *
6
7
  * @see https://github.com/floating-ui/floating-ui
7
8
  *
8
9
  * @param node target node
package/src/index.ts CHANGED
@@ -153,6 +153,11 @@ import on from './event/on';
153
153
  import off from './event/off';
154
154
  import one from './event/one';
155
155
 
156
+ // blocks
157
+ import documentBody from './blocks/documentBody';
158
+ import documentElement from './blocks/documentElement';
159
+ import documentHead from './blocks/documentHead';
160
+
156
161
  // misc
157
162
  import ArrayFrom from './misc/ArrayFrom';
158
163
  import Data, { getInstance } from './misc/data';
@@ -166,13 +171,14 @@ import Float32ArrayFrom from './misc/Float32ArrayFrom';
166
171
  import Float64ArrayFrom from './misc/Float64ArrayFrom';
167
172
  import focus from './misc/focus';
168
173
  import noop from './misc/noop';
174
+ import hasOwn from './misc/hasOwn';
169
175
  import normalizeOptions from './misc/normalizeOptions';
170
176
  import normalizeValue from './misc/normalizeValue';
171
177
  import ObjectAssign from './misc/ObjectAssign';
172
178
  import ObjectEntries from './misc/ObjectEntries';
173
179
  import ObjectKeys from './misc/ObjectKeys';
174
180
  import ObjectValues from './misc/ObjectValues';
175
- import OriginalEvent from './misc/OriginalEvent';
181
+ import createCustomEvent from './misc/createCustomEvent';
176
182
  import passiveHandler from './misc/passiveHandler';
177
183
  import reflow from './misc/reflow';
178
184
  import setElementStyle from './misc/setElementStyle';
@@ -361,12 +367,16 @@ const SHORTY = {
361
367
  on,
362
368
  off,
363
369
  one,
370
+ documentBody,
371
+ documentElement,
372
+ documentHead,
364
373
  dispatchEvent,
365
374
  distinct,
366
375
  Data,
367
376
  getInstance,
368
377
  createElement,
369
378
  createElementNS,
379
+ createCustomEvent,
370
380
  toUpperCase,
371
381
  toLowerCase,
372
382
  Timer,
@@ -416,6 +426,7 @@ const SHORTY = {
416
426
  getElementsByClassName,
417
427
  getElementsByTagName,
418
428
  matches,
429
+ hasOwn,
419
430
  normalizeValue,
420
431
  normalizeOptions,
421
432
  reflow,
@@ -429,7 +440,6 @@ const SHORTY = {
429
440
  ObjectEntries,
430
441
  ObjectKeys,
431
442
  ObjectValues,
432
- OriginalEvent,
433
443
  getBoundingClientRect,
434
444
  getDocument,
435
445
  getDocumentBody,
@@ -4,5 +4,5 @@ export interface CustomElement extends HTMLElement {
4
4
  disconnectedCallback?: () => void;
5
5
  adoptedCallback?: () => void;
6
6
  attributeChangedCallback?: () => void;
7
- [key: string]: any;
7
+ // [key: PropertyKey]: any;
8
8
  }
@@ -1,3 +1,4 @@
1
- export interface OriginalEvent<T> extends CustomEvent<T> {
1
+ export interface OriginalEvent extends CustomEvent<any> {
2
+ readonly type: string;
2
3
  relatedTarget?: EventTarget;
3
4
  }
package/src/is/isArray.ts CHANGED
@@ -4,6 +4,6 @@
4
4
  * @param obj array-like iterable object
5
5
  * @returns the query result
6
6
  */
7
- const isArray = (obj?: any): obj is any[] => Array.isArray(obj) || false;
7
+ const isArray = (obj?: unknown): obj is any[] => Array.isArray(obj) || false;
8
8
 
9
9
  export default isArray;
@@ -1,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an element is an `HTMLCanvasElement` or `<canvas>`.
3
5
  *
@@ -5,7 +7,7 @@
5
7
  * @returns the query result
6
8
  */
7
9
 
8
- const isCanvas = (element?: any): element is HTMLCanvasElement =>
9
- (element && element.constructor.name === 'HTMLCanvasElement') || false;
10
+ const isCanvas = (element?: unknown): element is HTMLCanvasElement =>
11
+ (isNode(element) && element.nodeName === 'CANVAS') || false;
10
12
 
11
13
  export default isCanvas;
@@ -1,3 +1,4 @@
1
+ import isHTMLElement from './isHTMLElement';
1
2
  import { CustomElement } from '../interface/customElement';
2
3
 
3
4
  /**
@@ -6,7 +7,7 @@ import { CustomElement } from '../interface/customElement';
6
7
  * @param element the target object
7
8
  * @returns the query result
8
9
  */
9
- const isCustomElement = <T extends CustomElement>(element?: any): element is T =>
10
- (element && !!element.shadowRoot) || false;
10
+ const isCustomElement = <T extends CustomElement>(element?: unknown): element is T =>
11
+ (isHTMLElement(element) && !!(element as T).shadowRoot) || false;
11
12
 
12
13
  export default isCustomElement;
@@ -1,10 +1,13 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an object is a `Document`.
5
+ *
3
6
  * @see https://dom.spec.whatwg.org/#node
4
7
  *
5
8
  * @param obj the target object
6
9
  * @returns the query result
7
10
  */
8
- const isDocument = (obj?: any): obj is Document => (obj && obj.nodeType === 9) || false;
11
+ const isDocument = (obj?: unknown): obj is Document => (isNode(obj) && obj.nodeType === 9) || false;
9
12
 
10
13
  export default isDocument;
@@ -1,5 +1,8 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an object is an `Element`.
5
+ *
3
6
  * @see https://dom.spec.whatwg.org/#node
4
7
  *
5
8
  * ```
@@ -18,7 +21,7 @@
18
21
  * @param element the target object
19
22
  * @returns the query result
20
23
  */
21
- const isElement = (element?: any): element is Element =>
22
- (element && [1, 2, 3, 4, 5, 6, 7, 8].some((x) => element.nodeType === x)) || false;
24
+ const isElement = (element?: unknown): element is Element =>
25
+ (isNode(element) && [1, 2, 3, 4, 5, 6, 7, 8].some(x => element.nodeType === x)) || false;
23
26
 
24
27
  export default isElement;
@@ -7,6 +7,7 @@ import isArray from './isArray';
7
7
  * @param obj the target object
8
8
  * @returns the query result
9
9
  */
10
- const isElementsArray = (obj?: any): obj is HTMLElement[] => (isArray(obj) && obj.every(isHTMLElement)) || false;
10
+ const isElementsArray = (obj?: unknown): obj is HTMLElement[] =>
11
+ (isArray(obj) && obj.every(isHTMLElement)) || false;
11
12
 
12
13
  export default isElementsArray;
@@ -4,6 +4,7 @@
4
4
  * @param fn the target object
5
5
  * @returns the query result
6
6
  */
7
- const isFunction = (fn?: any): fn is (() => any) => (fn && fn.constructor.name === 'Function') || false;
7
+ const isFunction = (fn?: unknown): fn is (...arg0: any[]) => any =>
8
+ typeof fn === 'function' || false;
8
9
 
9
10
  export default isFunction;
@@ -1,10 +1,12 @@
1
+ import isObject from './isObject';
2
+
1
3
  /**
2
4
  * Checks if an object is an `HTMLCollection`.
3
5
  *
4
6
  * @param obj the target object
5
7
  * @returns the query result
6
8
  */
7
- const isHTMLCollection = (obj?: any): obj is HTMLCollection =>
8
- (obj && obj.constructor.name === 'HTMLCollection') || false;
9
+ const isHTMLCollection = (obj?: unknown): obj is HTMLCollection =>
10
+ (isObject(obj) && obj.constructor.name === 'HTMLCollection') || false;
9
11
 
10
12
  export default isHTMLCollection;
@@ -1,9 +1,13 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an element is an `HTMLElement`.
5
+ *
3
6
  * @see https://dom.spec.whatwg.org/#node
4
7
  *
5
8
  * @param element the target object
6
9
  * @returns the query result
7
10
  */
8
- const isHTMLElement = (element?: any): element is HTMLElement => (element && element.nodeType === 1) || false;
11
+ const isHTMLElement = (element?: unknown): element is HTMLElement =>
12
+ (isNode(element) && element.nodeType === 1) || false;
9
13
  export default isHTMLElement;
@@ -1,9 +1,12 @@
1
+ import isHTMLElement from './isHTMLElement';
2
+
1
3
  /**
2
4
  * Check if a target element is an `<img>`.
5
+ *
3
6
  * @param element the target element
4
7
  * @returns the query result
5
8
  */
6
- const isHTMLImageElement = (element?: any): element is HTMLImageElement =>
7
- (element && element.tagName === 'IMG') || false;
9
+ const isHTMLImageElement = (element?: unknown): element is HTMLImageElement =>
10
+ (isHTMLElement(element) && element.tagName === 'IMG') || false;
8
11
 
9
12
  export default isHTMLImageElement;