UNPKG

generate-short-id-simple

Version:

A simple JavaScript package to generate short IDs with letters, numbers, and special characters.

39 lines (27 loc) 1.35 kB
# 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 1. You specify the **length** of the ID. 2. Optional boolean flags determine the character set: - `includeNumbers``true` to include numbers - `includeSpecials``true` to include special characters 3. The function generates a **random string exactly matching the requested length**. ## Installation ```bash 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$"