@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.
- package/README.md +7 -5
- package/dist/shorty.cjs +1 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +1454 -377
- package/dist/shorty.js +1 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +364 -365
- package/dist/shorty.mjs.map +1 -1
- package/package.json +10 -9
- package/src/boolean/isApple.ts +1 -1
- package/src/event/one.ts +1 -1
- package/src/get/getBoundingClientRect.ts +1 -1
- package/src/get/getElementTransitionDelay.ts +3 -1
- package/src/get/getElementTransitionDuration.ts +3 -1
- package/src/get/getRectRelativeToOffsetParent.ts +1 -1
- package/src/index.ts +5 -4
- package/src/interface/{boundingClientRect.ts → boundingClientRect.d.ts} +1 -1
- package/src/interface/css4Declaration.d.ts +4 -0
- package/src/interface/{customElement.ts → customElement.d.ts} +2 -2
- package/src/interface/{navigatorUA.ts → navigatorUA.d.ts} +3 -3
- package/src/interface/{offsetRect.ts → offsetRect.d.ts} +1 -1
- package/src/interface/originalEvent.d.ts +4 -0
- package/src/is/isArray.ts +1 -1
- package/src/is/isCanvas.ts +4 -2
- package/src/is/isCustomElement.ts +4 -3
- package/src/is/isDocument.ts +3 -1
- package/src/is/isElement.ts +4 -2
- package/src/is/isElementsArray.ts +1 -1
- package/src/is/isFunction.ts +1 -1
- package/src/is/isHTMLCollection.ts +4 -2
- package/src/is/isHTMLElement.ts +4 -2
- package/src/is/isHTMLImageElement.ts +4 -2
- package/src/is/isMap.ts +4 -2
- package/src/is/isMedia.ts +4 -3
- package/src/is/isNode.ts +9 -3
- package/src/is/isNodeList.ts +4 -2
- package/src/is/isNumber.ts +1 -1
- package/src/is/isObject.ts +2 -1
- package/src/is/isSVGElement.ts +4 -2
- package/src/is/isShadowRoot.ts +4 -2
- package/src/is/isString.ts +1 -1
- package/src/is/isTableElement.ts +4 -4
- package/src/is/isWeakMap.ts +4 -2
- package/src/is/isWindow.ts +4 -2
- package/src/misc/ObjectHasOwn.ts +17 -0
- package/src/misc/createCustomEvent.ts +1 -1
- package/src/misc/createElement.ts +1 -3
- package/src/misc/createElementNS.ts +1 -1
- package/src/misc/data.ts +12 -26
- package/src/misc/getInstance.ts +9 -0
- package/src/misc/setElementStyle.ts +1 -1
- package/src/selectors/getCustomElements.ts +1 -1
- package/src/selectors/querySelector.ts +6 -5
- package/src/strings/userAgentData.ts +1 -1
- package/src/interface/css4Declaration.ts +0 -3
- 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.
|
|
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.
|
|
29
|
-
"fix:ts": "eslint -c .eslintrc.
|
|
30
|
-
"build": "npm run
|
|
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
|
-
"@
|
|
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": "^
|
|
59
|
-
"dts-bundle-generator": "^
|
|
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.
|
|
73
|
+
"typescript": "^4.9.4",
|
|
73
74
|
"vite": "^3.0.9"
|
|
74
75
|
}
|
|
75
76
|
}
|
package/src/boolean/isApple.ts
CHANGED
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
|
}
|
|
@@ -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'
|
|
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'
|
|
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
|
|
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
|
-
|
|
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,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:
|
|
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
|
}
|
package/src/is/isArray.ts
CHANGED
package/src/is/isCanvas.ts
CHANGED
|
@@ -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?:
|
|
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
|
|
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?:
|
|
10
|
-
(element && !!(element as
|
|
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;
|
package/src/is/isDocument.ts
CHANGED
|
@@ -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?:
|
|
11
|
+
const isDocument = (obj?: unknown): obj is Document => (isNode(obj) && obj.nodeType === 9) || false;
|
|
10
12
|
|
|
11
13
|
export default isDocument;
|
package/src/is/isElement.ts
CHANGED
|
@@ -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?:
|
|
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?:
|
|
10
|
+
const isElementsArray = (obj?: unknown): obj is HTMLElement[] =>
|
|
11
11
|
(isArray(obj) && obj.every(isHTMLElement)) || false;
|
|
12
12
|
|
|
13
13
|
export default isElementsArray;
|
package/src/is/isFunction.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param fn the target object
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
|
-
const isFunction =
|
|
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?:
|
|
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;
|
package/src/is/isHTMLElement.ts
CHANGED
|
@@ -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?:
|
|
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?:
|
|
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 =
|
|
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?:
|
|
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
|
-
|
|
9
|
-
|
|
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;
|
package/src/is/isNodeList.ts
CHANGED
|
@@ -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?:
|
|
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;
|
package/src/is/isNumber.ts
CHANGED
package/src/is/isObject.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @param obj the target object
|
|
5
5
|
* @returns the query result
|
|
6
6
|
*/
|
|
7
|
-
const isObject = (obj?:
|
|
7
|
+
const isObject = (obj?: unknown): obj is object =>
|
|
8
|
+
(obj !== null && obj !== undefined && typeof obj === 'object') || false;
|
|
8
9
|
|
|
9
10
|
export default isObject;
|
package/src/is/isSVGElement.ts
CHANGED
|
@@ -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?:
|
|
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;
|
package/src/is/isShadowRoot.ts
CHANGED
|
@@ -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?:
|
|
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;
|
package/src/is/isString.ts
CHANGED
package/src/is/isTableElement.ts
CHANGED
|
@@ -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
|
|
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;
|
package/src/is/isWeakMap.ts
CHANGED
|
@@ -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 =
|
|
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;
|
package/src/is/isWindow.ts
CHANGED
|
@@ -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?:
|
|
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;
|
|
@@ -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 |
|
|
20
|
+
param?: string | Partial<HTMLElement>,
|
|
21
21
|
): HTMLElement | undefined => {
|
|
22
22
|
if (!ns || !param) return undefined;
|
|
23
23
|
|