Zero dependency profanity detector.

Overview

@cnakazawa/profane

Zero dependency profanity detector based on Swearjar and Profane.

Note: Some examples may contain offensive language for illustration purposes.

install

npm install @cnakazawa/profane

Usage

new Profane(options?)

Create a new instance:

import Profane from 'profane';

const profane = new Profane();

check(text: string): boolean

Check if a text matches the word list:

profance.check('Hell no'); // true
profance.check('H3ll no'); // true
profane.check('Banana Banana Banana'); // false

censor(censored: string, replacement?: string): string;

Censor words matching the word list:

profane.censor('Hell no'); // '**** no'
profane.censor('Hell no', '•'); // '•••• no'

getWordFrequencies(text: string): Record<string, number>;

Get the word frequencies of words matching the word list:

```js
const frequencies = profane.getWordFrequencies('horniest hornet fart');
{
  "horniest": 1,
  "fart": 1
}

getCategoryFrequencies(text: string): Record<string, number>;

Get the category frequencies of words matching the word list:

const frequencies = profane.getCategoryFrequencies('horniest hornet fart');
{
  "inappropriate": 1,
  "sexual": 1
}

Options

words: Record<string, ReadonlyArray<string>>

You can configure your Profane instance with a custom word list by supplying an object with word definitions:

const profane = new Profane({
  words: {
    happy: ['inappropriate'],
    awesome: ['elated'],
  },
});

profane.check('Mr. Happy is awesome'); // true
profane.getCategoryFrequencies('Mr. Happy is awesome'); // {inappropriate: 1, elated: 1}

You can receive a copy of the word list through the getWordList() function:

import {getWordList} from '@cnakazawa/profane';

getWordList(); // Record<string, ReadonlyArray<string>>

normalize?: boolean

Determines whether to normalize Leet or not. Defaults to true'.

new Profane({normalize: false}).check('H3ll'); // false
new Profane({normalize: true}).check('H3ll'); // true

wholeWordsOnly?: boolean

Whether to match only on whole words or not. Defaults to false'.

new Profane({wholeWordsOnly: false}).check('shell'); // true
new Profane({wholeWordsOnly: true}).check('shell'); // false

Updates to the word list

The default word list was lifted from Swearjar and may be out-of-date. Please feel free to send Pull Requests with new and updated definitions.

You might also like...

DOM ViewModel - A thin, fast, dependency-free vdom view layer

DOM ViewModel - A thin, fast, dependency-free vdom view layer

domvm (DOM ViewModel) A thin, fast, dependency-free vdom view layer (MIT Licensed) Introduction domvm is a flexible, pure-js view layer for building h

Dec 8, 2022

A simpliest DI(Dependency Injection) example

di-example A simpliest DI(Dependency Injection) example showing how dependency injection actually works. How to Run Install dependency with your favor

Dec 6, 2022

Simple, fast, accessible accordion library with no dependency

Simple, fast, accessible accordion library with no dependency

React Fast Accordion ⚡️ Dynamic, fast, accessible & zero dependency accordion for React How it's fast? Instead of adding event listener on all the ite

Oct 8, 2022

Small, typed, dependency free tool to round corners of 2d-polygon provided by an array of { x, y } points.

Small, typed, dependency free tool to round corners of 2d-polygon provided by an array of { x, y } points.

round-polygon Small, typed, dependency-free tool to round corners of 2d-polygon provided by an array of { x, y } points. The algorithm prevents roundi

Nov 26, 2022

A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Nov 12, 2022

Calculates dependencies for a Go build-target and submits the list to the Dependency Submission API

Go Dependency Submission This GitHub Action calculates dependencies for a Go build-target (a Go file with a main function) and submits the list to the

Dec 7, 2022

Fixes code dependency issues 🤼‍♀️

Codependence 🤼‍♀️ Codependence is a JavaScript utility CLI or node tool for checking specified dependencies in a project to ensure dependencies are u

Dec 15, 2022

A TypeScript library for creating dependency snapshots.

Dependency Submission Toolkit @github/dependency-submission-toolkit is a TypeScript library for creating dependency snapshots and submitting them to t

Nov 22, 2022

Easily create key board shortcuts for your JS functions. Built using JS only with no other dependency. Inspired from MacOS spotlight

floodlightjs Inspired from macOS spotlight, floodlight is simple JS library that will show a search area. How the search is handled is completely on y

Aug 12, 2022
Releases(v1.0.0)
  • v1.0.0(Jul 22, 2022)

    Initial release. Improvements over the existing libraries:

    • Added TypeScript support.
    • Improved API and code quality.
    • Significantly reduced code size.

    Install

    npm install profane
    
    Source code(tar.gz)
    Source code(zip)
Owner
Christoph Nakazawa
Engineering Manager. Built Jest, Metro, Yarn and MooTools.
Christoph Nakazawa
A lightweight Adobe Photoshop .psd/.psb file parser in typescript with zero-dependency for WebBrowser and NodeJS

@webtoon/psd A lightweight Adobe Photoshop .psd/.psb file parser in typescript with zero-dependency for WebBrowser and NodeJS Browser Support Chrome F

null 830 Jan 1, 2023
Dynamic, fast, accessible & zero dependency accordion for React

React Fast Accordion ⚡️ Dynamic, fast, accessible & zero dependency accordion for React How it's fast? Instead of adding event listener on all the ite

Shivam 59 Oct 8, 2022
A zero-dependency, buildless, terse, and type-safe way to write HTML in JavaScript.

hdot A sensible way to write HTML in JavaScript. Type-safe. Helps you follow the HTML spec. Terse. Almost character for character with plain HTML. Bui

Will Martin 31 Oct 24, 2022
Shifty is a tiny zero-dependency secrets generator, built for the web using TypeScript.

Shifty is a tiny zero-dependency secrets generator, built for the web using TypeScript. Installation yarn add @deepsource/shifty Usage Shifty is built

DeepSource 46 Nov 24, 2022
Jsonup - This is a zero dependency compile-time JSON parser written in TypeScript

jsonup This is a zero dependency compile-time JSON parser written in TypeScript.

TANIGUCHI Masaya 39 Dec 8, 2022
A zero-dependency, strongly-typed web framework for Bun, Node and Cloudflare workers

nbit A simple, declarative, type-safe way to build web services and REST APIs for Bun, Node and Cloudflare Workers. Examples See some quick examples b

Simon Sturmer 16 Sep 16, 2022
Zero Dependency, Vanilla JavaScript Tag Editor

_____ |_ _|___ ___ ___ ___ ___ | | | .'| . | . | -_| _| |_| |__,|_ |_ |___|_| |___|___| version 0.4.4 Tagger: Zero dependenc

Jakub T. Jankiewicz 155 Nov 25, 2022
Zero Two Bot,A fully Modular Whatsapp Bot to do everything possible in WhatsApp by Team Zero Two

?? ???????? ?????? ???? ?? A Moduler WhatsApp Bot designed for both PM and Groups - To take your boring WhatsApp usage into a whole different level. T

Sam Pandey 69 Dec 25, 2022
Multiplies a number by zero. Useful for when you need to multiply a number by zero

multiply-by-zero Multiplies a number by zero. Useful for when you need to multiply a number by zero Please consider checking out the links of this pro

Dheirya Tyagi 2 Jul 3, 2022
a lightweight, dependency-free JavaScript plugin which makes a HTML table interactive

JSTable The JSTable is a lightweight, dependency-free JavaScript plugin which makes a HTML table interactive. The plugin is similar to the jQuery data

null 63 Oct 20, 2022