Last active
May 10, 2021 17:48
-
-
Save Bound3R/0cfced2ff8dd20ec705976e0a4d7391b to your computer and use it in GitHub Desktop.
special function to create simple-codes (eg, sms validators or coupons)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
after create all codes, you can split using next command:
split -l 4 -d --numeric-suffixes=1 --suffix-length=3 codes.txt codes.