@domql/utils 2.3.100 → 2.3.103
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/dist/cjs/node.js +44 -0
- package/dist/cjs/types.js +3 -11
- package/node.js +37 -0
- package/package.json +2 -2
- package/types.js +1 -17
package/dist/cjs/node.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
+
isHtmlElement: () => isHtmlElement,
|
|
21
22
|
isNode: () => isNode
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(node_exports);
|
|
@@ -26,3 +27,46 @@ const isNode = (node) => {
|
|
|
26
27
|
const { Node } = import_globals.window;
|
|
27
28
|
return typeof Node === "function" ? node instanceof Node : node && typeof node === "object" && typeof node.nodeType === "number" && typeof node.tag === "string";
|
|
28
29
|
};
|
|
30
|
+
const isHtmlElement = (obj) => {
|
|
31
|
+
let hasHTMLElement = false;
|
|
32
|
+
try {
|
|
33
|
+
if (import_globals.window.HTMLElement !== void 0) {
|
|
34
|
+
hasHTMLElement = true;
|
|
35
|
+
}
|
|
36
|
+
} catch (e1) {
|
|
37
|
+
}
|
|
38
|
+
if (obj !== null && obj !== void 0) {
|
|
39
|
+
if (hasHTMLElement && typeof obj === "object") {
|
|
40
|
+
return obj instanceof import_globals.window.HTMLElement;
|
|
41
|
+
} else {
|
|
42
|
+
try {
|
|
43
|
+
if ("nodeType" in obj) {
|
|
44
|
+
return obj.nodeType === 1;
|
|
45
|
+
} else if ("tagName" in obj) {
|
|
46
|
+
return obj.tagName !== null;
|
|
47
|
+
} else {
|
|
48
|
+
return "canHaveHTML" in obj;
|
|
49
|
+
}
|
|
50
|
+
} catch (e2) {
|
|
51
|
+
try {
|
|
52
|
+
if (obj.nodeType) {
|
|
53
|
+
return obj.nodeType === 1;
|
|
54
|
+
} else if (obj.tagName) {
|
|
55
|
+
return obj.tagName !== null;
|
|
56
|
+
} else {
|
|
57
|
+
return !!obj.canHaveHTML;
|
|
58
|
+
}
|
|
59
|
+
} catch (e3) {
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if ("IMDebugger" in import_globals.window) {
|
|
66
|
+
new import_globals.window.IMDebugger().pass("isHTMLElement must be supplied something.");
|
|
67
|
+
} else {
|
|
68
|
+
console.log("isHTMLElement must be supplied something.");
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
};
|
package/dist/cjs/types.js
CHANGED
|
@@ -24,8 +24,6 @@ __export(types_exports, {
|
|
|
24
24
|
isBoolean: () => isBoolean,
|
|
25
25
|
isDefined: () => isDefined,
|
|
26
26
|
isFunction: () => isFunction,
|
|
27
|
-
isHtmlElement: () => isHtmlElement,
|
|
28
|
-
isNode: () => isNode,
|
|
29
27
|
isNot: () => isNot,
|
|
30
28
|
isNull: () => isNull,
|
|
31
29
|
isNumber: () => isNumber,
|
|
@@ -36,8 +34,8 @@ __export(types_exports, {
|
|
|
36
34
|
isValidHtmlTag: () => isValidHtmlTag
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(types_exports);
|
|
39
|
-
var import_globals = require("@domql/globals");
|
|
40
37
|
var import_tags = require("@domql/tags");
|
|
38
|
+
var import_node = require("./node");
|
|
41
39
|
const isValidHtmlTag = (arg) => import_tags.HTML_TAGS.body.includes(arg);
|
|
42
40
|
const isObject = (arg) => {
|
|
43
41
|
if (arg === null)
|
|
@@ -55,12 +53,6 @@ const isObjectLike = (arg) => {
|
|
|
55
53
|
return false;
|
|
56
54
|
return typeof arg === "object";
|
|
57
55
|
};
|
|
58
|
-
const isNode = (obj) => {
|
|
59
|
-
return typeof import_globals.window.Node === "object" ? obj instanceof import_globals.window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
|
|
60
|
-
};
|
|
61
|
-
const isHtmlElement = (obj) => {
|
|
62
|
-
return typeof import_globals.window.HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
63
|
-
};
|
|
64
56
|
const isDefined = (arg) => {
|
|
65
57
|
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
66
58
|
};
|
|
@@ -76,8 +68,8 @@ const TYPES = {
|
|
|
76
68
|
null: isNull,
|
|
77
69
|
function: isFunction,
|
|
78
70
|
objectLike: isObjectLike,
|
|
79
|
-
node: isNode,
|
|
80
|
-
htmlElement: isHtmlElement,
|
|
71
|
+
node: import_node.isNode,
|
|
72
|
+
htmlElement: import_node.isHtmlElement,
|
|
81
73
|
defined: isDefined
|
|
82
74
|
};
|
|
83
75
|
const is = (arg) => {
|
package/node.js
CHANGED
|
@@ -13,3 +13,40 @@ export const isNode = (node) => {
|
|
|
13
13
|
typeof node.tag === 'string'
|
|
14
14
|
)
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/** @url https://github.com/jimbrittain/isHTMLElement/tree/master */
|
|
18
|
+
export const isHtmlElement = obj => {
|
|
19
|
+
let hasHTMLElement = false
|
|
20
|
+
try {
|
|
21
|
+
if (window.HTMLElement !== undefined) { hasHTMLElement = true }
|
|
22
|
+
} catch (e1) {}
|
|
23
|
+
if (obj !== null && obj !== undefined) {
|
|
24
|
+
if (hasHTMLElement && typeof obj === 'object') {
|
|
25
|
+
return ((obj instanceof window.HTMLElement))
|
|
26
|
+
} else {
|
|
27
|
+
try {
|
|
28
|
+
if ('nodeType' in obj) {
|
|
29
|
+
return ((obj.nodeType === 1))
|
|
30
|
+
} else if ('tagName' in obj) {
|
|
31
|
+
return (obj.tagName !== null)
|
|
32
|
+
} else { return ('canHaveHTML' in obj) }
|
|
33
|
+
} catch (e2) {
|
|
34
|
+
try {
|
|
35
|
+
if (obj.nodeType) {
|
|
36
|
+
return ((obj.nodeType === 1))
|
|
37
|
+
} else if (obj.tagName) {
|
|
38
|
+
return (obj.tagName !== null)
|
|
39
|
+
} else { return !!(obj.canHaveHTML) }
|
|
40
|
+
} catch (e3) {}
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
if ('IMDebugger' in window) {
|
|
46
|
+
(new window.IMDebugger()).pass('isHTMLElement must be supplied something.')
|
|
47
|
+
} else {
|
|
48
|
+
console.log('isHTMLElement must be supplied something.')
|
|
49
|
+
}
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.103",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@domql/globals": "latest",
|
|
23
23
|
"@domql/tags": "latest"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "7164391acbd537941db294707e1ad808d5368894"
|
|
26
26
|
}
|
package/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { window } from '@domql/globals'
|
|
4
3
|
import { HTML_TAGS } from '@domql/tags'
|
|
4
|
+
import { isHtmlElement, isNode } from './node'
|
|
5
5
|
|
|
6
6
|
export const isValidHtmlTag = arg => HTML_TAGS.body.includes(arg)
|
|
7
7
|
|
|
@@ -28,22 +28,6 @@ export const isObjectLike = arg => {
|
|
|
28
28
|
return (typeof arg === 'object')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export const isNode = obj => {
|
|
32
|
-
return (
|
|
33
|
-
typeof window.Node === 'object'
|
|
34
|
-
? obj instanceof window.Node
|
|
35
|
-
: obj && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const isHtmlElement = obj => {
|
|
40
|
-
return (
|
|
41
|
-
typeof window.HTMLElement === 'object'
|
|
42
|
-
? obj instanceof window.HTMLElement // DOM2
|
|
43
|
-
: obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
31
|
export const isDefined = arg => {
|
|
48
32
|
return isObject(arg) ||
|
|
49
33
|
isObjectLike(arg) ||
|