This library enable to check html tag whether html is missed opening or closing tags by TypeScript
You can use this from Node.js or JavaScript whatever.
npm install html-tag-check # npm
yarn add html-tag-check # yarn
pnpm add html-tag-check # pnpm
import { htmlTagCheck } from "html-tag-check";
const HTML = "<div><p>Opening div tag isn't necessary!!</p>";
htmlTagCheck(HTML);
// => { type: "invalid_extra_opening_tag", detail: { type: "opening", tag: "<div>", index: 0 } }
Name | Type | Required | Description |
---|---|---|---|
html |
string |
true | html you want to check |
options |
object |
false | the options of checker |
Name | Type | Required | Description |
---|---|---|---|
trimHtml |
boolean |
false | remove new lines and white spaces from html string |
ignoreTagNames |
string[] |
false | tag names you want to ignore check. e.g. ["size","template"] |
{
type: "valid";
}
{
type: "invalid_extra_closing_tag";
detail: [
{
type: "closing"; // closing tag error
tag: string; // tag name like </div>
index: number; // tag index number from html string.
}
];
}
{
type: "invalid_mismatch_opening_and_closing_tag";
detail: [
{
type: "opening";
tag: string;
index: number;
},
{
type: "closing";
tag: string;
index: number;
}
];
}
{
type: "invalid_extra_opening_tag";
detail: [
{
type: "opening";
tag: string;
index: number;
}
];
};