UNPKG

smgtools

Version:

Common tools used for SMG projects for generating IDs and other standard tasks.

23 lines (19 loc) 1.47 kB
var crypto = require('crypto'); exports.newIdentifier = function(len=12) { var identifier = crypto.randomBytes(len+4).toString('base64').substr(0,x.length); var blacklist = ['anal','anus','arse','ass','ballsack','balls','bastard','bitch','biatch','bloody','blowjob','bollock','bollok','boner','boob','bugger','bum','butt','buttplug','clitoris','cock','coon','crap','cunt','damn','dick','dildo','dyke','fag','feck','fellate','fellatio','felching','fuck','fudgepacker','flange','Goddamn','hell','homo','jerk','jizz','knobend','labia','lmao','lmfao','muff','nigger','nigga','omg','penis','piss','poop','prick','pube','pussy','queer','scrotum','sex','shit','sh1t','slut','smegma','spunk','tit','tosser','turd','twat','vagina','wank','whore','wtf']; do { // replace / and + from id string with a number identifier = identifier.replace(/[\/+]/g, function(x) { if (x == '+') return "-"; if (x == '/') return "_"; return Math.floor((Math.random() * 10)); }); var result = identifier; // result check is set here since the do loop doesn't need to repeat if we only replaced symbols // if we find a blacklist word replace with new hash identifier = identifier.replace(new RegExp(blacklist.join("|"),"gi"), function (x) { return crypto.randomBytes(len+4).toString('base64').substr(0,x.length); }); } while (result != identifier); return identifier; };