There are lots of scenarios which one can use our Random string generator the most known or the best scenario is for
1.Password generation
2.Token generation.
3.Testing
4.id generation
This package generate random string based on the given parameters.
To start to use this on local machine build then first Test the program using the test.js
Install node modules
- npm
npm install randomized-string
- yarn
yarn add randomized-string
For generating a random string you call generate()
function.By default it generate 16 character string.
const randomString = require('randomized-string');
randomString.generate(); // xabgtl3yb1Ac0MrQ
or you can use import
statment
import randomString from 'randomized-string';
If you want some length to random string pass a number to the function.
randomString.generate(6); // lAo3Bi
To be more specific you can pass an object for more flexibility.This are the listed options you can provide
type options = {
charset?: 'alphanumeric' | 'number' | 'alphabet' | 'hex' | 'binary' | 'octal';
lowerCaseOnly?: boolean; //only lowercase letter
range?: string; // user provided charset
length: number; //length of the character if not provided generates 16 characters by default
upperCaseOnly?: boolean; // only uppercase letter
insertSymbol?: boolean; // insert symbols to given charset
symbolsOnly: boolean; //only symbols
prefix: string; // add before string
suffix: string; // add after the string
};
Generate string only in the given string range
randomeString.generate({
range: 'abc123',
length: 6,
});
// a3cb21
You can set also set type of string
randomString.generate({
charset: 'number',
length: 10,
}); //2342612198
randomString.generate({
charset: 'alphabet',
length: 10,
}); //SoWhopDFTb
randomString.generate({
charset: 'hex',
length: 6,
}); // C0faDB
You can insert prefix prefix
or suffix
characters. Note that the length of the prefix or suffix is not counted with the length of the random string.
randomString.generate({
length: 10,
prefix: 'pre-',
}); //pre-GaKdvH8Bro
randomString.generate({
length: 10,
suffix: '-suff',
}); //0YcCeMISpE-suff
You can also insert symbols if you pass set the insertSymbol
option to true. But it doesn't work for binary or octal or hex charset option.
randomString.generate({
insertSymbol: true,
});
//bd@MK8ˆIvpGVoorO{FJkf]iMz,{1+-8g
You can pass the option upperCaseOnly
to make the string only capital and lowerCaseOnly
to make the string lowercase
randomString.generate({
charset: 'alphabet',
upperCaseOnly: true,
});
//ODEISDGQXUGGOHHG
randomString.generate({
lowerCaseOnly: true,
});
//fnzkamf0svos4yso
You can get symbols only if you set option symbolsOnly:true,
randomString.generate({
symbolsOnly: true,
length: 10,
});
// ?[]}$'&,{]
For fun you can also generate random emojis using generateUnicodeEmoji(length)
randomString.generateUnicodeEmoji(1); //🍍
First the package should be installed globally
$ npm install randomized-string -g
$ yarn add randomized-string
$ randomized-string
// Urp0YDaIHWn7YCCF
$ randomized-string upperCaseOnly=true charset=alphanumeric
// DX5ACJP1FJN5Q79Z
$ randomized-string charset=alphanumeric insertSymbol=true length=8
// S8Cza8v^
$ randomized-string prefix=pre-
//pre-KOyWstwcpA6sLaH3
$ randomized-string generateUnicodeEmoji length=5
// ⏺️💤👇😰🗳️
randomString
generate(option|length)
-
option:
-
length: define the length of the output default 16 [Optional]
-
insert Symbol: to use Symbols when generatig random string output [Optional]
-
charset:
-
Alphabetic [a-zA-Z]
-
alphanumeric[0-9a-zAZ]
-
numeric [0-9]
-
Binary [01]
-
Octal [0-7]
-
Hexa [0-9a-fA-F]
-
-
capitalization:
-
upperCaseOnly : Only Capital Leters are used to generate the output [Optional]
-
lowerCaseOnly : Only Small Leters are used to generate the output [Optional]
-
-
symbols only:
- used to generate symbols only
-
prefix:
- Adds a character before the random string
-
suffix:
- Adds character after the random string
generateUnicodeEmoji(length)
- generates random emojis
- npm install
- npm run test
See the open issues for a full list of proposed features (and known issues).
- You can also give as star to our repo.
👤 Dagmawi Zewdu
- GitHub: @Dagic-zewdu
- LinkedIn: Dagi-Zewdu
👤 Sentayhu Berhanu
- GitHub: @sentayhu19
- LinkedIn: sentayhu-berhanu
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Dagmawi Zewdu - @Dagi - [email protected]
Sentayhu Berhanu- @Sentayhu - [email protected]
Project Link: https://github.com/Dagic-zewdu/random-string