generate-short-id-simple
v1.0.0
Published
A simple JavaScript package to generate short IDs with letters, numbers, and special characters.
Maintainers
Readme
generate-short-id
A simple JavaScript package to generate short IDs with letters, numbers, and special characters.
Description
generate-short-id allows you to generate unique, random strings of any length.
- By default, it generates letters only (A-Z, a-z).
- You can optionally include numbers (
0-9) and special characters (!@#$%^&*()_+-=[]{}|;:,.<>?). - Perfect for generating IDs for fake inputs, tokens, or unique keys.
How It Works
- You specify the length of the ID.
- Optional boolean flags determine the character set:
includeNumbers→trueto include numbersincludeSpecials→trueto include special characters
- The function generates a random string exactly matching the requested length.
Installation
npm install generate-short-id
## Usage
```bash
const { generateShortId } = require('generate-short-id');
// Letters only (default)
console.log(generateShortId(10)); // e.g., "aBcDeFgHiJ"
// Letters + numbers
console.log(generateShortId(10, true)); // e.g., "aB3dE6fHkL"
// Letters + numbers + special characters
console.log(generateShortId(10, true, true)); // e.g., "aB3$dE6!kL"
// Letters + special characters only
console.log(generateShortId(10, false, true)); // e.g., "aB@dE!fGh$"