otp-gen-random
v1.0.0
Published
This is a test package to generate random otp
Maintainers
Readme
otp-generator
A simple and lightweight npm package to generate random OTP (One-Time Password) numbers.
Installation
npm install otp-gen-randomUsage
CommonJS (require)
const getOTP = require('otp-gen-random');
// Generate a 6-digit OTP
const otp = getOTP(6);
console.log(otp); // e.g., "123456"ES Modules (import)
import getOTP from 'otp-gen-random';
// Generate a 4-digit OTP
const otp = getOTP(4);
console.log(otp); // e.g., "5678"API
getOTP(length)
Generates a random OTP with the specified number of digits.
Parameters:
length(number): The number of digits in the OTP (must be a positive integer)
Returns:
string: A random OTP string containing only digits (0-9)
Example:
const otp1 = getOTP(5); // Returns a 5-digit OTP
const otp2 = getOTP(6); // Returns a 6-digit OTP
const otp3 = getOTP(10); // Returns a 10-digit OTPFeatures
- ✅ Simple and lightweight
- ✅ Works with both CommonJS and ES Modules
- ✅ No external dependencies
- ✅ Type-safe (throws error on invalid input)
License
ISC
Author
Deepak Carpenter
