Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-tag

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-tag - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

6

dist/get-tag.d.ts

@@ -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 @@ */

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