@thednp/shorty 2.0.0-alpha5 → 2.0.0-alpha7

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 (56) hide show
  1. package/README.md +7 -5
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +1454 -377
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +364 -365
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +10 -9
  10. package/src/boolean/isApple.ts +1 -1
  11. package/src/event/one.ts +1 -1
  12. package/src/get/getBoundingClientRect.ts +1 -1
  13. package/src/get/getElementTransitionDelay.ts +3 -1
  14. package/src/get/getElementTransitionDuration.ts +3 -1
  15. package/src/get/getRectRelativeToOffsetParent.ts +1 -1
  16. package/src/index.ts +5 -4
  17. package/src/interface/{boundingClientRect.ts → boundingClientRect.d.ts} +1 -1
  18. package/src/interface/css4Declaration.d.ts +4 -0
  19. package/src/interface/{customElement.ts → customElement.d.ts} +2 -2
  20. package/src/interface/{navigatorUA.ts → navigatorUA.d.ts} +3 -3
  21. package/src/interface/{offsetRect.ts → offsetRect.d.ts} +1 -1
  22. package/src/interface/originalEvent.d.ts +4 -0
  23. package/src/is/isArray.ts +1 -1
  24. package/src/is/isCanvas.ts +4 -2
  25. package/src/is/isCustomElement.ts +4 -3
  26. package/src/is/isDocument.ts +3 -1
  27. package/src/is/isElement.ts +4 -2
  28. package/src/is/isElementsArray.ts +1 -1
  29. package/src/is/isFunction.ts +1 -1
  30. package/src/is/isHTMLCollection.ts +4 -2
  31. package/src/is/isHTMLElement.ts +4 -2
  32. package/src/is/isHTMLImageElement.ts +4 -2
  33. package/src/is/isMap.ts +4 -2
  34. package/src/is/isMedia.ts +4 -3
  35. package/src/is/isNode.ts +9 -3
  36. package/src/is/isNodeList.ts +4 -2
  37. package/src/is/isNumber.ts +1 -1
  38. package/src/is/isObject.ts +2 -1
  39. package/src/is/isSVGElement.ts +4 -2
  40. package/src/is/isShadowRoot.ts +4 -2
  41. package/src/is/isString.ts +1 -1
  42. package/src/is/isTableElement.ts +4 -4
  43. package/src/is/isWeakMap.ts +4 -2
  44. package/src/is/isWindow.ts +4 -2
  45. package/src/misc/ObjectHasOwn.ts +17 -0
  46. package/src/misc/createCustomEvent.ts +1 -1
  47. package/src/misc/createElement.ts +1 -3
  48. package/src/misc/createElementNS.ts +1 -1
  49. package/src/misc/data.ts +12 -26
  50. package/src/misc/getInstance.ts +9 -0
  51. package/src/misc/setElementStyle.ts +1 -1
  52. package/src/selectors/getCustomElements.ts +1 -1
  53. package/src/selectors/querySelector.ts +6 -5
  54. package/src/strings/userAgentData.ts +1 -1
  55. package/src/interface/css4Declaration.ts +0 -3
  56. package/src/interface/originalEvent.ts +0 -4
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@thednp/shorty",
3
- "version": "2.0.0alpha5",
3
+ "version": "2.0.0alpha7",
4
+ "type": "module",
4
5
  "description": "TypeScript shorties for the web",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./dist/shorty.js",
@@ -20,14 +21,14 @@
20
21
  "scripts": {
21
22
  "pre-test": "npm run clean-coverage",
22
23
  "test": "npm run pre-test && npx cypress run",
23
- "clean": "rimraf dist",
24
24
  "clean-coverage": "rimraf coverage .nyc_output",
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": "eslint -c .eslintrc.js --ext .ts src",
29
- "fix:ts": "eslint -c .eslintrc.js --ext .ts src --fix",
30
- "build": "npm run clean && tsc && vite build && dts-bundle-generator --config ./dts.config.ts"
28
+ "lint:ts": "eslint -c .eslintrc.cjs --ext .ts src",
29
+ "fix:ts": "eslint -c .eslintrc.cjs --ext .ts src --fix",
30
+ "build": "npm run lint:ts && vite build && npm run dts",
31
+ "dts": "dts-bundle-generator --config ./dts.config.ts"
31
32
  },
