Socket
Socket
Sign inDemoInstall

email-doctype

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-doctype

Easily manage your email's Document Type Definition (DTD).


Version published
Maintainers
1
Created
Source

Email Doctype

Easily manage your email's Document Type Definition (DTD).

Install with yarn

yarn add email-doctype

Or install with npm:

npm install email-doctype

Doctypes

KeysAlias PrefixAlias VersionAlias Suffix
html-5h or html5n/a
html-4.01-stricth or html4.01s or strict
html-4.01-transitionalh or htmln/at or transitional
xhtml-1.1x or xhtml1.1n/a
xhtml-1.0-strictx or xhtml1 or 1.0s or strict
xhtml-1.0-transitionalx or xhtmln/at or transitional

Aliases

While you can easily get a doctype using a Key, you can also use an alias. An alias can be an Alias Version or string composing of an Alias Prefix, Alias Version, and Alias Suffix.

  • Casing will be normalized so keys and aliases are case insensitive
  • Whitespace is removed so spaces are allowed
  • When there is an Alias Suffix available but not used, the returned doctype will use the strict alias suffix

Examples

Checkout the test for more examples.

import * as doctype from 'email-doctype';

doctype.version('recommended');
doctype.version('html-1.0-transitional');
doctype.version('XHTML 1.0 Transitional');
// => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'

doctype.version(5);
doctype.version('html-5');
doctype.version('HTML 5');
// => '<!DOCTYPE html>'

doctype.version(4.01);
doctype.version('xhtml-4.01-strict');
// => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'

doctype.version(1.1);
doctype.version('xhtml-1.1');
doctype.version('XHTML 1.1');
// => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'

doctype.version(1.0);
doctype.version('xhtml-1.0-strict');
doctype.version('XHTML 1.0 Strict');
// => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'

Extracting a doctype

Extract the doctype from a given html string.

import { extract } from 'email-doctype';

const html = '<!DOCTYPE html> <html><head></head><body></body></html>';

extract(html);
// => '<!DOCTYPE html>'

Setting a doctype

Add a doctype to a given html string.

import { set } from 'email-doctype';

const html = '<html><head></head><body></body></html>';

set(html, 'HTML 5');
// => '<!DOCTYPE html> <html><head></head><body></body></html>'

Automatic replacement

When the given html contains a doctype, it will be automatically replaced with your new doctype.

import { set } from 'email-doctype';

const html = '<!DOCTYPE html> <html><head></head><body></body></html>';

set(html, 'HTML 4.01');
// '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head></head><body></body></html>'

Removing a doctype

Remove a given html string's doctype, returning just the html.

import { remove } from 'email-doctype';

const html = '<!DOCTYPE html> <html><head></head><body></body></html>';

remove(html);
// => '<html><head></head><body></body></html>'

API

version

version(alias: string): string

Gets a doctype from a given alias.

extract

extract(html: string): string

Extracts the doctype from a given html string.

set

set(html: string, alias: string = 'recommended'): string

Adds a doctype to a given html string.

remove

remove(html: string): string

Removes a given html string's doctype, returning just the html.

FAQs

Package last updated on 23 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc