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

@kennx9/random-password

v0.0.5

Published

A versatile random password generator for Node.js and browser

Downloads

262

Readme

Random Password Generator | 随机密码生成器

A versatile random password generator for Node.js and browser.

一个适用于 Node.js 和浏览器的多功能随机密码生成器。

Features | 特性

  • Generate secure random passwords | 生成安全的随机密码
  • Customizable password length and character sets | 可自定义密码长度和字符集
  • Password strength evaluation | 密码强度评估
  • Support for both Node.js and browser environments | 同时支持 Node.js 和浏览器环境
  • Command-line interface (CLI) support | 支持命令行界面
  • Flexible configuration options | 灵活的配置选项
  • TypeScript support | 支持 TypeScript

Installation | 安装

npm install @kennx9/random-password
# or
pnpm add @kennx9/random-password
# or
yarn add @kennx9/random-password

Usage | 使用方法

As a Module | 作为模块使用

import { generatePassword } from '@kennx9/random-password';

// Generate password with default options
// 使用默认选项生成密码
const { password, strength } = generatePassword();
console.log(password);  // e.g., "Kj#9mP$2nL5q"
console.log(strength);  // "strong"

// Generate password with custom options
// 使用自定义选项生成密码
const result = generatePassword({
  length: 16,                // Password length | 密码长度
  numbers: true,             // Include numbers | 包含数字
  symbols: true,             // Include symbols | 包含符号
  uppercase: true,           // Include uppercase letters | 包含大写字母
  lowercase: true,           // Include lowercase letters | 包含小写字母
  firstCharacter: 'random',  // First character type | 首字符类型
  excludeChars: {           // Characters to exclude | 要排除的字符
    lowercase: ['l', 'o'],
    uppercase: ['I', 'O'],
    numbers: ['0', '1'],
    symbols: ['@', '#']
  },
  customCharset: undefined   // Custom character set | 自定义字符集
});

Command Line Usage | 命令行使用

The package includes a CLI tool named 'rnd'.

包含一个名为 'rnd' 的命令行工具。

# Basic usage | 基本使用
rnd

# Generate a 16-character password | 生成16位密码
rnd -l 16

# Generate 5 passwords | 生成5个密码
rnd -c 5

# Generate password with verbose output | 生成密码并显示详细信息
rnd -v

# Exclude specific characters | 排除特定字符
rnd --exclude-lowercase "l,o" --exclude-numbers "0,1"

# Use custom character set | 使用自定义字符集
rnd --custom-charset "abcdefghijklmnopqrstuvwxyz0123456789"

CLI Options | 命令行选项

| Option | Description | 描述 | |--------|-------------|------| | -l, --length <number> | Password length (4-128) | 密码长度 (4-128) | | -c, --count <number> | Number of passwords to generate | 生成密码的数量 | | -v, --verbose | Show detailed password information | 显示详细的密码信息 | | --no-numbers | Exclude numbers | 排除数字 | | --no-symbols | Exclude symbols | 排除符号 | | --no-uppercase | Exclude uppercase letters | 排除大写字母 | | --no-lowercase | Exclude lowercase letters | 排除小写字母 | | --exclude-lowercase <chars> | Exclude specific lowercase letters | 排除特定小写字母 | | --exclude-uppercase <chars> | Exclude specific uppercase letters | 排除特定大写字母 | | --exclude-numbers <chars> | Exclude specific numbers | 排除特定数字 | | --exclude-symbols <chars> | Exclude specific symbols | 排除特定符号 | | --custom-charset <chars> | Use custom character set | 使用自定义字符集 |

API Reference | API 参考

generatePassword(options?)

Generate a random password based on the provided options.

根据提供的选项生成随机密码。

Options | 选项

interface PasswordOptions {
  length?: number;           // Password length | 密码长度
  numbers?: boolean;         // Include numbers | 包含数字
  symbols?: boolean;         // Include symbols | 包含符号
  uppercase?: boolean;       // Include uppercase | 包含大写字母
  lowercase?: boolean;       // Include lowercase | 包含小写字母
  firstCharacter?: FirstCharacterType;  // First character type | 首字符类型
  excludeChars?: {          // Characters to exclude | 要排除的字符
    lowercase?: string[];
    uppercase?: string[];
    numbers?: string[];
    symbols?: string[];
  };
  customCharset?: string;    // Custom character set | 自定义字符集
}

Return Value | 返回值

{
  password: string;          // Generated password | 生成的密码
  strength: PasswordStrength // Password strength (weak/medium/strong) | 密码强度 (弱/中/强)
}

License | 许可证

MIT