cosmic-dust-sanitizer

1.0.3 • Public • Published

cosmic-dust-sanitizer

cosmic-dust-sanitizer is a JavaScript library for sanitizing HTML content using popular sanitization libraries like sanitize-html and xss.

Installation

npm install cosmic-dust-sanitizer

Usage

const CosmicDustSanitizer = require('cosmic-dust-sanitizer');

// Create an instance of CosmicDustSanitizer
const sanitizer = new CosmicDustSanitizer();

// Sanitize HTML using sanitize-html library
const sanitizedHtmlWithSanitizeHtml = sanitizer.sanitizeWithSanitizeHtml('<p>Hello <script>alert("world")</script></p>');

// Sanitize HTML using xss library
const sanitizedHtmlWithXss = sanitizer.sanitizeWithXss('<p>Hello <script>alert("world")</script></p>');

API

new CosmicDustSanitizer(options)

Creates a new instance of CosmicDustSanitizer with optional options object.

  • options (Object): Optional configuration options.

sanitizeWithSanitizeHtml(html)

Sanitizes HTML content using the sanitize-html library.

  • html (String): The HTML content to be sanitized.

Returns the sanitized HTML.

sanitizeWithXss(html)

Sanitizes HTML content using the xss library.

  • html (String): The HTML content to be sanitized.

Returns the sanitized HTML.

Example

const CosmicDustSanitizer = require('cosmic-dust-sanitizer');

// Create an instance of CosmicDustSanitizer with options
const sanitizer = new CosmicDustSanitizer({
allowedTags: ['p', 'a', 'b', 'i']
});

// Sanitize HTML using sanitize-html library
const sanitizedHtmlWithSanitizeHtml = sanitizer.sanitizeWithSanitizeHtml('<p>Hello <script>alert("world")</script></p>');

// Sanitize HTML using xss library
const sanitizedHtmlWithXss = sanitizer.sanitizeWithXss('<p>Hello <script>alert("world")</script></p>');

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i cosmic-dust-sanitizer

Weekly Downloads

4

Version

1.0.3

License

MIT

Unpacked Size

4.04 kB

Total Files

5

Last publish

Collaborators

  • antonioio