htmlev.js
Escaping and validation for embedding strings in HTML.
Home |
npm install htmlev
API
escapeText(content: string): string
Returns a representation of content
as HTML source code, usable in any element that can contain character references (everything but elements that can't have children, <script>, and <style>).
escapeAttributeValueDQ(content: string): string
Returns a representation of content
as HTML source code, usable in a double-quoted attribute value.
escapeAttributeValueSQ(content: string): string
Returns a representation of content
as HTML source code, usable in a single-quoted attribute value.
escapeAttributeValueUQ(content: string): string
Returns a representation of content
as HTML source code, usable in an unquoted attribute value.
isValidScript(content: string): boolean
Returns whether content
may be a script element's content. Does not work on partial script content - it may be true that isValidScript(a) && isValidScript(b) && !isValidScript(a + b)
.
isValidStyle(content: string): boolean
Returns whether content
may be a style element's content. Does not work on partial style content - it may be true that isValidStyle(a) && isValidStyle(b) && !isValidStyle(a + b)
.
isValidComment(content: string): boolean
Returns whether content
may be a comment's content. Does not work on partial comments - it may be true that isValidComment(a) && isValidComment(b) && !isValidComment(a + b)
.
isValidTagName(content: string): boolean
Returns whether content
is a valid tag name. This checks synax, not structure - the tag name may still be undefined by HTML5 or not a valid child of its intended parent.
isValidAttributeName(content: string): boolean
Returns whether content
is a valid attribute name.