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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nithin-sivakumar/genotp

v1.0.1

Published

A lightweight and secure OTP (One-Time Password) generator for JavaScript with customizable features like length, character set, prefix, suffix, and base64 encoding.

Readme

@nithin-sivakumar/genotp

A lightweight and secure OTP (One-Time Password) generator for JavaScript with customizable features like length, character set, prefix, suffix, and base64 encoding.

Features

  • Secure OTP Generation: Uses crypto module for secure, random OTP generation.
  • Customizable Length: Generate OTPs of any length.
  • Multiple Character Sets:
    • Numeric: 0123456789
    • Alphanumeric: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
    • Custom: Use a custom character set of your choice.
  • Prefix and Suffix: Optionally add a prefix or suffix to your OTP.
  • Base64 Encoding: Optionally return the OTP as a base64-encoded string.
  • No Expiry Handling: This package only focuses on OTP generation; expiry is left to the user.

Installation

To install the package, run:

npm install @nithin-sivakumar/genotp

Usage

Generate OTP

To generate an OTP, use the generate function with the following options:

import { generate } from "@nithin-sivakumar/genotp";

// Generate Numeric OTP of length 6
const otp = generate(6, "numeric");
console.log("Generated Numeric OTP:", otp);

// Generate Alphanumeric OTP with a prefix
const otpWithPrefix = generate(8, "alphanumeric", "", "OTP-", "");
console.log("Generated OTP with Prefix:", otpWithPrefix);

// Generate OTP with a custom character set
const customCharSet =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#";
const otpWithCustomCharSet = generate(10, "custom", customCharSet);
console.log("Generated OTP with Custom Character Set:", otpWithCustomCharSet);

// Generate Base64-encoded OTP
const base64Otp = generate(10, "alphanumeric", "", "", "", true);
console.log("Base64 Encoded OTP:", base64Otp);

Options for generate function:

  • length (number): The length of the OTP. Default is 6.
  • mode (string): The mode of OTP generation:
    • 'numeric': OTP contains only numbers.
    • 'alphanumeric': OTP contains numbers and letters (both uppercase).
    • 'custom': OTP uses a custom character set. Default is 'numeric'.
  • charSet (string): Custom characters to use for OTP generation (only for custom mode). Default is empty.
  • prefix (string): Optional prefix to be added to the OTP. Default is "".
  • suffix (string): Optional suffix to be added to the OTP. Default is "".
  • base64Encode (boolean): Whether to return the OTP as a base64-encoded string. Default is false.

Example

import { generate } from "@nithin-sivakumar/genotp";

// Generate OTP of length 6 using numeric characters
const otp = generate(6, "numeric");
console.log(otp); // Example: 123456

// Generate OTP of length 8 using alphanumeric characters
const otpAlphanumeric = generate(8, "alphanumeric");
console.log(otpAlphanumeric); // Example: A1B2C3D4

// Generate OTP with custom character set
const customOtp = generate(
  10,
  "custom",
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#"
);
console.log(customOtp); // Example: aB1!jK8@

Error Handling

The package throws the following errors:

  • Invalid Mode or Character Set: If the mode or character set is invalid, an error will be thrown.
  • Invalid Length: If the length is less than or equal to 0, an error will be thrown.

License

MIT License. See LICENSE for more information.