New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

generate-verification-code

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-verification-code

NPM library to generate verification code for sms or email

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Generate Verification Code

A simple NPM package to generate verification code for sms or email

Installation

You can install the generate-verification-code library using npm or yarn:

npm install generate-verification-code
# or
yarn add generate-verification-code

Usage

To generate a verification code using the library, follow these steps:

  • Import the library:
import { generateVerificationCode } from 'generate-verification-code';

//or

const { generateVerificationCode } = require('generate-verification-code');
  • Call the generateVerificationCode function with optional parameters:
// Default options: length = 6, type = 'number'
const verificationCode1 = generateVerificationCode();

// Custom options: length = 4, type = 'string'
const verificationCode2 = generateVerificationCode({
    length: 4,
    type: 'string',
});
  • Use the generated verification code:
console.log('Verification Code 1:', verificationCode1);
console.log('Verification Code 2:', verificationCode2);

API

generateVerificationCode(options) Generates a verification code based on the provided options.

  • options (optional): An object containing the following optional properties:
    • length (optional): The length of the verification code. Default is 6. If type is number then maximum value of the length will be 16. Length should be greater than zero.s
    • type (optional): The type of verification code to generate. Can be 'string' or 'number'. Default is 'number'.

Returns the generated verification code as a string or number, based on the specified type in the options.

Error Handling

The library handles various error scenarios, such as invalid options or input. If an error occurs, the library will throw an error with a descriptive message.

try {
    const verificationCode = generateVerificationCode({
        length: -1,
        type: 'number'
    });
} catch (error) {
    console.error('Error:', error.message);
}

Keywords

verification-code

FAQs

Package last updated on 23 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts