Installation

Last updated:

Installation

npm install @visulima/html

Import

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 type

Requirements

  • 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>'));
// => '&lt;script>test&lt;/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,
    },
};
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues