Info on HTML, XHTML, MathML, and SVG doctypes.
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Security
- Related
- Contribute
- License
This package lists known doctypes and exposes a function to turn a fuzzy name
(such as html
, 5
) into a corresponding doctype.
This package is rather niche, using something other than <!doctype html>
is
almost never needed anymore.
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
npm install doctype
In Deno with esm.sh
:
import {doctype} from 'https://esm.sh/doctype@3'
In browsers with esm.sh
:
<script type="module">
import {doctype} from 'https://esm.sh/doctype@3?bundle'
</script>
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 identifiers doctype
and 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
tot
)
Doctype string when found (string|null
).
Map of doctype names to doctype values (Record<string, string>
).
{
'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. It exports no additional types.
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
This package is safe.
wooorm/html-tag-names
— list of HTML tag nameswooorm/html-element-attributes
— map of HTML attributeswooorm/html-void-elements
— list of void HTML tag-nameswooorm/property-information
— info on HTML, SVG, etc propertieswooorm/web-namespaces
— map of web namespaces
Yes please! See How to Contribute to Open Source.