{"id":11053,"library":"html5-tag","title":"HTML5 Tag Generator","description":"html5-tag is a lightweight JavaScript utility designed for programmatically generating HTML5 tags and handling their attributes. Its primary function is to create HTML strings, correctly managing void elements (e.g., `<br>`, `<input>`) by omitting their closing tags, and automatically escaping attribute values to prevent XSS vulnerabilities. The current stable version is 0.3.0, released in 2016, indicating a very slow release cadence and likely an abandoned status. Unlike full-fledged templating engines or JSX, html5-tag focuses solely on simple string concatenation for server-side HTML generation, making it suitable for scenarios where a minimal, dependency-free solution for basic HTML element creation is preferred. A key differentiator is its automatic handling of attribute escaping and void elements, abstracting away common HTML syntax pitfalls.","status":"abandoned","version":"0.3.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/cheton/html5-tag","tags":["javascript","attr","attribute","attributes","element","elements","generate","html","html5"],"install":[{"cmd":"npm install html5-tag","lang":"bash","label":"npm"},{"cmd":"yarn add html5-tag","lang":"bash","label":"yarn"},{"cmd":"pnpm add html5-tag","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a default function for tag generation. Named imports will not work.","wrong":"import { tag } from 'html5-tag'","symbol":"tag","correct":"import tag from 'html5-tag'"},{"note":"For CommonJS environments, the default export is directly assigned to the require call.","symbol":"tag (CommonJS)","correct":"const tag = require('html5-tag');"}],"quickstart":{"code":"import tag from 'html5-tag';\n\n// Basic usage: tag name, attributes object, and child content\nconst link = tag('a', { href: 'https://example.com', target: '_blank' }, 'Visit Example');\nconsole.log(link);\n// Expected: <a href=\"https://example.com\" target=\"_blank\">Visit Example</a>\n\n// Void elements do not receive a closing tag\nconst linebreak = tag('br');\nconsole.log(linebreak);\n// Expected: <br>\n\n// Attributes are automatically escaped\nconst divWithTitle = tag('div', { title: 'It\\'s \"a\" test & <more>' }, 'Escaped Title');\nconsole.log(divWithTitle);\n// Expected: <div title=\"It&#39;&quot;a&quot; test &amp; &lt;more&gt;\">Escaped Title</div>\n\n// If tag is omitted, it defaults to 'div' (since v0.3.0)\nconst defaultDiv = tag({ class: 'container' }, 'Content goes here');\nconsole.log(defaultDiv);\n// Expected: <div class=\"container\">Content goes here</div>\n","lang":"javascript","description":"Demonstrates how to import and use the `tag` function to create various HTML elements, including void elements, attribute escaping, and the default 'div' behavior."},"warnings":[{"fix":"Consider more actively maintained alternatives for generating HTML, especially in new projects.","message":"The html5-tag package appears to be unmaintained. The last release (v0.3.0) was in 2016. It may lack updates for modern web standards, security patches, or compatibility with newer JavaScript ecosystems.","severity":"gotcha","affected_versions":"<=0.3.0"},{"fix":"Ensure you always provide the desired tag name as the first argument, or explicitly rely on the 'div' default if that is the intended behavior. For example, `tag({ class: 'my-class' }, 'Content')` now yields `<div>` instead of potentially throwing an error or having different behavior in older versions.","message":"Starting with version 0.3.0, the `tag` function defaults to generating a `div` element if the tag name is not explicitly provided as the first argument.","severity":"breaking","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to use a default import: `import tag from 'html5-tag';`.","cause":"Attempting to use a named import (`import { tag } from 'html5-tag';`) when the library only provides a default export.","error":"TypeError: html5_tag_1.tag is not a function"},{"fix":"Ensure the CommonJS import is `const tag = require('html5-tag');` to correctly capture the default exported function.","cause":"This error can occur in CommonJS environments if `require('html5-tag')` is not assigned correctly, or if `exports.default` is accessed directly after `require()`, often when mixing ESM import syntax with CJS usage.","error":"TypeError: Cannot read properties of undefined (reading 'call')"}],"ecosystem":"npm"}