Comparing version 0.1.2 to 0.1.3
@@ -9,6 +9,6 @@ declare type Attributes = { | ||
* @param {string} textContent Text content for the element. | ||
* @param {Attributes} attributes Object representing attribute key/value pairs. | ||
* @param {boolean} selfClosing Boolean representing a self closing element. Default: false | ||
* @param {Object} attributes Object representing attribute key/value pairs. | ||
* @param {boolean} selfClosing Boolean representing a self closing element. Default: false (or true if `tag` is a known [void-element](https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-elements)) | ||
* @return {string} A string representing the constructed HTML element. | ||
*/ | ||
declare function getTag(tag: string, textContent: string, attributes: Attributes | undefined, isSelfClosing?: boolean): string; | ||
declare function getTag(tag: string, textContent: string, attributes: Attributes | undefined, selfClosing?: boolean): string; |
@@ -10,11 +10,11 @@ "use strict"; | ||
* @param {string} textContent Text content for the element. | ||
* @param {Attributes} attributes Object representing attribute key/value pairs. | ||
* @param {boolean} selfClosing Boolean representing a self closing element. Default: false | ||
* @param {Object} attributes Object representing attribute key/value pairs. | ||
* @param {boolean} selfClosing Boolean representing a self closing element. Default: false (or true if `tag` is a known [void-element](https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-elements)) | ||
* @return {string} A string representing the constructed HTML element. | ||
*/ | ||
function getTag(tag, textContent, attributes, isSelfClosing = false) { | ||
function getTag(tag, textContent, attributes, selfClosing = false) { | ||
const selfClosingTags = ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]; | ||
let fields = ""; | ||
tag = tag.toLowerCase(); | ||
const selfClosing = selfClosingTags.includes(tag) || isSelfClosing; | ||
let fields = ""; | ||
selfClosing = selfClosingTags.includes(tag) || selfClosing; | ||
if (attributes && typeof attributes == "object" && Object.keys(attributes).length > 0) { | ||
@@ -21,0 +21,0 @@ for (const key in attributes) { |
{ | ||
"name": "get-tag", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Create HTML tag strings on the fly.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/get-tag.js", |
@@ -5,3 +5,3 @@ # get-tag | ||
## Installation | ||
Install the plugin from [npm](https://www.npmjs.com/package/get-tag): | ||
Install the package from [npm](https://www.npmjs.com/package/get-tag): | ||
@@ -27,8 +27,10 @@ ```bash | ||
### Details | ||
If the provided HTML tag name `tag` is apart of the [void-elements](https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-elements) list, then `selfClosing` will default to `true`. | ||
```js | ||
/** | ||
* @param {string} tag HTML tag name. | ||
* @param {string} textContent Text content for the element. | ||
* @param {Attributes} attributes Object representing attribute key/value pairs. | ||
* @param {boolean} selfClosing Boolean representing a self closing element. Default: false | ||
* @param {string} `tag` HTML tag name. | ||
* @param {string} `textContent` Text content for the element. | ||
* @param {Attributes} `attributes` Object representing attribute key/value pairs. | ||
* @param {boolean} `selfClosing` Boolean representing a self closing element. Default: false. (Or true if `tag` is a known void-element defined in the HTML spec) | ||
* @return {string} A string representing the constructed HTML element. | ||
@@ -35,0 +37,0 @@ */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5322
43