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

unique-username-generator

v1.5.1

Published

A package to generate a unique username from email or randomly selected nouns and adjectives. User can add a separator between the username, define the maximum length of a username and adds up to six random digits.

Readme

npm version downloads license: MIT TypeScript types install size bundle size install size semantic-release

Visitors

unique-username-generator

A tiny, flexible username generator for Node and browsers. Generate from email or dictionaries; control separator, style, max length, optional digits, profanity filtering, templates, deterministic seeds, and batch generation.

Security note: this library generates human-friendly display names. It is not intended for security-sensitive randomness (e.g., passwords, tokens). It prefers Web Crypto when available and falls back to a non-crypto PRNG only as a last resort.

NPM

Installation

npm install unique-username-generator --save
  • Importing
// Using Node.js `require()`
const { generateFromEmail, generateUsername } = require("unique-username-generator");
// Using ES6 imports
import { generateFromEmail, generateUsername } from "unique-username-generator";

Usage

Generate username from email

It will generate username from email and add upto six random digits at the end of the name.

// Simple: add three random digits
generateFromEmail("[email protected]", 3); // "lakshminarayan234"

// Advanced: options
generateFromEmail("[email protected]", { randomDigits: 2, stripLeadingDigits: true }); // "john12"
generateFromEmail("[email protected]", { randomDigits: 0, leadingFallback: "member" });  // "member"

Randomly generate unique username.

It will generate unique username from adjectives, nouns, random digits and separator. You can control these following parameters - separator, number of random digits and maximum length of a username.

// generaterUsername(separator, number of random digits, maximum length)

// Without any parameter
const username = generateUsername();
console.log(username); // blossomlogistical

// With any separator like "-, _"
const username = generateUsername("-");
console.log(username); // blossom-logistical

// With random digits and no separator
const username = generateUsername("", 3);
console.log(username); // blossomlogistical732

// With maximum length constraint and no separator, no random digits
const username = generateUsername("", 0, 15);
console.log(username); // blossomlogistic

// With maximum length constraint and separator but no random digits
const username = generateUsername("-", 0, 15);
console.log(username); // blossom-logisti

// With maximum length constraint and random digits but no separator
const username = generateUsername("", 2, 19);
console.log(username); // blossomlogistical73

// With all parameters
const username = generateUsername("-", 2, 20, "unique username");
console.log(username); // unique-username-73

Default dictionaries

By default, the unique username generator library comes with 2 dictionaries out of the box, so that you can use them straight away.

The new syntax for using the default dictionaries is the following:

import { uniqueUsernameGenerator, Config, adjectives, nouns } from 'unique-username-generator';

const config: Config = {
  dictionaries: [adjectives, nouns]
}

const username: string = uniqueUsernameGenerator(config); // blossomlogistical

Custom dictionaries

You might want to provide your custom dictionaries to use for generating your unique username, in order to meet your project requirements. You can easily do that using the dictionaries option.

import { uniqueUsernameGenerator } from 'unique-username-generator';

const marvelCharacters = [
  'Iron Man',
  'Doctor Strange',
  'Hulk',
  'Captain America',
  'Thanos'
];

const config: Config = {
  dictionaries: [marvelCharacters],
  separator: '',
  style: 'capital',
  randomDigits: 3
}

const username: string = uniqueUsernameGenerator(config); // Hulk123

Profanity filtering and exclusions

By default, the generator filters out common profane words from the built-in dictionaries to avoid unsafe names. You can extend or override the blocklist using exclude and profanityList.

import { uniqueUsernameGenerator, adjectives, nouns, DEFAULT_PROFANITY } from 'unique-username-generator';

const username = uniqueUsernameGenerator({
  dictionaries: [adjectives, nouns],
  exclude: ['beta', 'foo'],            // custom exclusions
  profanityList: DEFAULT_PROFANITY,    // extend/override blocklist
  randomDigits: 0
});

Output styles

