A lightweight, zero-dependency TypeScript library for generating secure One-Time Passwords (OTPs).
- 🚀 Generate random numeric OTPs of custom length
- 🔒 Secure random number generation
- 📦 Zero dependencies
- 🛠 Written in TypeScript with full type definitions
- ⚡ Lightweight and fast
npm install otpx-test
# or
yarn add otpx-test
# or
pnpm add otpx-testimport { generateRandomDigits } from "otpx-test";
// Generate a 4-digit OTP (default)
const otp = generateRandomDigits();
console.log(otp); // e.g., '1234'
// Generate a 6-digit OTP
const sixDigitOtp = generateRandomDigits(6);
console.log(sixDigitOtp); // e.g., '123456'Generates a random numeric OTP of the specified length.
length(optional): The length of the OTP to generate. Defaults to 4.- Returns: A string containing the generated OTP.
- Clone the repository
- Install dependencies:
npm install
- Build the project:
npm run build
- For development with watch mode:
npm run dev
This project is licensed under the MIT License - see the LICENSE file for details.
👤 Jay
- GitHub: @JaySyntax
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Give a ⭐️ if this project helped you!