Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bad-words-next

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bad-words-next

JavaScript/TypeScript filter and checker for bad words aka profanity

  • 1.2.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-13.09%
Maintainers
1
Weekly downloads
 
Created
Source

bad-words-next

workflows-nodejs-ci workflows-wiki-doc 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`

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
}

interface Lookalike {
  [key: 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 '***'
  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']
  maxCacheSize?: number // Max items to store in cache - default 100
}

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

Keywords

FAQs

Package last updated on 03 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc