npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

otp-number

v1.0.4

Published

> πŸ” A lightweight and flexible JavaScript library to generate random OTPs (One-Time Passwords) for use in both frontend and backend applications.

Readme

otp-number

πŸ” A lightweight and flexible JavaScript library to generate random OTPs (One-Time Passwords) for use in both frontend and backend applications.


✨ Features

  • βœ… Supports digits, uppercase, and lowercase characters
  • βœ… Configurable OTP length
  • βœ… Works in Node.js and browser (UMD compatible)
  • βœ… Zero dependencies
  • πŸ”’ Numeric-only OTP shortcut with otp_number_only(length)

πŸ“¦ Installation

npm install otp-number

πŸ”§ Usage

const { otp_number, otp_number_only } = require('otp-number');

// Generate a 6-digit OTP with digits, uppercase, and lowercase letters (default) const defaultOTP = otp_number(); console.log(defaultOTP); // Example: "aB3dE9"

// Generate an 8-digit numeric-only OTP using the helper function const numericOTP = otp_number_only(8); console.log(numericOTP); // Example: "12345678"

// Generate a 10-character OTP with only uppercase letters and digits const customOTP = otp_number(10, { digits: true, upperCase: true, lowerCase: false }); console.log(customOTP); // Example: "A1B2C3D4E5"

// Generate a 4-character OTP with only lowercase letters const lowercaseOTP = otp_number(4, { digits: false, upperCase: false, lowerCase: true }); console.log(lowercaseOTP); // Example: "wxyz"

// Attempting to generate an OTP with no character sets enabled will throw an error: try { otp_number(6, { digits: false, upperCase: false, lowerCase: false }); } catch (error) { console.error(error.message); // Output: "At least one character set must be enabled." }

Numeric Only Shortcut

const { otp_number_only } = require('otp-number');
console.log(otp_number_only(6)); // ➀ "920384"

## Browser (UMD)

<script src="dist/otp-generator.umd.js"></script>
<script>
  const otp = OtpGenerator.otp_number(6, { digits: true, upperCase: true });
  console.log("OTP:", otp);
</script>


## βš™οΈ API
otp_number(length, options)

Parameter	Type	Default	Description
length	number	6	Length of the OTP
options.digits	boolean	true	Include digits (0-9)
options.upperCase	boolean	false	Include uppercase letters (A-Z)
options.lowerCase	boolean	false	Include lowercase letters (a-z)

## πŸ“Œ Example Outputs

otp_number();
// ➀ "729314"

otp_number(6, { digits: true, upperCase: true });
// ➀ "5J8K2Q"

otp_number(4, { lowerCase: true });
// ➀ "kfza"
otp_number_only(length = 6)

A helper function that generates a numeric-only OTP string of the specified length. This is equivalent to calling otp_number(length, { digits: true }).

## πŸ“ Build (for Browser Support)

Install dev dependencies:

bash
Copy
Edit
npm install --save-dev rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve
Build UMD:

bash
Copy
Edit
npx rollup -c

## πŸ”Ž Keywords

otp, otp-number, random otp, otp generator, javascript otp, nodejs otp, one-time password, verification code, auth code, frontend backend otp, browser otp, 2FA