Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/y-gagar1n/nanoid-good
Obscene words filter for nanoid
https://github.com/y-gagar1n/nanoid-good
Last synced: 3 months ago
JSON representation
Obscene words filter for nanoid
- Host: GitHub
- URL: https://github.com/y-gagar1n/nanoid-good
- Owner: y-gagar1n
- License: mit
- Created: 2018-07-14T11:52:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T07:39:04.000Z (almost 2 years ago)
- Last Synced: 2024-07-18T15:29:57.986Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.28 MB
- Stars: 82
- Watchers: 2
- Forks: 5
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nanoid-good
Guarantees you will not get any obscene words or other profanity in your ids generated by [Nano ID](https://github.com/ai/nanoid).
This is a drop-in replacement for **Nano ID** which means you can just change the name of imported package from `nanoid` to `nanoid-good`.
## How it works
It checks every generated ID through a vocabulary of obscene words. If any match is found, then ID is generated again and again until it gets clean ID which is returned.
It finds bad words with mixed registry and words which are hidden in between other letters.
For example:
`Uakgb_J5m9g~0JDMpoRnqLJ`
This one will be considered a bad word because of `poRn` hidden near the end.
## Installation
```shell
npm install nanoid-good
```## Usage
```js
var en = require("nanoid-good/locale/en"); // you should add locale of your preferred language
var nanoid = require("nanoid-good").nanoid(en);
var id = nanoid(); //=> "V1StGXR8_Z5jdHi6B~myT"
```You can also use several locales:
```js
var en = require("nanoid-good/locale/en");
var ru = require("nanoid-good/locale/ru");
var nanoid = require("nanoid-good").nanoid(en, ru);
```All additional functions of **Nano ID** are supported too:
```js
var en = require("nanoid-good/locale/en");
var customRandom = require("nanoid-good").customRandom(en);
var customAlphabet = require("nanoid-good").customAlphabet(en);
var nonSecure = require("nanoid-good/non-secure").nanoid(en);var generator1 = customRandom("abcdef", 5, randomFunc);
var id1 = generator1();var generator2 = customAlphabet("1234567abcdef", 10);
var id2 = generator2();var id3 = nonSecure();
```## Async
You can use async versions of `nanoid` functions the same way as you use them in `nanoid`, i.e. by inserting `async` in the path import.
```js
var en = require("nanoid-good/locale/en");
var nanoid = require("nanoid-good/async").nanoid(en);
var customAlphabet = require("nanoid-good/async").customAlphabet(en);async function generateIds() {
var id1 = await nanoid();
var id2 = await customAlphabet("1234567abcdef", 10)();
}
```