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 🙏

© 2025 – Pkg Stats / Ryan Hefner

kata-kasar

v1.0.2

Published

Filter badwords in Bahasa and English words

Readme

kata-kasar

A powerful, lightweight, and multilingual library to filter, censor, and detect profanity (bad words) in text. Primarily designed for Bahasa Indonesia and English, it supports fuzzy matching, leetspeak detection, and dynamic dictionary management.

Features

  • Multilingual Support: Built-in support for Indonesian and English dictionaries.
  • Leetspeak Detection: Automatically normalizes and detects leetspeak (e.g., 4njing, sh1t).
  • Fuzzy Matching: Uses Damerau-Levenshtein distance to detect typos or deliberate misspellings.
  • Detailed Analysis: Get comprehensive details about detected words, including confidence levels and match categories.
  • Dictionary Management: Add, remove, or override usage dictionaries dynamically at runtime.
  • TypeScript Support: Fully typed for better developer experience.

Installation

npm install kata-kasar

Usage

Basic Usage

import { analyze, censor, flag } from "kata-kasar";

// 1. Analyze text (Recommended)
const result = analyze("Dasar lo anjing!");
console.log(result);
/*
{
  original: "Dasar lo anjing!",
  filtered: "Dasar lo ******!",
  isProfane: true,
  decision: "CENSOR",
  data: [ ... ]
}
*/

// 2. Simple Boolean Check
const isBad = flag("This is shit"); // true

// 3. Censor Text
const clean = censor("Dasar lo anjing"); // "Dasar lo ******"

API Reference

Core Functions

analyze(text: string, options?: AnalyzeOptions): AnalyzeResult

The most robust function in the library. It performs validation, normalization, tokenization, and fuzzy detection against the blacklist and whitelist.

Options:

  • type: 'username' | 'text' (default: 'text')
  • threshold: number (default: 3) - Maximum edit distance for fuzzy matching.

Returns an AnalyzeResult object containing:

  • original: Input text.
  • filtered: Text with profanity masked.
  • isProfane: Boolean indicating if profanity was found.
  • decision: 'CENSOR' | 'ALLOW'.
  • data: Array of detailed matches.

censor(text: string, replacement?: string): string

Replaces bad words in the text.

  • replacement: defaults to "***", but can be a single character like * to mask each character.

flag(text: string): boolean

Returns true if the text contains any bad words.

filter(text: string): string

Removes bad words from the text completely.

extract(text: string): string[]

Returns an array of all bad words found in the text.

Note: Methods like leetCensor, leetFlag, leetFilter, and leetExtract are also available. These normalize the input (convert leetspeak) before processing, referring to the normalized text in their output.

Dictionary Management

You can modify the blacklist and whitelist at runtime. Functions support a lang parameter (e.g., 'id', 'en') to target specific dictionaries.

import { addBlacklist, removeBlacklist, addWhitelist } from "kata-kasar";

// Add specific words to the Indonesian blacklist
addBlacklist(["krupuk", "seblak"], "id");

// Remove words from the English blacklist
removeBlacklist("hell", "en");

// Add words to the whitelist (bypass checks)
addWhitelist(["hello", "analysis"], "en");

Fuzzy Utilities

Exposed for cases where you need raw string comparison.

import { distance, similarity } from "kata-kasar";

// Damerau-Levenshtein distance
const dist = distance("kitten", "sitten"); // 1

// Cosine similarity
const sim = similarity("hello", "hello world"); // 0.7...

License

MIT License