32
33
  "publishConfig": {
33
34
  "access": "public",
@@ -51,12 +52,12 @@
51
52
  "devDependencies": {
52
53
  "@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
53
54
  "@cypress/code-coverage": "^3.10.0",
54
- "@testing-library/cypress": "^8.0.3",
55
+ "@rollup/plugin-json": "^5.0.2",
55
56
  "@types/istanbul-lib-instrument": "^1.7.4",
56
57
  "@typescript-eslint/eslint-plugin": "^5.35.1",
57
58
  "@typescript-eslint/parser": "^5.35.1",
58
- "cypress": "^10.6.0",
59
- "dts-bundle-generator": "^6.12.0",
59
+ "cypress": "^12.0.2",
60
+ "dts-bundle-generator": "^7.1.0",
60
61
  "esbuild": "^0.14.30",
61
62
  "eslint": "^8.23.0",
62
63
  "eslint-plugin-jsdoc": "^39.3.6",
@@ -69,7 +70,7 @@
69
70
  "nyc": "^15.1.0",
70
71
  "prettier": "^2.7.1",
71
72
  "rimraf": "^3.0.2",
72
- "typescript": "^4.7.4",
73
+ "typescript": "^4.9.4",
73
74
  "vite": "^3.0.9"
74
75
  }
75
76
  }
@@ -1,4 +1,4 @@
1
- import { NavigatorUABrand } from '../interface/navigatorUA';
1
+ import type { NavigatorUABrand } from '../interface/navigatorUA';
2
2
  import userAgentData from '../strings/userAgentData';
3
3
  import userAgent from '../strings/userAgent';
4
4
 
