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

bad-words-next

v2.3.1

Published

JavaScript/TypeScript filter and checker for bad words aka profanity

Downloads

9,800

Readme

bad-words-next

workflows-nodejs-ci npm version NPM license npm bundle size npm downloads

JavaScript/TypeScript filter and checker for bad words aka profanity.

API documentation in GitHub Wiki.

Install

yarn add bad-words-next

or

npm install bad-words-next

Basic usage

const BadWordsNext = require('bad-words-next')
const en = require('bad-words-next/data/en.json')

const badwords = new BadWordsNext({ data: en })

// Returns true when passed string contains a bad word
console.log(badwords.check('S0me sh!tt is here'))
// will print `true`

// Returns filtered string with masked bad words
console.log(badwords.filter('S0me sh!tt is here'))
// will print `S0me *** is here`

// Returns filtered string and catches bad words
badwords.filter('S0me sh!tt is here', badword => {
  console.log(badword)
})
// will print `sh!tt`

// Use exclusions
const badwords = new BadWordsNext({ data: en, exclusions: ['sh+it+' /*works with lookalikes or the actual words*/] })
console.log(badwords.filter('S0me sh!tt is here'))
// will keep the `sh!tt` word

Add more dictionaries

const BadWordsNext = require('bad-words-next')

const en = require('bad-words-next/data/en.json')
const es = require('bad-words-next/data/es.json')
const fr = require('bad-words-next/data/fr.json')
const de = require('bad-words-next/data/de.json')
const ru = require('bad-words-next/data/ru.json')
const rl = require('bad-words-next/data/ru_lat.json')
const ua = require('bad-words-next/data/ua.json')
const pl = require('bad-words-next/data/pl.json')
const ch = require('bad-words-next/data/ch.json')

const badwords = new BadWordsNext()
badwords.add(en)
badwords.add(es)
badwords.add(fr)
badwords.add(de)
badwords.add(ru)
badwords.add(rl)
badwords.add(ua)
badwords.add(pl)
badwords.add(ch)

Dictionary files format

interface Data {
  id: string  // Unique dictionary ID
  words: string[] // Words list
  lookalike: Lookalike // Lookalike homoglyphs map
}

type Lookalike = Record<string | number, string> // Simple key-value object

You can use the following pattern characters in a word string:

  • * indicates any characters, use it only on start and/or end of a word
  • + indicates one or more repeating characters
  • _ indicates special characters

Options

interface Options {
  data?: Data // Dictionary data
  placeholder?: string // Filter placeholder - default '***'
  placeholderMode?: 'repeat' | 'replace' // Placeholder mode to either replace with or repeat the placeholder - default 'replace'
  specialChars?: RegExp // Special chars to allow on start and/or end of a word - default /\d|[!@#$%^&*()[\];:'",.?\-_=+~`|]|a|(?:the)|(?:el)|(?:la)/
  spaceChars?: string[] // Pseudo space chars, a list of values for `_` symbol in a dictionary word string - default ['', '.', '-', ';', '|']
  confusables?: string[] // List of ids to apply transformations from `confusables` npm package - default ['en', 'es', 'de', 'ru_lat']
  maxCacheSize?: number // Max items to store in cache - default 100
  exclusions?: string[] // The list of exclusions
}

See Options API for more details.

Notes

  • Dictionary words with spaces won't work b/c they do not represent a single word

  • Dictionaries have to be improved over time