Additional styles are supported beyond lowerCase, upperCase, and capital:

  • camelCase
  • pascalCase
  • kebabCase
  • snakeCase
  • titleCase (capitalize each word)
uniqueUsernameGenerator({ dictionaries: [["blue"],["whale"]], separator: "-", style: 'camelCase', randomDigits: 0 }); // blueWhale

Templates and deterministic output

// Template tokens: {adjective}, {noun}, positional {0},{1},... and {digits:n}
uniqueUsernameGenerator({
  dictionaries: [adjectives, nouns],
  template: "{adjective}-{noun}-{digits:2}",
  seed: "v1",           // make output deterministic
  style: "lowerCase",
}); // e.g. "brave-otter-42"

Batch generation

import { generateMany, generateUniqueAsync } from 'unique-username-generator';

// Generate N (optionally unique) usernames in-memory
const many = generateMany({ dictionaries: [adjectives, nouns], count: 5, unique: true });

// Generate a username that is unique against an external store
const taken = new Set(["cool-fox"]);
const username = await generateUniqueAsync(
  { dictionaries: [adjectives, nouns], separator: "-" },
  (candidate) => taken.has(candidate)
);

CLI

After installing, a simple CLI is available as usergen (aliases: usernamegen, unique-username, uuname).

Usage: usergen [options]

Options:
  -s, --separator <sep>     Separator between words (default: empty)
  -d, --digits <n>          Number of random digits to append (0-6)
  -l, --length <n>          Maximum username length (default: 15)
      --style <style>       Style: lowerCase | upperCase | capital | camelCase | pascalCase | kebabCase | snakeCase | titleCase
  -U, --upper               Shortcut for --style upperCase
      --seed <seed>         Deterministic seed for reproducible output
  -t, --template <tpl>      Template, e.g. "{adjective}-{noun}-{digits:2}"
  -c, --count <n>           Generate many
  -u, --unique              Ensure unique usernames within this run
  -o, --out <file>          Write results to a file (UTF-8)
      --unsafe              Disable profanity filtering
  -U, --upper               Shortcut for --style upperCase
  -D, --dict <a,b,c>        Provide a custom dictionary (can be used multiple times)
  -x, --exclude <a,b,c>     Extra words to exclude
  -h, --help                Show help

API

uniqueUsernameGenerator (options)

Returns a string with a random generated username

options

Type: Config

The options argument mostly corresponds to the properties defined for uniqueUsernameGenerator. Only dictionaries is required.

| Option | Type | Description | Default value | Example value | |--------------|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | dictionaries | array | This is an array of dictionaries. Each dictionary is an array of strings containing the words to use for generating the string.The provided dictionaries can be imported from the library as a separate modules and provided in the desired order. | n/a | import { uniqueUsernameGenerator, adjectives, nouns } from 'unique-username-generator';const username: string = uniqueUsernameGenerator({ dictionaries: [nouns, adjectives]}); // blossomlogistical | | separator | string | A string separator to be used for separate the words generated. The default separator is set to be empty string. | "" | - | | randomDigits | number | A number of random digits to add at the end of a username. | 0 | 3 | | length | number | A maximum length of a username | 15 | 12 | | style | lowerCase \| upperCase \| capital \| titleCase | The default value is set to lowerCase and it will return a lower case username.By setting the value to upperCase, the words will be returned in upper case.The capital option will capitalize only the first character of the full username.titleCase will capitalize each word (token). | lowerCase | lowerCase |

Additional options:

| Option | Type | Description | Default | |-----------------|--------------|-------------|---------| | exclude | string[] | Extra words to filter out | [] | | profanityList | string[] | Profanity blocklist to apply to dictionaries | built-in minimal list | | profanityOptions| { matchSubstrings?: boolean, wordBoundary?: string } | Fine-tune matching | word-boundary matching | | style | extend to: camelCase \| pascalCase \| kebabCase \| snakeCase \| titleCase | Additional output styles | lowerCase |

License

The MIT License.

Thank you

If you'd like to say thanks, I'd really appreciate a coffee :)