doctype
Version:
Information for HTML doctypes
164 lines (108 loc) • 3.91 kB
Markdown
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
Info on HTML / XHTML / MathML / SVG doctypes.
* [Install](
* [Use](
* [API](
* [`doctype(name)`](
* [`doctypes`](
* [Types](
* [Compatibility](
* [Security](
* [Related](
* [Contribute](
* [License](
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
```sh
npm install doctype
```
In Deno with [Skypack][]:
```js
import {doctype} from 'https://cdn.skypack.dev/doctype@3?dts'
```
In browsers with [Skypack][]:
```html
<script type="module">
import {doctype} from 'https://cdn.skypack.dev/doctype@3?min'
</script>
```
```js
import {doctype} from 'doctype'
console.log(doctype(5)) // => 'html'
console.log(doctype(4.01))
console.log(doctype('4.01t'))
console.log(doctype('4.01 Transitional'))
console.log(doctype('HTML 4.01 Transitional'))
// => 'HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"'
console.log(doctype('svg'))
// => 'svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"'
```
This package exports the following identifiers: [`doctype`](
[`doctypes`](
There is no default export.
Get a doctype from a fuzzy doctype name.
* `name` (`string`, `number`)
— fuzzy doctype name which is stripped from white space, casing, fractional
part of version, `'HTML'` or `'XHTML'` prefix, and whose suffixes are
normalized (`Transitional` to `t`)
###### Returns
`string?` — doctype string when found.
### `doctypes`
`Object` mapping doctype names to doctype strings.
```js
{
'HTML 5': 'html',
'HTML 4.01 Strict': 'HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"',
// …
}
```
This package is fully typed with [TypeScript][].
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.
This package is safe.
* [`wooorm/html-tag-names`](https://github.com/wooorm/html-tag-names)
— list of HTML tag names
* [`wooorm/html-element-attributes`](https://github.com/wooorm/html-element-attributes)
— map of HTML attributes
* [`wooorm/html-void-elements`](https://github.com/wooorm/html-void-elements)
— list of void HTML tag-names
* [`wooorm/property-information`](https://github.com/wooorm/property-information)
— info on HTML, SVG, etc properties
* [`wooorm/web-namespaces`](https://github.com/wooorm/web-namespaces)
— map of web namespaces
Yes please!
See [How to Contribute to Open Source][contribute].
[][license] © [Titus Wormer][author]
<!-- Definitions -->
[]: https://github.com/wooorm/doctype/workflows/main/badge.svg
[]: https://github.com/wooorm/doctype/actions
[]: https://img.shields.io/codecov/c/github/wooorm/doctype.svg
[]: https://codecov.io/github/wooorm/doctype
[]: https://img.shields.io/npm/dm/doctype.svg
[]: https://www.npmjs.com/package/doctype
[]: https://img.shields.io/bundlephobia/minzip/doctype.svg
[]: https://bundlephobia.com/result?p=doctype
[]: https://docs.npmjs.com/cli/install
[]: https://www.skypack.dev
[]: license
[]: https://wooorm.com
[]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[]: https://www.typescriptlang.org
[]: https://opensource.guide/how-to-contribute/