JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 356116
  • Score
    100M100P100Q166387F
  • License MIT

Generate HTML elements from a javascript object.

Package Exports

  • html-tag

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-tag) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

html-tag NPM version NPM monthly downloads NPM total downloads Linux Build Status

Generate HTML elements from a javascript object.

Install

Install with npm:

$ npm install --save html-tag

Originally inspired by an HTML helper in hexo by Tommy Chen.

Usage

var tag = require('html-tag');
tag(name[, attribs, text]);

Params

  • tag {String}: Name of the tag to create.
  • attribs {Object}: Optional attributes
  • text {String|Boolean}: Optional text
  • returns {String}: string of HTML

Examples

console.log(tag('a', {href: 'https://sellside.com'}, 'Sellside'));
//=> <a href="https://sellside.com">Sellside</a>

console.log(tag('a', {id: 'anchor'}));
//=> <a id="anchor"></a>

console.log(tag('strong', 'Let\'s dance!'));
//=> <strong>Let's dance</strong>

console.log(tag('div'));
//=> <div></div>

Void elements (self-closing tags)

console.log(tag('img', {src: 'foo.jpg'}));
//=> <img src="foo.jpg">

console.log(tag('br'));
//=> <br>

console.log(tag('br', '\nfoo'));
//=> <br>\nfoo

Boolean attributes

Boolean attributes are defined by defining the attribute with a boolean value (strictly true or strictly false)

console.log(tag('details', {open: true}));
//=> <details open></details>

console.log(tag('details', {open: false}));
//=> <details></details>

console.log(tag('details', {open: 'false'}));
//=> <details open="false"></details>

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.3.0, on January 08, 2017.