1.0.4 • Published 4 months ago

otp-pass-kit-2 v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

OTP & Pass Kit

A simple and customizable OTP and password generator for Node.js and TypeScript projects.

Installation

npm install otp-pass-kit

Importing the Module

import { generateOtp, generatePass } from "otp-pass-kit";

OTP Generator

Function Signature

function generateOtp(length?: number, options?: OtpOptions): string;

Options

OptionTypeDefaultDescription
upperCaseAlphabetsbooleanfalseInclude uppercase letters
lowerCaseAlphabetsbooleanfalseInclude lowercase letters
specialCharsbooleanfalseInclude special characters
digitsbooleantrueInclude digits

Example Usage

import { generateOtp } from "otp-pass-kit";

const otp1 = generateOtp(); // Default 6-digit numeric OTP
console.log(otp1);

const otp2 = generateOtp(8, { upperCaseAlphabets: true, digits: true }); // 8-character OTP with digits and uppercase letters
console.log(otp2);

Password Generator

Function Signature

function generatePass(length?: number, options?: passOptions): string;

Options

OptionTypeDefaultDescription
upperCaseAlphabetsbooleantrueInclude uppercase letters
lowerCaseAlphabetsbooleantrueInclude lowercase letters
specialCharsbooleantrueInclude special characters
digitsbooleantrueInclude digits

Example Usage

import { generatePass } from "otp-pass-kit";

const password1 = generatePass(); // Default 8-character password with all character sets
console.log(password1);

const password2 = generatePass(12, { lowerCaseAlphabets: true, digits: true }); // 12-character password with lowercase letters and digits
console.log(password2);

Error Handling

If no character set is selected in the options, an error is thrown:

try {
  generateOtp(6, { upperCaseAlphabets: false, lowerCaseAlphabets: false, specialChars: false, digits: false });
} catch (error) {
  console.error(error.message); // "At least one character set must be enabled"
}

License

This package is licensed under the MIT License.

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago