Randomized-string Node module package
Node module package
This is a node module package project I did together with my friend last month. The package is called randomized-string which Generates Random strings based on passed parameters. The best scenario is for this project to be used is for:
- Password generation
- Token generation.
- Testing
- id generation
- Random Unicode Emoji Generator
We have many different features on this package to give developers the flexibility so that we will generate based on the needs of the programmer. we will discuss more on the features in detail later.
We used Typescript and JavaScript to build the package
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
Now let’s see how to install the package
To install our package you can use :
npm: npm install randomized-string
yarn: yarn add randomized-string
For generating a random string you call generate()
function. By default, it generates 16 character string.
const randomString = require("randomized-string");
randomString.generate(); // xabgtl3yb1Ac0MrQ
or you can use import
statement
import randomString from 'randomized-string'
If you want the length to a random string pass a number to the function.
randomString.generate(6); // lAo3Bi
Passing down the options
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
}) //2342612198randomString.generate({
charset:'alphabet',
length:10
}) //SoWhopDFTbrandomString.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) //🍍
we have also implemented the Command Line usage.
Command Line Usage
In order to use the command line interface 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 // ⏺️💤👇😰🗳️
Tests
- npm run test
we have written a bunch of tests so that we can test our package functionality.
The package is published on npm to view click here
Our GitHub Repo Link to view click here