1.0.1 • Published 3 years ago
randomim v1.0.1
randomim
About
A Node.js module for generating random things.
Installation
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).
Using npm
npm install randomim
Using Yarn
yarn install randomim
Using Git
git clone https://github.com/MustafaTRK/randomim.git
Manually (GitHub Archive)
MustafaTRK/randomim - GitHub Archive
API
options
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
randomim#Charset.ALPHABETIC
- a-z, A-Zrandomim#Charset.NUMERIC
- 0-9randomim#Charset.ALPHANUMERIC
- a-z, A-Z, 0-9randomim#Charset.HEXADECIMAL
- 0-9, a-frandomim#Charset.BINARY
- 0, 1
randomim#Capitalization
randomim#Capitalization.LOWERCASE
- Lowercase letters. - (int: 1)randomim#Capitalization.UPPERCASE
- Uppercase letters. - (int: 2)
Examples
Include in the project
// ES5
const randomim = require("randomim");
// ES6
import randomim from "randomim";
static randomim#generate(options)
randomim.generate(); // "KjrOQKuDBc"
static randomim#constructor(options)
let randomizer = new randomim();
randomizer.generate(); // "WdplRqaDYU"
randomizer.generate(); // "JJYKsWyCSM"
with options
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)