You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
7.5 KiB

4 years ago
  1. # dom-nodes
  2. [![Build Status][travis-image]][travis-url]
  3. [![NPM version][npm-version-image]][npm-url]
  4. [![NPM downloads][npm-downloads-image]][npm-url]
  5. [![MIT License][license-image]][license-url]
  6. ## Installation
  7. ```bash
  8. $ npm i dom-nodes -S
  9. ```
  10. ## Usage
  11. ```js
  12. import {isVoid} from 'dom-nodes'
  13. isVoid('div') // false
  14. isVoid('img') // true
  15. ```
  16. `dom-nodes` exports all the methods [listed below](#API) giving you some simple tests to understand which kind of node you are dealing with.
  17. This project includes [html-tags](https://github.com/sindresorhus/html-tags) and [svg-tag-names](https://github.com/wooorm/svg-tag-names) directly in its source code avoiding to rely on third party npm modules for such simple list of strings.
  18. This project couldn't have been made without the projects above!
  19. [travis-image]: https://img.shields.io/travis/riot/dom-nodes.svg?style=flat-square
  20. [travis-url]: https://travis-ci.org/riot/dom-nodes
  21. [license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
  22. [license-url]: LICENSE
  23. [npm-version-image]: http://img.shields.io/npm/v/dom-nodes.svg?style=flat-square
  24. [npm-downloads-image]: http://img.shields.io/npm/dm/dom-nodes.svg?style=flat-square
  25. [npm-url]: https://npmjs.org/package/dom-nodes
  26. ## API
  27. <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
  28. #### Table of Contents
  29. - [VOID_SVG_TAGS_LIST](#void_svg_tags_list)
  30. - [HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_LIST](#html_elements_having_value_attribute_list)
  31. - [SVG_TAGS_LIST](#svg_tags_list)
  32. - [VOID_HTML_TAGS_LIST](#void_html_tags_list)
  33. - [HTML_TAGS_LIST](#html_tags_list)
  34. - [BOOLEAN_ATTRIBUTES_LIST](#boolean_attributes_list)
  35. - [HTML_TAGS_RE](#html_tags_re)
  36. - [SVG_TAGS_RE](#svg_tags_re)
  37. - [VOID_HTML_TAGS_RE](#void_html_tags_re)
  38. - [VOID_SVG_TAGS_RE](#void_svg_tags_re)
  39. - [HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_RE](#html_elements_having_value_attribute_re)
  40. - [BOOLEAN_ATTRIBUTES_RE](#boolean_attributes_re)
  41. - [isVoid](#isvoid)
  42. - [Parameters](#parameters)
  43. - [Examples](#examples)
  44. - [isHtml](#ishtml)
  45. - [Parameters](#parameters-1)
  46. - [Examples](#examples-1)
  47. - [isSvg](#issvg)
  48. - [Parameters](#parameters-2)
  49. - [Examples](#examples-2)
  50. - [isCustom](#iscustom)
  51. - [Parameters](#parameters-3)
  52. - [Examples](#examples-3)
  53. - [hasValueAttribute](#hasvalueattribute)
  54. - [Parameters](#parameters-4)
  55. - [Examples](#examples-4)
  56. - [isBoolAttribute](#isboolattribute)
  57. - [Parameters](#parameters-5)
  58. - [Examples](#examples-5)
  59. ### VOID_SVG_TAGS_LIST
  60. SVG void elements that cannot be auto-closed and shouldn't contain child nodes.
  61. Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
  62. ### HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_LIST
  63. List of html elements where the value attribute is allowed
  64. Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
  65. ### SVG_TAGS_LIST
  66. - **See: <https://github.com/wooorm/svg-tag-names>**
  67. List of all the available svg tags
  68. Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
  69. ### VOID_HTML_TAGS_LIST
  70. - **See: <http://www.w3.org/TR/html-markup/syntax.html#syntax-elements>**
  71. - **See: <http://www.w3.org/TR/html5/syntax.html#void-elements>**
  72. HTML void elements that cannot be auto-closed and shouldn't contain child nodes.
  73. Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
  74. ### HTML_TAGS_LIST
  75. - **See: <https://github.com/sindresorhus/html-tags>**
  76. List of all the html tags
  77. Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
  78. ### BOOLEAN_ATTRIBUTES_LIST
  79. - **See: <https://www.w3.org/TR/html5/infrastructure.html#sec-boolean-attributes>**
  80. List of all boolean HTML attributes
  81. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  82. ### HTML_TAGS_RE
  83. Regex matching all the html tags ignoring the cases
  84. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  85. ### SVG_TAGS_RE
  86. Regex matching all the svg tags ignoring the cases
  87. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  88. ### VOID_HTML_TAGS_RE
  89. Regex matching all the void html tags ignoring the cases
  90. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  91. ### VOID_SVG_TAGS_RE
  92. Regex matching all the void svg tags ignoring the cases
  93. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  94. ### HTML_ELEMENTS_HAVING_VALUE_ATTRIBUTE_RE
  95. Regex matching all the html tags where the value tag is allowed
  96. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  97. ### BOOLEAN_ATTRIBUTES_RE
  98. Regex matching all the boolean attributes
  99. Type: [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
  100. ### isVoid
  101. True if it's a self closing tag
  102. #### Parameters
  103. - `tag` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test tag
  104. #### Examples
  105. ```javascript
  106. isVoid('meta') // true
  107. isVoid('circle') // true
  108. isVoid('IMG') // true
  109. isVoid('div') // false
  110. isVoid('mask') // false
  111. ```
  112. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if void
  113. ### isHtml
  114. True if it's a known HTML tag
  115. #### Parameters
  116. - `tag` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test tag
  117. #### Examples
  118. ```javascript
  119. isHtml('img') // true
  120. isHtml('IMG') // true
  121. isHtml('Img') // true
  122. isHtml('path') // false
  123. ```
  124. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if html tag
  125. ### isSvg
  126. True if it's a known SVG tag
  127. #### Parameters
  128. - `tag` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test tag
  129. #### Examples
  130. ```javascript
  131. isSvg('g') // true
  132. isSvg('radialGradient') // true
  133. isSvg('radialgradient') // true
  134. isSvg('div') // false
  135. ```
  136. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if svg tag
  137. ### isCustom
  138. True if it's not SVG nor a HTML known tag
  139. #### Parameters
  140. - `tag` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test tag
  141. #### Examples
  142. ```javascript
  143. isCustom('my-component') // true
  144. isCustom('div') // false
  145. ```
  146. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if custom element
  147. ### hasValueAttribute
  148. True if the value attribute is allowed on this tag
  149. #### Parameters
  150. - `tag` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test tag
  151. #### Examples
  152. ```javascript
  153. hasValueAttribute('input') // true
  154. hasValueAttribute('div') // false
  155. ```
  156. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if the value attribute is allowed
  157. ### isBoolAttribute
  158. True if it's a boolean attribute
  159. #### Parameters
  160. - `attribute` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** test attribute
  161. #### Examples
  162. ```javascript
  163. isBoolAttribute('selected') // true
  164. isBoolAttribute('class') // false
  165. ```
  166. Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if the attribute is a boolean type