Nuanced Pumpkin Mavens

    get-tag
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.4 • Public • Published

    get-tag

    Create HTML tag strings on the fly.

    Installation

    Install the package from npm:

    npm install get-tag

    Usage

    const getTag = require("get-tag");
    
    getTag("title", "Some Title");
    // <title>Some Title</title>
    
    getTag("a", "Some Link", {href: "foo.com"});
    // <a href="foo.com">Some link</a>
    
    getTag("meta", null, {name: "author", content: "foo"});
    // <meta name="author" content="foo">

    Details

    If the provided HTML tag name is included in the void-elements list, then selfClosing will default to true.

    /**
     * @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.
     */
    getTag(tag, textContent, attributes, selfClosing);

    License

    MIT

    Related projects

    Install

    npm i get-tag

    DownloadsWeekly Downloads

    108

    Version

    0.1.4

    License

    MIT

    Unpacked Size

    5.32 kB

    Total Files

    5

    Last publish

    Collaborators

    • tannerdolby