package/src/event/one.ts CHANGED
@@ -14,7 +14,7 @@ const one = (
14
14
  /** Wrap the listener for easy on -> off */
15
15
  const handlerWrapper = (e: Event): void => {
16
16
  /* istanbul ignore else */
17
- if (e.target === element) {
17
+ if (e.target === element || e.currentTarget === element) {
18
18
  listener.apply(element, [e]);
19
19
  off(element, eventName, handlerWrapper, options);
20
20
  }
@@ -1,5 +1,5 @@
1
1
  import isHTMLElement from '../is/isHTMLElement';
2
- import { BoundingClientRect } from '../interface/boundingClientRect';
2
+ import type { BoundingClientRect } from '../interface/boundingClientRect';
3
3
 
4
4
  /**
5
5
  * Returns the bounding client rect of a target `HTMLElement`.
@@ -14,7 +14,9 @@ const getElementTransitionDelay = (element: HTMLElement): number => {
14
14
  const delayValue = getElementStyle(element, transitionDelay);
15
15
  const delayScale = delayValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
16
  const duration =
17
- propertyValue && propertyValue !== 'none' ? parseFloat(delayValue) * delayScale : 0;
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(delayValue) * delayScale
19
+ : /* istanbul ignore next */ 0;
18
20
 
19
21
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
20
22
  };
@@ -14,7 +14,9 @@ const getElementTransitionDuration = (element: HTMLElement): number => {
14
14
  const durationValue = getElementStyle(element, transitionDuration);
15
15
  const durationScale = durationValue.includes('ms') ? /* istanbul ignore next */ 1 : 1000;
16
16
  const duration =
17
- propertyValue && propertyValue !== 'none' ? parseFloat(durationValue) * durationScale : 0;
17
+ propertyValue && propertyValue !== 'none'
18
+ ? parseFloat(durationValue) * durationScale
19
+ : /* istanbul ignore next */ 0;
18
20
 
19
21
  return !Number.isNaN(duration) ? duration : /* istanbul ignore next */ 0;
20
22
  };
@@ -1,4 +1,4 @@
1
- import { OffsetRect } from '../interface/offsetRect';
1
+ import type { OffsetRect } from '../interface/offsetRect';
2
2
  import isScaledElement from '../is/isScaledElement';
3
3
  import isHTMLElement from '../is/isHTMLElement';
4
4
  import getBoundingClientRect from './getBoundingClientRect';
package/src/index.ts CHANGED
@@ -160,7 +160,8 @@ import documentHead from './blocks/documentHead';
160
160
 
161
161
  // misc
162
162
  import ArrayFrom from './misc/ArrayFrom';
163
- import Data, { getInstance } from './misc/data';
163
+ import Data from './misc/data';
164
+ import getInstance from './misc/getInstance';
164
165
  import createElement from './misc/createElement';
165
166
  import createElementNS from './misc/createElementNS';
166
167
  import dispatchEvent from './misc/dispatchEvent';
@@ -175,6 +176,7 @@ import normalizeOptions from './misc/normalizeOptions';
175
176
  import normalizeValue from './misc/normalizeValue';
176
177
  import ObjectAssign from './misc/ObjectAssign';
177
178
  import ObjectEntries from './misc/ObjectEntries';
179
+ import ObjectHasOwn from './misc/ObjectHasOwn';
178
180
  import ObjectKeys from './misc/ObjectKeys';
179
181
  import ObjectValues from './misc/ObjectValues';
180
182
  import createCustomEvent from './misc/createCustomEvent';
@@ -241,7 +243,7 @@ import getElementsByTagName from './selectors/getElementsByTagName';
241
243
  import getElementsByClassName from './selectors/getElementsByClassName';
242
244
  import matches from './selectors/matches';
243
245
 
244
- const SHORTY = {
246
+ export {
245
247
  ariaChecked,
246
248
  ariaDescription,
247
249
  ariaDescribedBy,
@@ -434,6 +436,7 @@ const SHORTY = {
434
436
  ArrayFrom,
435
437
  Float32ArrayFrom,
436
438
  Float64ArrayFrom,
439
+ ObjectHasOwn,
437
440
  ObjectAssign,
438
441
  ObjectEntries,
439
442
  ObjectKeys,
@@ -454,5 +457,3 @@ const SHORTY = {
454
457
  removeAttribute,
455
458
  removeAttributeNS,
456
459
  };
457
-
458
- export default SHORTY;
@@ -1,4 +1,4 @@
1
- export interface BoundingClientRect {
1
+ export declare interface BoundingClientRect {
2
2
  width: number;
3
3
  height: number;
4
4
  top: number;
@@ -0,0 +1,4 @@
1
+ export declare interface CSS4Declaration
2
+ extends Exclude<() => string | symbol, CSSStyleDeclaration> {
3
+ [key: string]: string;
4
+ }
@@ -1,8 +1,8 @@
1
- export interface CustomElement extends HTMLElement {
1
+ export declare interface CustomElement extends HTMLElement {
2
2
  shadowRoot: ShadowRoot;
3
3
  connectedCallback?: () => void;
4
4
  disconnectedCallback?: () => void;
5
5
  adoptedCallback?: () => void;
6
6
  attributeChangedCallback?: () => void;
7
- [key: string]: any;
7
+ // [key: PropertyKey]: any;
8
8
  }
@@ -1,15 +1,15 @@
1
1
  // https://github.com/lukewarlow/user-agent-data-types/blob/master/index.d.ts
2
- export interface NavigatorUABrand {
2
+ export declare interface NavigatorUABrand {
3
3
  readonly brand: string;
4
4
  readonly version: string;
5
5
  }
6
6
 
7
- export interface NavigatorUAData {
7
+ export declare interface NavigatorUAData {
8
8
  readonly brands: NavigatorUABrand[];
9
9
  readonly mobile: boolean;
10
10
  readonly platform: string;
11
11
  }
12
12
 
13
- export interface NavigatorUA extends Navigator {
13
+ export declare interface NavigatorUA extends Navigator {
14
14
  readonly userAgentData: NavigatorUAData;
15
15
  }
@@ -1,4 +1,4 @@
1
- export interface OffsetRect {
1
+ export declare interface OffsetRect {
2
2
  width: number;
3
3
  height: number;
4
4
  x: number;
@@ -0,0 +1,4 @@
1
+ export declare interface OriginalEvent extends CustomEvent<any> {
2
+ readonly type: string;
3
+ relatedTarget?: EventTarget;
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?: Node): element is HTMLCanvasElement =>
9
- (element && element.nodeName === 'CANVAS') || false;
10
+ const isCanvas = (element?: unknown): element is HTMLCanvasElement =>
11
+ (isNode(element) && element.nodeName === 'CANVAS') || false;
10
12
 
11
13
  export default isCanvas;
@@ -1,4 +1,5 @@
1
- import { CustomElement } from '../interface/customElement';
1
+ import isHTMLElement from './isHTMLElement';
2
+ import type { CustomElement } from '../interface/customElement';
2
3
 
3
4
  /**
4
5
  * Checks if an object is a `CustomElement`.
@@ -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?: T | Node): element is T =>
10
- (element && !!(element as CustomElement).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,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an object is a `Document`.
3
5
  *
@@ -6,6 +8,6 @@
6
8
  * @param obj the target object
7
9
  * @returns the query result
8
10
  */
9
- const isDocument = (obj?: Node | Document): obj is Document => (obj && obj.nodeType === 9) || false;
11
+ const isDocument = (obj?: unknown): obj is Document => (isNode(obj) && obj.nodeType === 9) || false;
10
12
 
11
13
  export default isDocument;
@@ -1,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an object is an `Element`.
3
5
  *
@@ -19,7 +21,7 @@
19
21
  * @param element the target object
20
22
  * @returns the query result
21
23
  */
22
- const isElement = (element?: Element | Node): element is Element =>
23
- (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;
24
26
 
25
27
  export default isElement;
@@ -7,7 +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[] =>
10
+ const isElementsArray = (obj?: unknown): obj is HTMLElement[] =>
11
11
  (isArray(obj) && obj.every(isHTMLElement)) || false;
12
12
 
13
13
  export default isElementsArray;
@@ -4,7 +4,7 @@
4
4
  * @param fn the target object
5
5
  * @returns the query result
6
6
  */
7
- const isFunction = <T extends (...arg0: any[]) => any>(fn?: T): fn is T =>
7
+ const isFunction = (fn?: unknown): fn is (...arg0: any[]) => any =>
8
8
  typeof fn === 'function' || false;
9
9
 
10
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?: HTMLCollection): 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,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an element is an `HTMLElement`.
3
5
  *
@@ -6,6 +8,6 @@
6
8
  * @param element the target object
7
9
  * @returns the query result
8
10
  */
9
- const isHTMLElement = (element?: HTMLElement | Node): element is HTMLElement =>
10
- (element && element.nodeType === 1) || false;
11
+ const isHTMLElement = (element?: unknown): element is HTMLElement =>
12
+ (isNode(element) && element.nodeType === 1) || false;
11
13
  export default isHTMLElement;
@@ -1,10 +1,12 @@
1
+ import isHTMLElement from './isHTMLElement';
2
+
1
3
  /**
2
4
  * Check if a target element is an `<img>`.
3
5
  *
4
6
  * @param element the target element
5
7
  * @returns the query result
6
8
  */
7
- const isHTMLImageElement = (element?: HTMLImageElement): element is HTMLImageElement =>
8
- (element && element.tagName === 'IMG') || false;
9
+ const isHTMLImageElement = (element?: unknown): element is HTMLImageElement =>
10
+ (isHTMLElement(element) && element.tagName === 'IMG') || false;
9
11
 
10
12
  export default isHTMLImageElement;
package/src/is/isMap.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import isObject from './isObject';
2
+
1
3
  /**
2
4
  * Checks if an element is a `Map`.
3
5
  *
4
6
  * @param obj the target object
5
7
  * @returns the query result
6
8
  */
7
- const isMap = <T extends Map<any, any>>(obj?: T): obj is T =>
8
- (obj && obj.constructor.name === 'Map') || false;
9
+ const isMap = (obj?: unknown): obj is Map<any, any> =>
10
+ (isObject(obj) && obj.constructor.name === 'Map') || false;
9
11
  export default isMap;
package/src/is/isMedia.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Checks if an element is an `<svg>` (or any type of SVG element),
3
5
  * `<img>`, `<video>` or `<canvas>`.
@@ -9,10 +11,9 @@
9
11
  */
10
12
 
11
13
  const isMedia = (
12
- element?: SVGElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement,
14
+ element?: unknown,
13
15
  ): element is SVGElement | HTMLImageElement | HTMLVideoElement | HTMLCanvasElement =>
14
- (element &&
15
- element.nodeType === 1 &&
16
+ (isNode(element) &&
16
17
  ['SVG', 'Image', 'Video', 'Canvas'].some(s => element.constructor.name.includes(s))) ||
17
18
  false;
18
19
 
package/src/is/isNode.ts CHANGED
@@ -1,11 +1,17 @@
1
+ import isObject from './isObject';
2
+
3
+ type NodeObject = object & { nodeType: number };
4
+
1
5
  /**
2
6
  * Checks if an object is a `Node`.
3
7
  *
4
8
  * @param node the target object
5
9
  * @returns the query result
6
10
  */
7
-
8
- const isNode = (node?: Node): node is Node =>
9
- (node && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some(x => node.nodeType === x)) || false;
11
+ const isNode = (node?: unknown): node is Node =>
12
+ (isObject(node) &&
13
+ typeof (node as NodeObject).nodeType === 'number' &&
14
+ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].some(x => (node as NodeObject).nodeType === x)) ||
15
+ false;
10
16
 
11
17
  export default isNode;
@@ -1,3 +1,5 @@
1
+ import isObject from './isObject';
2
+
1
3
  /**
2
4
  * Checks if an object is a `NodeList`.
3
5
  * => equivalent to `object instanceof NodeList`
@@ -5,7 +7,7 @@
5
7
  * @param obj the target object
6
8
  * @returns the query result
7
9
  */
8
- const isNodeList = (obj?: NodeList): obj is NodeList =>
9
- (obj && obj.constructor.name === 'NodeList') || false;
10
+ const isNodeList = (obj?: unknown): obj is NodeList =>
11
+ (isObject(obj) && obj.constructor.name === 'NodeList') || false;
10
12
 
11
13
  export default isNodeList;
@@ -4,6 +4,6 @@
4
4
  * @param num input value
5
5
  * @returns the query result
6
6
  */
7
- const isNumber = (num?: number): num is number => typeof num === 'number' || false;
7
+ const isNumber = (num?: unknown): num is number => typeof num === 'number' || false;
8
8
 
9
9
  export default isNumber;
@@ -4,6 +4,7 @@
4
4
  * @param obj the target object
5
5
  * @returns the query result
6
6
  */
7
- const isObject = (obj?: object): obj is object => typeof obj === 'object' || false;
7
+ const isObject = (obj?: unknown): obj is object =>
8
+ (obj !== null && obj !== undefined && typeof obj === 'object') || false;
8
9
 
9
10
  export default isObject;
@@ -1,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Check if an element is an `<svg>` or any other SVG element,
3
5
  * an equivalent to `SOMETHING instanceof SVGElement`.
@@ -5,7 +7,7 @@
5
7
  * @param element the target element
6
8
  * @returns the query result
7
9
  */
8
- const isSVGElement = (element?: SVGElement): element is SVGElement =>
9
- (element && element.constructor.name.includes('SVG')) || false;
10
+ const isSVGElement = (element?: unknown): element is SVGElement =>
11
+ (isNode(element) && element.constructor.name.includes('SVG')) || false;
10
12
 
11
13
  export default isSVGElement;
@@ -1,10 +1,12 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Check if target is a `ShadowRoot`.
3
5
  *
4
6
  * @param element target
5
7
  * @returns the query result
6
8
  */
7
- const isShadowRoot = (element?: Node | ShadowRoot): element is ShadowRoot =>
8
- (element && element.constructor.name === 'ShadowRoot') || false;
9
+ const isShadowRoot = (element?: unknown): element is ShadowRoot =>
10
+ (isNode(element) && element.constructor.name === 'ShadowRoot') || false;
9
11
 
10
12
  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?: string): str is string => typeof str === 'string' || false;
7
+ const isString = (str?: unknown): str is string => typeof str === 'string' || false;
8
8
 
9
9
  export default isString;
@@ -1,3 +1,5 @@
1
+ import isNode from './isNode';
2
+
1
3
  /**
2
4
  * Check if a target element is a `<table>`, `<td>` or `<th>`.
3
5
  * This specific check is important for determining
@@ -6,9 +8,7 @@
6
8
  * @param element the target element
7
9
  * @returns the query result
8
10
  */
9
- const isTableElement = (
10
- element?: HTMLTableElement | HTMLTableCellElement,
11
- ): element is HTMLTableElement | HTMLTableCellElement =>
12
- (element && ['TABLE', 'TD', 'TH'].includes(element.tagName)) || false;
11
+ const isTableElement = (element?: unknown): element is HTMLTableElement | HTMLTableCellElement =>
12
+ (isNode(element) && ['TABLE', 'TD', 'TH'].includes(element.nodeName)) || false;
13
13
 
14
14
  export default isTableElement;
@@ -1,9 +1,11 @@
1
+ import isObject from './isObject';
2
+
1
3
  /**
2
4
  * Checks if an element is a `WeakMap`.
3
5
  *
4
6
  * @param obj the target object
5
7
  * @returns the query result
6
8
  */
7
- const isWeakMap = <T extends WeakMap<any, unknown>>(obj?: T): obj is T =>
8
- (obj && obj.constructor.name === 'WeakMap') || false;
9
+ const isWeakMap = (obj?: unknown): obj is WeakMap<any, any> =>
10
+ (isObject(obj) && obj.constructor.name === 'WeakMap') || false;
9
11
  export default isWeakMap;
@@ -1,3 +1,5 @@
1
+ import isObject from './isObject';
2
+
1
3
  /**
2
4
  * Check if a target object is `Window`.
3
5
  * => equivalent to `object instanceof Window`
@@ -5,7 +7,7 @@
5
7
  * @param obj the target object
6
8
  * @returns the query result
7
9
  */
8
- const isWindow = (obj?: Node | Window): obj is Window =>
9
- (obj && obj.constructor.name === 'Window') || false;
10
+ const isWindow = (obj?: unknown): obj is Window =>
11
+ (isObject(obj) && obj.constructor.name === 'Window') || false;
10
12
 
11
13
  export default isWindow;
@@ -0,0 +1,17 @@
1
+ import isObject from '../is/isObject';
2
+
3
+ /**
4
+ * A shortcut to `Object.hasOwn()` static method to work
5
+ * with regular `Object` elements.
6
+ *
7
+ * @see https://fettblog.eu/typescript-hasownproperty/
8
+ * @param obj the target object
9
+ * @param prop the property to check
10
+ * @returns the query result
11
+ */
12
+ const ObjectHasOwn = <T extends object, K extends PropertyKey>(
13
+ obj: T,
14
+ prop: K,
15
+ ): obj is T & Record<K, unknown> => isObject(obj) && (Object.hasOwn(obj, prop) || prop in obj);
16
+
17
+ export default ObjectHasOwn;
@@ -1,4 +1,4 @@
1
- import { OriginalEvent } from '../interface/originalEvent';
1
+ import type { OriginalEvent } from '../interface/originalEvent';
2
2
  import isObject from '../is/isObject';
3
3
  import ObjectAssign from './ObjectAssign';
4
4
 
@@ -14,9 +14,7 @@ import ObjectEntries from './ObjectEntries';
14
14
  * @param param `tagName` or object
15
15
  * @return a new `HTMLElement`
16
16
  */
17
- const createElement = (
18
- param?: string | Exclude<HTMLElement, ((...args: any[]) => any) | object>,
19
- ): HTMLElement | undefined => {
17
+ const createElement = (param?: string | Partial<HTMLElement>): HTMLElement | undefined => {
20
18
  if (!param) return undefined;
21
19
 
22
20
  if (isString(param)) {
@@ -17,7 +17,7 @@ import isString from '../is/isString';
17
17
  */
18
18
  const createElementNS = (
19
19
  ns: string,
20
- param?: string | Exclude<HTMLElement, ((...args: any[]) => any) | object>,
20
+ param?: string | Partial<HTMLElement>,
21
21
  ): HTMLElement | undefined => {
22
22
  if (!ns || !param) return undefined;
23
23