A Node.js module for generating random things.
This is a Node.js module available through the npm registry. Before installing, download and install Node.js (tested and recommended Node.js v14.17.0).
npm install randomim
yarn install randomim
git clone https://github.com/MustafaTRK/randomim.git
MustafaTRK/randomim - GitHub Archive
-
length
- number - The lenght of the random string. - OPTIONAL (default: 10) -
charset
- randomim#Charset | string - Set the character list. - OPTIONAL (default: randomim#Charset.ALPHANUMERIC) -
capitalization
- randomim#Capitalization | number - Choose whether the output should be in lowercase or uppercase letters only. - OPTIONAL (default: null) -
prefix
- string - Prefix of the output. - OPTIONAL (default: null) -
suffix
- string - Suffix of the output. - OPTIONAL (default: null) -
unique
- string - Whether to delete repeated chars in charset. - OPTIONAL (default: true)
-
randomim#Charset.ALPHABETIC
- [a-z, A-Z] -
randomim#Charset.NUMERIC
- [0-9] -
randomim#Charset.ALPHANUMERIC
- [a-z, A-Z, 0-9] -
randomim#Charset.HEXADECIMAL
- [0-9, a-f] -
randomim#Charset.BINARY
- [0, 1]
-
randomim#Capitalization.LOWERCASE
- Lowercase letters. - (int: 1) -
randomim#Capitalization.UPPERCASE
- Uppercase letters. - (int: 2)
// ES5
const randomim = require("randomim");
// ES6
import randomim from "randomim";
randomim.generate(); // "KjrOQKuDBc"
let randomizer = new randomim();
randomizer.generate(); // "WdplRqaDYU"
randomizer.generate(); // "JJYKsWyCSM"
randomim.generate({
length: 25,
charset: randomim.Charset.ALPHABETIC
}); // "VcpHwuRJKOrIXvTcbJPOUEvMX"
randomim.generate({
charset: "test123"
}); // "st1tst3ee3"
randomim.generate({
prefix: "key_",
suffix: "_2021"
}); // "key_J52CeRnM5F_2021"
randomim.generate({
length: 30,
capitalization: randomim.Capitalization.UPPERCASE
}); // "LYRQP7HI4EODWJF3EY8A3PUR0GA0XJ" (yea, there are too many letters)
randomim.generate({
length: 30,
capitalization: randomim.Capitalization.UPPERCASE,
unique: true
}); // "41Z01HQ6GFRPPZ3O69G3QQLGIASJS5" (now balanced)
let randomizer = new randomim({
length: 12
});
randomizer.generate(); // "mIV3KWfbTCY9"
randomizer.options.charset = "omgwhatisthis";
randomizer.options.length = 25;
randomizer.generate(); // "asiootthtagashioitthsiats" (options.unique is not effective here)