doctype

Information for HTML doctypes

Usage no npm install needed!

<script type="module">
  import doctype from 'https://cdn.skypack.dev/doctype';
</script>

README

doctype

Build Coverage Downloads Size

Info on HTML / XHTML / MathML / SVG doctypes.

Contents

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install doctype

In Deno with Skypack:

import {doctype} from 'https://cdn.skypack.dev/doctype@3?dts'

In browsers with Skypack:

<script type="module">
  import {doctype} from 'https://cdn.skypack.dev/doctype@3?min'
</script>

Use

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

API

This package exports the following identifiers: doctype and doctypes. There is no default export.

doctype(name)

Get a doctype from a fuzzy doctype name.

Parameters
  • 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.

{
  'HTML 5': 'html',
  'HTML 4.01 Strict': 'HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"',
  // …
}

Types

This package is fully typed with TypeScript.

Compatibility

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.

Security

This package is safe.

Related

Contribute

Yes please! See How to Contribute to Open Source.

License

MIT © Titus Wormer