@crispengari/random-verification-codes
v1.0.3
Published
This is a simple node.js/ts package that generates random verification codes.
Downloads
11
Maintainers
Readme
Verification Code Generator.
This is a package that generate verification code using random numbers. For example you can generate numbers like 12789
and use it as a verification code with your magic.
Why this simple package?
I created this package, when i was working on a certain application where I have to send the verification codes to the users via email. So I take it as a good idea to create it as a package that using regular functions for reusability.
Installation
yarn
yarn add @crispengari/random-verification-codes
npm
npm install @crispengari/random-verification-codes
TypeScript
You don't have to explicitly install the types for this package because it was created using typescript.
Basic usage
import {
generateVerificationCode,
generateInteger,
} from "@crispengari/random-verification-codes";
const randomInt = generateInteger(); // returns a random number between 0 and 9 inclusive
const generated = await generateVerificationCode(); // generate a random verification 5 digit as a string by default
generateVerificationCode()
A promise function that accepts three argument and returns a string or an integer based on the arguments passed:
**numberOfDigits**
- anumber
which specifies length of the generated code default is5
.**allowZeroStart**
- aboolean
which specifies wether the verification code to start with a zero or not default istrue
.**returnAsString**
- aboolean
which specifies wether the verification should be a string or a number default istrue
.
Basic example
es6
import {
generateVerificationCode,
generateInteger,
} from "@crispengari/random-verification-codes";
const main = async () => {
const generated = await generateVerificationCode();
console.log(generated);
};
main();
es5
import {
generateVerificationCode,
generateInteger,
} from "@crispengari/random-verification-codes";
generateVerificationCode().then((generatedCode) => console.log(generatedCode));