npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

i18next-dompurify-postprocessor

v1.0.3

Published

This is a postprocessor for the i18next internationalization framework that integrates with the DOMPurify library. It provides a post-processing functionality to sanitize HTML content in translations using DOMPurify.

Downloads

6

Readme

i18next DOMPurify Postprocessor

This is a postprocessor for the i18next internationalization framework that integrates with the DOMPurify library. It provides a post-processing functionality to sanitize HTML content in translations using DOMPurify.

Installation

You can install the i18next DOMPurify plugin via npm:

npm install i18next-dompurify-plugin

Usage

To use the i18next DOMPurify plugin, you need to import it and initialize it alongside your i18next configuration.

import i18next from 'i18next';
import dompurify from 'i18next-dompurify-postprocessor';

// (Optional) Change the settings passed to DOMPurify
// the below settings are the default ones
dompurify.setOptions({
  ALLOWED_TAGS: ['a', 'b', 'br', 'code', 'em', 'i', 'li', 'ol', 'p', 'strong', 'ul', 'h1', 'h2', 'h3'],
  ALLOWED_ATTR: ['style', 'class']
});

// Import and initialize the plugin
i18next.use(dompurify);

// Configure i18next as usual
i18next.init({
    // ...
    postProcess: ['dompurify'], // Only if you want to use the plugin globally
});

Options

The plugin provides options to customize the sanitization process. By default, the following options are set:

{
  ALLOWED_TAGS: ['a', 'b', 'br', 'code', 'em', 'i', 'li', 'ol', 'p', 'strong', 'ul'],
  ALLOWED_ATTR: ['style']
}

To modify these options, you can call the setOptions method on the plugin instance before initializing i18next:

dompurify.setOptions({
  ALLOWED_TAGS: ['a', 'b', 'br', 'code', 'em', 'i', 'li', 'ol', 'p', 'strong', 'ul', 'h1', 'h2', 'h3'],
  ALLOWED_ATTR: ['style', 'class']
});

Example

Once the plugin is set up, you can use i18next as usual. Depending on if you configured i18next to use the postprocessor as a global plugin, the translations will be automatically sanitized by DOMPurify.

If you want to use the plugin only for specific translations, you can pass the postProcess option to the t function

i18next.t('keyWithHTML', { postProcess: 'dompurify' });

Please note that this plugin should be used with caution to prevent any potential security vulnerabilities. Make sure to review and customize the allowed tags and attributes according to your specific needs.

License

This plugin is released under the MIT License.