JSPM

@stalepretzels/bartender

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q10611F
  • License MIT

bindings to rustrict

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stalepretzels/bartender) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Bartender

    .github/workflows/release.yml npmpkg

    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:

    Features
    • 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 &str or Iterator<Item = char>
      • Can track per-user state with context feature
      • Can add words with the customize feature
      • Accurately reports the width of Unicode via the width feature
      • Plenty of options
    • Performant
      • O(n) analysis and censoring
      • No regex (uses custom trie)
      • 3 MB/s in release mode
      • 100 KB/s in debug mode

    Limitations

    This is handicapped by everything the original was:

    Limitations
    • 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") // -> true

    Type 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"); // -> true

    Roadmap

    1. Add custom words and censors
    2. Implement context feature
    3. Array iterators