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

@engr-lukman/random-string-generator

v1.0.7

Published

A lightweight utility library for generating random strings with TypeScript support

Readme

Random String Generator

A lightweight, TypeScript-compatible utility for generating random strings.

Installation

npm install @engr-lukman/random-string-generator
# or
yarn add @engr-lukman/random-string-generator
# or
pnpm add @engr-lukman/random-string-generator

Demo

Check out the interactive Storybook demo to see the component in action.

Features

  • Generate random alphanumeric strings of any length
  • Customize the character set used for generation
  • Optional timestamp prefix for ensuring uniqueness
  • Full TypeScript support with type definitions
  • Zero dependencies
  • ES6 module compatible
  • Built for Node.js 20 LTS or higher and modern browsers

Usage

Basic Usage

import { generateRandomString } from '@engr-lukman/random-string-generator';

// Generate a random string with default length (32 characters)
const randomStr = generateRandomString();
console.log(randomStr); // e.g., "8FKP2JH7SQ9RT5VZ3WX1CV6BN4ML0AD"

// Generate a random string with custom length
const shortRandomStr = generateRandomString(8);
console.log(shortRandomStr); // e.g., "7DH9XP3S"

// Generate a unique random string with timestamp prefix
const uniqueStr = generateRandomString(32, { useTimestampPrefix: true });
console.log(uniqueStr); // e.g., "10EFRG2WCV6BN4ML0ADFKP2JH7SQ9RT"

Custom Character Set

import { generateRandomStringWithCharset } from '@engr-lukman/random-string-generator';

// Generate a random string using only numbers
const randomNumbers = generateRandomStringWithCharset(6, '0123456789');
console.log(randomNumbers); // e.g., "847295"

// Generate a random hexadecimal string
const hexString = generateRandomStringWithCharset(16, '0123456789ABCDEF');
console.log(hexString); // e.g., "9A7C3F5D8E2B1064"

API Reference

generateRandomString(length?: number, options?: RandomStringOptions): string

Generates a random string using uppercase alphanumeric characters (A-Z, 0-9).

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | length | number | 32 | The length of the generated string | | options | RandomStringOptions | {} | Options for string generation |

RandomStringOptions:

| Property | Type | Default | Description | |----------|------|---------|-------------| | useTimestampPrefix | boolean | false | If true, adds a timestamp prefix for uniqueness |

Returns: A random string of specified length.

generateRandomStringWithCharset(length?: number, charset?: string): string

Generates a random string using characters from the provided charset.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | length | number | 32 | The length of the generated string | | charset | string | "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | The character set to use for generation |

Returns: A random string of specified length using the provided character set.

Compatibility

  • Node.js 20 LTS or higher
  • Modern browsers supporting ES6 modules

Security

For cryptographically secure strings, this library uses the Web Crypto API when available, with a fallback to Math.random() when not.

License

MIT © Mohammad Lukman Hussain