0.1.2 • Published 2 years ago
@stalepretzels/bartender v0.1.2
Bartender
Node.js bindings for the rustrict crate.
NOTE: rustrict was made by @finnbear, and not me! I am simply making bindings to it! Please check out his original project.
How capable is this library?
Since it's based off of rustrict, it has every capability of the rust crate! Here's what the original can do:
- Multiple types (profane, offensive, sexual, mean, spam)
- Multiple levels (mild, moderate, severe)
- Resistant to evasion
- Alternative spellings (like "fck")
- Repeated characters (like "craaaap")
- Confusable characters (like 'ᑭ', '𝕡', and '🅿')
- Spacing (like "c r_a-p")
- Accents (like "pÓöp")
- Bidirectional Unicode (related reading)
- Self-censoring (like "f*ck")
- Safe phrase list for known bad actors]
- Censors invalid Unicode characters
- Battle-tested in Mk48.io
- Resistant to false positives
- One word (like "assassin")
- Two words (like "push it")
- Flexible
- Censor and/or analyze
- Input
&strorIterator<Item = char> - Can track per-user state with
contextfeature - Can add words with the
customizefeature - Accurately reports the width of Unicode via the
widthfeature - Plenty of options
- Performant
- O(n) analysis and censoring
- No
regex(uses custom trie) - 3 MB/s in
releasemode - 100 KB/s in
debugmode
Limitations
This is handicapped by everything the original was:
- Mostly English/emoji
- Censoring removes most diacritics (accents)
- Does not detect right-to-left profanity while analyzing, so...
- Censoring forces Unicode to be left-to-right
- Doesn't understand context
- Not resistant to false positives affecting profanities added at runtime
How do I use this?
Simple! Just alias (or import) Bartender at the beginning of the your .js file to begin!
let bartender = require('@stalepretzels/bartender'); // commonjs require
import * as bartender from '@stalepretzels/bartender'; // esm import
// Simply remove `bartender.` from the beginning of the code if you plan on importing functions by themselves. Censor and check for profanity:
// censor(input: String) -> String
// is_inappropriate(input: String) -> bool
bartender.censor("hello crap") // -> "hello c***"
bartender.is_inappropriate("f u c k") // -> trueType match strings:
// is(input: String, filter_input: String) -> bool
// isnt(input: String, filter_input: String) -> bool
bartender.is("pron", "evasive"); // -> true
bartender.isnt("porn", "evasive"); // -> true
bartender.is("Hello there!", "safe"); // -> true
bartender.is("nice work.", "safe"); // -> true
bartender.is("yes", "safe"); // -> true
bartender.is("NVM", "safe"); // -> true
bartender.is("gtg", "safe"); // -> true
bartender.isnt("not a common phrase", "safe"); // -> trueRoadmap
- Add custom words and censors
- Implement
contextfeature - Array iterators