Skip to content

Instantly share code, notes, and snippets.

@Bound3R
Last active May 10, 2021 17:48
Show Gist options
  • Save Bound3R/0cfced2ff8dd20ec705976e0a4d7391b to your computer and use it in GitHub Desktop.
Save Bound3R/0cfced2ff8dd20ec705976e0a4d7391b to your computer and use it in GitHub Desktop.
special function to create simple-codes (eg, sms validators or coupons)
const randomstring = require('randomstring');
const badWords = require('./profanity.js'); // array to get the "black-list"
function genRandomCodes(quantity, length) {
const codes = new Set();
while (codes.size <= quantity) {
let code = randomstring.generate(length, true);
// This conditional is the ´code´ when this contains profane language
if (!badWords.some(word => code.toLowerCase().includes(word))) {
codes.add(code);
} else {
continue;
}
}
return codes
}
for (let item of genRandomCodes(1, 6)) console.log(item + ','); // this is the "output" using shell and csv format
@Bound3R
Copy link
Author

Bound3R commented Jan 25, 2020

after create all codes, you can split using next command:

split -l 4 -d --numeric-suffixes=1 --suffix-length=3 codes.txt codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment