# html-tag-check

> HTML Tag Checker by TypeScript

Latest version **0.1.8** (published 2023-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install html-tag-check
pnpm add html-tag-check
yarn add html-tag-check
bun add html-tag-check
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2023-03-27 |
| First published | 2023-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Koki Nagai |
| Maintainers | kokinagai |
| Keywords | TypeScript, HTML, tag, check, error, validation |

## Links

- npm: https://www.npmjs.com/package/html-tag-check
- Repository: https://github.com/NagaiKoki/html-tag-check
- Issues: https://github.com/NagaiKoki/html-tag-chck/issues
- npm.io page: https://npm.io/package/html-tag-check

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.1.8 (latest) — 2023-03-27
- 0.1.7 — 2023-03-27
- 0.1.6 — 2023-03-26
- 0.1.5 — 2023-03-26
- 0.1.4 — 2023-03-26
- 0.1.3 — 2023-03-24
- 0.1.2 — 2023-03-24
- 0.1.1 — 2023-03-24
- 0.1.0 — 2023-03-24

## README

## Introduction

This library enable to check html tag whether html is missed opening or closing tags by TypeScript

## Installation

You can use this from Node.js or JavaScript whatever.

```shell
npm install html-tag-check # npm
yarn add html-tag-check # yarn
pnpm add html-tag-check # pnpm
```

## How to use

```ts
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 } }
```

### Arguments

| Name      | Type     | Required | Description            |
| --------- | -------- | -------- | ---------------------- |
| `html`    | `string` | true     | html you want to check |
| `options` | `object` | false    | the options of checker |

#### options

| 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"] |

### Return

#### Valid

```ts
{
  type: "valid";
}
```

#### Invalid

##### extra closing tag error

```ts
{
  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.
    }
  ];
}
```

##### mismatch opening and closing tag error

```ts
{
  type: "invalid_mismatch_opening_and_closing_tag";
  detail: [
    {
      type: "opening";
      tag: string;
      index: number;
    },
    {
      type: "closing";
      tag: string;
      index: number;
    }
  ];
}
```

##### extra opening tag error

```ts
{
  type: "invalid_extra_opening_tag";
  detail: [
    {
      type: "opening";
      tag: string;
      index: number;
    }
  ];
};
```

---
_Source: https://npm.io/package/html-tag-check · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
