common-tags
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Common-tags is a set of well-tested, commonly used template literal tag functions designed for use in ES2015+. This node.js module provides utility template tags for easier and cleaner manipulation of JavaScript template literals. It includes tags for actions like removing line breaks or excess white space, changing case, and even safe HTML escaping. It is especially useful when dealing with Multi-line strings or when you want to create your own template tags.
Using common-tags is straightforward and involves importing the tags you need from the package and using them as template tags. Here is an example of how you would use the html
tag:
import { html } from 'common-tags';
let user = { name: 'John Doe' };
let output = html`
<div id="user-card">
<h2>${user.name}</h2>
</div>
`;
console.log(output);
In this example, the html
tag is imported from the 'common-tags' module and used as a template literal tag. This formats the resulting string by correctly indenting it.
The documentation for common-tags is located on the project's GitHub page: https://github.com/zspecza/common-tags. The detailed documentation includes usage examples, means of importing, and available tags description. The repository's README page also provides detail on advanced usage and additional ES2015 template tag modules.