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

samlibs-generate-password

v1.0.0

Published

A lightweight, fast, and optimized password generator library

Readme

samlibs-generate-password

npm version License: MIT

A lightweight, fast, and optimized password generator library for Node.js. Unlike other libraries that require complex setup, this package provides a simple function that accepts a configuration object to generate secure passwords.

🚀 Features

  • Ultra Lightweight: Minimal dependencies and optimized code
  • Fast Performance: Efficient character pool generation and selection
  • TypeScript Support: Full TypeScript definitions included
  • Universal Compatibility: Works with CommonJS and ES modules
  • Flexible Configuration: Comprehensive options for password customization
  • Secure Random Generation: Uses crypto.getRandomValues when available
  • Character Exclusion: Exclude specific characters from password generation

📦 Installation

npm install samlibs-generate-password

🔧 Usage

CommonJS

const generatePassword = require('samlibs-generate-password');

// Generate a simple password with default settings
const password = generatePassword();
console.log(password); // e.g., "K9$mN7#qR2@x"

// Generate password with custom options
const customPassword = generatePassword({
  length: 16,
  uppercase: true,
  lowercase: true,
  numbers: true,
  special: false,
  exclude: ['0', 'O', 'l', '1']
});
console.log(customPassword); // e.g., "KmN7qR2xPzWcJbVn"

ES Modules

import generatePassword from 'samlibs-generate-password';

// Generate multiple passwords
const passwords = generatePassword({
  length: 12,
  quantity: 5,
  special: true
});
console.log(passwords); // Array of 5 passwords

TypeScript

import generatePassword, { PasswordOptions } from 'samlibs-generate-password';

const options: PasswordOptions = {
  length: 20,
  quantity: 1,
  lowercase: true,
  uppercase: true,
  numbers: true,
  special: true,
  exclude: ['@', '#', '$']
};

const password: string = generatePassword(options) as string;

⚙️ Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | length | number | 12 | Length of each password | | quantity | number | 1 | Number of passwords to generate | | lowercase | boolean | true | Include lowercase letters (a-z) | | uppercase | boolean | true | Include uppercase letters (A-Z) | | numbers | boolean | true | Include numbers (0-9) | | special | boolean | true | Include special characters (!@#$%^&*()_+-=[]{}|;:,.<>?) | | exclude | string[] | [] | Array of characters to exclude |

📋 Examples

Basic Usage

const generatePassword = require('samlibs-generate-password');

// Default password (12 characters, all character types)
const password = generatePassword();

Custom Length and Character Types

// Only letters and numbers, 16 characters
const password = generatePassword({
  length: 16,
  special: false
});

// Only uppercase letters, 8 characters
const password = generatePassword({
  length: 8,
  lowercase: false,
  numbers: false,
  special: false
});

Multiple Passwords

// Generate 10 passwords at once
const passwords = generatePassword({
  length: 15,
  quantity: 10
});

Exclude Similar Characters

// Exclude confusing characters like 0, O, l, 1
const password = generatePassword({
  length: 12,
  exclude: ['0', 'O', 'l', '1', 'I']
});

Strong Password for Databases

// Database-safe password (no special characters that might cause issues)
const dbPassword = generatePassword({
  length: 32,
  special: false,
  exclude: ['\\', '/', '"', "'", '`']
});

🔒 Security Features

  • Uses crypto.getRandomValues() for cryptographically secure randomness when available
  • Falls back to Math.random() in environments where crypto is not available
  • No predictable patterns in password generation
  • Efficient character pool filtering to prevent bias

🚀 Performance

This library is optimized for:

  • Minimal memory footprint
  • Fast character pool generation
  • Efficient exclusion filtering using Set data structure
  • No unnecessary dependencies

📊 Comparison

Unlike other password libraries that require instantiating classes or complex configurations:

// Other libraries
const generator = new PasswordGenerator({...});
const password = generator.generate();

// samlibs-generate-password (simpler)
const password = generatePassword({...});

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License - see LICENSE file for details.

🔗 Links


Made with ❤️ for developers who value simplicity and performance.