common-tags provides a collection of reusable template literal tag functions for JavaScript (ES2015+). These tags offer functionalities like HTML escaping (`html`, `safeHtml`), string stripping and indentation (`stripIndent`, `oneLine`), and list formatting (`commaLists`, `inlineLists`). The current stable version is 1.8.2. While there's a pre-release v2.0.0-alpha.1 hinting at future TypeScript adoption and documentation rewrite, the package has a relatively stable, though not very frequent, release cadence for major features, with minor patches addressing bugs or internal tooling. It differentiates itself by offering a robust, well-tested set of common string manipulation utilities often needed when working with template literals, particularly for generating clean, formatted output like HTML or SQL, without the overhead of larger templating engines. It also provides an API for creating custom tags, emphasizing modularity and extensibility for custom text processing scenarios. Since version 1.8.0, it is entirely dependency-free, making it a lightweight choice for modern JavaScript projects.
npm install common-tagsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates the use of `html` for basic templating with variable interpolation, `stripIndent` for cleaning up multiline strings, and `oneLine` for condensing strings to a single line, showcasing common use cases for the library's tags.
Explicitly call functions passed as arguments within your custom `TemplateTag` implementation if you relied on the previous automatic function detection and execution.
Ensure all references to the `common-tags` repository, especially in package managers or CI/CD configurations, point to `https://github.com/zspecza/common-tags`.
Upgrade to `common-tags@1.8.0` or higher to ensure correct `valueOf` and `toString` call order, aligning with JavaScript specification.
Ensure you are using named imports: `import { html } from 'common-tags';`. For CommonJS, use `const { html } = require('common-tags');`. Verify your TypeScript `tsconfig.json` includes `"esModuleInterop": true` if using mixed module types.Add the necessary import statement at the top of your file: `import { html } from 'common-tags';` for ES Modules or `const { html } = require('common-tags');` for CommonJS.Always use template tag functions by preceding a template literal with the tag's name: `html`<div>Hello</div>`.
No dependency data recorded yet.