Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzel committed Sep 17, 2022
0 parents commit cd4613e
Show file tree
Hide file tree
Showing 19 changed files with 5,568 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": ["standard-with-typescript"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": './tsconfig.json'
}
}
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.vs
.vscode

.DS_Store

.node_history
*.log
.cache

pids
*.pid
*.seed

node_modules
public
build
dist
lib
tmp

.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Alex Zelensky

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# bad-words-next

Profanity filtering and detection.

Started as a quick overnight project. Feel free to contribute.

## Install

```sh
yarn add bad-words-next
```

or

```sh
npm install bad-words-next
```

## Basic usage

```js
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

```sh
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

```ts
interface Data {
id: string // unique ID
words: string[] // words list, supports `*` on start and end of a string to indicate any characters, also `+` for one or more repeating characters, and `_` for special characters.
lookalike: Lookalike // map for homoglyphs conversion
}

interface Lookalike {
[key: string | number]: string // just a simple key-value object
}
```

## Options

```ts
interface Options {
data?: Data // Dictionary data
placeholder?: string // Filter placeholder - default value '***'
specialChars?: RegExp // Special chars to allow on word start and word end - default value /\d|[!@#$%^&*()[\];:'",.?\-_=+~`|]|a|(?:the)|(?:el)|(?:la)/
spaceChars?: string[] // Pseudo space chars, a list of values for `_` symbol in a dictionary word string - default value ['', '.', '-', '_', ';', '|']
confusables?: string[] // List of ids to apply transformations from `confusables` npm package - default ['en', 'es', 'de']
}
```

## Notes

- Filtering may be potentially slow on large strings and large dictionaries

- Dictionary words with spaces won't work

- Dictionaries have to be improved over time
28 changes: 28 additions & 0 deletions data/ch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"id": "ch",
"words": [
"*屌*",
"*鸡巴*",
"*傻瓜*",
"*屄*",
"*屁股*",
"*肏你*",
"*狗屁*",
"*婊子*",
"*色鬼*",
"*王八*",
"*混蛋*",
"*妓*",
"*屁眼*",
"*幹*",
"*操你*",
"*狗日*",
"*白癡*",
"*糞*",
"*老母*",
"*肏*",
"*雞*巴"
],
"lookalike": {
}
}
46 changes: 46 additions & 0 deletions data/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "de",
"words": [
"analritt+er",
"arsch*",
"ficken",
"fotze",
"kacke",
"kacken",
"kackwurst",
"kampflesbe",
"lümmel",
"möpse",
"möse",
"neger",
"nippel",
"nutte",
"onanieren",
"orgasmus",
"scheiss+er",
"scheiße",
"schiess+er",
"schlampe",
"schwanzlutscher",
"titt+chen",
"titt+en",
"vollpfosten",
"vögeln",
"wichse",
"wichsen",
"wichser"
],
"lookalike": {
"$": "s",
"@": "a",
"<": "c",
"!": "i",
"+": "t",
"0": "o",
"1": "i",
"2": "z",
"3": "z",
"5": "s",
"8": "b"
}
}
Loading

0 comments on commit cd4613e

Please sign in to comment.