dom-nodes
Installation
$ npm i dom-nodes -S
Usage
import {isVoid} from 'dom-nodes'
isVoid('div')
isVoid('img')
dom-nodes
exports all the methods listed below giving you some simple tests to understand which kind of node you are dealing with.
This project includes html-tags and svg-tag-names directly in its source code avoiding to rely on third party npm modules for such simple list of strings.
This project couldn't have been made without the projects above!
API
Table of Contents
VOID_SVG_TAGS_LIST
SVG void elements that cannot be auto-closed and shouldn't contain child nodes.
Type: Array
HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_LIST
List of html elements where the value attribute is allowed
Type: Array
SVG_TAGS_LIST
List of all the available svg tags
Type: Array
VOID_HTML_TAGS_LIST
HTML void elements that cannot be auto-closed and shouldn't contain child nodes.
Type: Array
HTML_TAGS_LIST
List of all the html tags
Type: Array
BOOLEAN_ATTRIBUTES_LIST
List of all boolean HTML attributes
Type: RegExp
HTML_TAGS_RE
Regex matching all the html tags ignoring the cases
Type: RegExp
SVG_TAGS_RE
Regex matching all the svg tags ignoring the cases
Type: RegExp
VOID_HTML_TAGS_RE
Regex matching all the void html tags ignoring the cases
Type: RegExp
VOID_SVG_TAGS_RE
Regex matching all the void svg tags ignoring the cases
Type: RegExp
HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_RE
Regex matching all the html tags where the value tag is allowed
Type: RegExp
BOOLEAN_ATTRIBUTES_RE
Regex matching all the boolean attributes
Type: RegExp
isVoid
True if it's a self closing tag
Parameters
Examples
isVoid('meta')
isVoid('circle')
isVoid('IMG')
isVoid('div')
isVoid('mask')
Returns boolean true if void
isHtml
True if it's a known HTML tag
Parameters
Examples
isHtml('img')
isHtml('IMG')
isHtml('Img')
isHtml('path')
Returns boolean true if html tag
isSvg
True if it's a known SVG tag
Parameters
Examples
isSvg('g')
isSvg('radialGradient')
isSvg('radialgradient')
isSvg('div')
Returns boolean true if svg tag
isCustom
True if it's not SVG nor a HTML known tag
Parameters
Examples
isCustom('my-component')
isCustom('div')
Returns boolean true if custom element
hasValueAttribute
True if the value attribute is allowed on this tag
Parameters
Examples
hasValueAttribute('input')
hasValueAttribute('div')
Returns boolean true if the value attribute is allowed
isBoolAttribute
True if it's a boolean attribute
Parameters
attribute
string test attribute
Examples
isBoolAttribute('selected')
isBoolAttribute('class')
Returns boolean true if the attribute is a boolean type