From ada2337421740f683d731b40f2fc8b492241a210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Fri, 16 Apr 2021 02:17:32 -0700 Subject: [PATCH] refactor: Use tagtypes from `domhandler` (#593) --- package-lock.json | 14 +++++++------- package.json | 2 +- src/helpers.ts | 3 +-- src/index.ts | 9 ++++++++- src/legacy.ts | 3 +-- src/querying.ts | 3 +-- src/stringify.ts | 3 +-- src/tagtypes.ts | 42 ------------------------------------------ src/traversal.ts | 3 +-- 9 files changed, 21 insertions(+), 61 deletions(-) delete mode 100644 src/tagtypes.ts diff --git a/package-lock.json b/package-lock.json index 20d4ce54..2bffad75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "dom-serializer": "^1.0.1", "domelementtype": "^2.2.0", - "domhandler": "^4.1.0" + "domhandler": "^4.2.0" }, "devDependencies": { "@types/jest": "^26.0.0", @@ -2243,9 +2243,9 @@ } }, "node_modules/domhandler": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.1.0.tgz", - "integrity": "sha512-/6/kmsGlMY4Tup/nGVutdrK9yQi4YjWVcVeoQmixpzjOUK1U7pQkvAPHBJeUxOgxF0J8f8lwCJSlCfD0V4CMGQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.0.tgz", + "integrity": "sha512-zk7sgt970kzPks2Bf+dwT/PLzghLnsivb9CcxkvR8Mzr66Olr0Ofd8neSbglHJHaHa2MadfoSdNlKYAaafmWfA==", "dependencies": { "domelementtype": "^2.2.0" }, @@ -9121,9 +9121,9 @@ } }, "domhandler": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.1.0.tgz", - "integrity": "sha512-/6/kmsGlMY4Tup/nGVutdrK9yQi4YjWVcVeoQmixpzjOUK1U7pQkvAPHBJeUxOgxF0J8f8lwCJSlCfD0V4CMGQ==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.0.tgz", + "integrity": "sha512-zk7sgt970kzPks2Bf+dwT/PLzghLnsivb9CcxkvR8Mzr66Olr0Ofd8neSbglHJHaHa2MadfoSdNlKYAaafmWfA==", "requires": { "domelementtype": "^2.2.0" } diff --git a/package.json b/package.json index cd0997cc..8a571b26 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "dependencies": { "dom-serializer": "^1.0.1", "domelementtype": "^2.2.0", - "domhandler": "^4.1.0" + "domhandler": "^4.2.0" }, "devDependencies": { "@types/jest": "^26.0.0", diff --git a/src/helpers.ts b/src/helpers.ts index 40e37455..26d550bc 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,5 +1,4 @@ -import type { Node } from "domhandler"; -import { hasChildren } from "./tagtypes"; +import { hasChildren, Node } from "domhandler"; /** * Given an array of nodes, remove any member that is contained by another. diff --git a/src/index.ts b/src/index.ts index 4babc7af..8cf82b12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,4 +4,11 @@ export * from "./manipulation"; export * from "./querying"; export * from "./legacy"; export * from "./helpers"; -export * from "./tagtypes"; +export { + isTag, + isCDATA, + isText, + isComment, + isDocument, + hasChildren, +} from "domhandler"; diff --git a/src/legacy.ts b/src/legacy.ts index 20323161..5dc27240 100644 --- a/src/legacy.ts +++ b/src/legacy.ts @@ -1,7 +1,6 @@ -import type { Node, Element } from "domhandler"; +import { isTag, isText, Node, Element } from "domhandler"; import { ElementType } from "domelementtype"; import { filter, findOne } from "./querying"; -import { isTag, isText } from "./tagtypes"; type TestType = (elem: Node) => boolean; diff --git a/src/querying.ts b/src/querying.ts index 6e2d28e0..1504cac5 100644 --- a/src/querying.ts +++ b/src/querying.ts @@ -1,5 +1,4 @@ -import type { Node, Element } from "domhandler"; -import { isTag, hasChildren } from "./tagtypes"; +import { isTag, hasChildren, Node, Element } from "domhandler"; /** * Search a node and its children for nodes passing a test function. diff --git a/src/stringify.ts b/src/stringify.ts index 52a5485c..81b2b56c 100644 --- a/src/stringify.ts +++ b/src/stringify.ts @@ -1,5 +1,4 @@ -import type { Node } from "domhandler"; -import { isTag, isCDATA, isText, hasChildren } from "./tagtypes"; +import { isTag, isCDATA, isText, hasChildren, Node } from "domhandler"; import renderHTML, { DomSerializerOptions } from "dom-serializer"; /** diff --git a/src/tagtypes.ts b/src/tagtypes.ts deleted file mode 100644 index fa6194c7..00000000 --- a/src/tagtypes.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { Node, Element, NodeWithChildren, DataNode } from "domhandler"; -import { ElementType, isTag as isTagRaw } from "domelementtype"; - -/** - * @param node Node to check. - * @returns `true` if the node is a `Element`, `false` otherwise. - */ -export function isTag(node: Node): node is Element { - return isTagRaw(node); -} - -/** - * @param node Node to check. - * @returns `true` if the node has the type `CDATA`, `false` otherwise. - */ -export function isCDATA(node: Node): node is NodeWithChildren { - return node.type === ElementType.CDATA; -} - -/** - * @param node Node to check. - * @returns `true` if the node has the type `Text`, `false` otherwise. - */ -export function isText(node: Node): node is DataNode { - return node.type === ElementType.Text; -} - -/** - * @param node Node to check. - * @returns `true` if the node has the type `Comment`, `false` otherwise. - */ -export function isComment(node: Node): node is DataNode { - return node.type === ElementType.Comment; -} - -/** - * @param node Node to check. - * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise. - */ -export function hasChildren(node: Node): node is NodeWithChildren { - return Object.prototype.hasOwnProperty.call(node, "children"); -} diff --git a/src/traversal.ts b/src/traversal.ts index 61c69d8f..f7816098 100644 --- a/src/traversal.ts +++ b/src/traversal.ts @@ -1,5 +1,4 @@ -import type { Node, Element, NodeWithChildren } from "domhandler"; -import { isTag } from "./tagtypes"; +import { isTag, Node, Element, NodeWithChildren } from "domhandler"; const emptyArray: Node[] = []; /**