HtmlInstallation
Installation
Last updated:
Installation
npm install @visulima/htmlImport
Main Functions
import {
escapeHtml,
escapeCss,
escapeJs,
html,
css,
isValidCustomElementName,
} from "@visulima/html";Entity Encoding
import { encode, decode, decodeEntity } from "@visulima/html";HTML Processing
import { sanitizeHtml, stripHtml } from "@visulima/html";HTML Tag Lists
import { htmlTags, voidHtmlTags } from "@visulima/html";TypeScript Types
import type { Properties } from "@visulima/html"; // CSS properties typeRequirements
- Node.js: 22.13 or higher
- TypeScript: 5.0 or higher (if using TypeScript)
- ECMAScript: ES2020 or higher
Dependencies
The package includes:
- sanitize-html - HTML sanitization
- csstype - CSS property types for TypeScript autocomplete
Verification
Verify installation by running a simple example:
import { escapeHtml, sanitizeHtml } from "@visulima/html";
// Test escaping
console.log(escapeHtml('<script>test</script>'));
// => '<script>test</script>'
// Test sanitization
console.log(sanitizeHtml('<p>Hello <script>bad</script>World</p>'));
// => '<p>Hello World</p>'Browser Usage
For browser environments, import from the ESM bundle:
<script type="module">
import { escapeHtml } from "@visulima/html";
const safe = escapeHtml(userInput);
</script>Bundler Configuration
Vite
No special configuration needed:
// vite.config.ts
export default {
// @visulima/html works out of the box
};Webpack
Ensure proper ESM handling:
// webpack.config.js
module.exports = {
resolve: {
fullySpecified: false,
},
};