nanoid-bad

3.1.2 • Public • Published

⚠️ Disclaimer ⚠️

This repo is a joke, I advise you not to use it in production because even if the generated IDs seem random, the generation time is a bit longer than Nano ID and the presence of known words makes the IDs less secure.

nanoid-bad

Guarantees you will not get any obscene words or other profanity in your ids generated by Nano ID.

This is a drop-in replacement for Nano ID which means you can just change the name of imported package from nanoid to nanoid-bad.

How it works

It checks every generated ID through a vocabulary of obscene words. If no match is found, then ID is generated again and again until it gets an ID containing an obscene word 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

npm install nanoid-bad

Usage

var en = require("nanoid-bad/locale/en"); // you should add locale of your preferred language
var nanoid = require("nanoid-bad").nanoid(en);
var id = nanoid(); //=> "Oz3sEXuSLkLPw18gDCOvv"

You can also use several locales:

var en = require("nanoid-bad/locale/en");
var ru = require("nanoid-bad/locale/ru");
var nanoid = require("nanoid-bad").nanoid(en, ru);

All additional functions of Nano ID are supported too:

var en = require("nanoid-bad/locale/en");
var customRandom = require("nanoid-bad").customRandom(en);
var customAlphabet = require("nanoid-bad").customAlphabet(en);
var nonSecure = require("nanoid-bad/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.

var en = require("nanoid-bad/locale/en");
var nanoid = require("nanoid-bad/async").nanoid(en);
var customAlphabet = require("nanoid-bad/async").customAlphabet(en);

async function generateIds() {
  var id1 = await nanoid();
  var id2 = await customAlphabet("1234567abcdef", 10)();
}

Readme

Keywords

Package Sidebar

Install

npm i nanoid-bad

Weekly Downloads

0

Version

3.1.2

License

ISC

Unpacked Size

8.99 kB

Total Files

34

Last publish

Collaborators

  • simon_leclere