Generate unique and memorable names by combining words from various built-in dictionaries with flexible configuration options
npx @tessl/cli install tessl/npm-unique-names-generator@4.7.0Unique Names Generator is a tree-shakeable TypeScript library that generates unique and memorable names by combining words from various built-in dictionaries. It provides flexible configuration options including custom separators, text styling, deterministic seeding, and custom dictionaries, offering over 50 million default name combinations.
npm install unique-names-generatorimport { uniqueNamesGenerator, Config, adjectives, colors, animals, NumberDictionary } from "unique-names-generator";For CommonJS:
const { uniqueNamesGenerator, Config, adjectives, colors, animals, NumberDictionary } = require("unique-names-generator");import { uniqueNamesGenerator, adjectives, colors, animals } from "unique-names-generator";
// Generate a random name using built-in dictionaries
const randomName = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals]
}); // "big_red_donkey"
// Custom configuration
const customName = uniqueNamesGenerator({
dictionaries: [adjectives, animals],
separator: '-',
length: 2,
style: 'capital'
}); // "Big-Donkey"
// With deterministic seeding
const seededName = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
seed: 12345
}); // Always produces the same result with this seedCore function for generating unique names from dictionary combinations.
/**
* Generates a unique name based on provided configuration
* @param config - Configuration object defining dictionaries and options
* @returns Generated unique name string
* @throws Error if no dictionaries provided or invalid configuration
*/
function uniqueNamesGenerator(config: Config): string;
interface Config {
/** Array of word arrays to use for generation (required) */
dictionaries: string[][];
/** String to separate words (default: "_") */
separator?: string;
/** Number of words to generate (default: length of dictionaries array) */
length?: number;
/** Text formatting style (default: none - no transformation applied) */
style?: 'lowerCase' | 'upperCase' | 'capital';
/** Deterministic seed for consistent generation */
seed?: number | string;
}Configuration Options:
Usage Examples:
// Multiple separators
const hyphenated = uniqueNamesGenerator({
dictionaries: [adjectives, animals],
separator: '-'
}); // "clever-fox"
const spaced = uniqueNamesGenerator({
dictionaries: [colors, animals],
separator: ' '
}); // "blue elephant"
// Different styles
const lowercase = uniqueNamesGenerator({
dictionaries: [adjectives, colors],
style: 'lowerCase'
}); // "bright_green"
const uppercase = uniqueNamesGenerator({
dictionaries: [adjectives, colors],
style: 'upperCase'
}); // "BRIGHT_GREEN"
const capitalized = uniqueNamesGenerator({
dictionaries: [adjectives, colors],
style: 'capital'
}); // "Bright_Green"
// Custom dictionaries
const starWarsColors = [
['Dangerous', 'Mysterious', 'Ancient'],
['Jedi', 'Sith', 'Droid'],
['Master', 'Knight', 'Padawan']
];
const customName = uniqueNamesGenerator({
dictionaries: starWarsColors,
separator: ' ',
length: 2
}); // "Dangerous Jedi"Utility class for generating random numbers as dictionary entries.
class NumberDictionary {
/**
* Generates a string array containing a single random number
* @param config - Configuration for number generation
* @returns Array with single number string
*/
static generate(config?: Partial<NumberConfig>): string[];
}
interface NumberConfig {
/** Minimum number value (default: 1) */
min: number;
/** Maximum number value (default: 999) */
max: number;
/** Number of digits (overrides min/max if provided) */
length?: number;
}Usage Examples:
import { uniqueNamesGenerator, NumberDictionary, adjectives, animals } from "unique-names-generator";
// Generate numbers in range
const numberDict = NumberDictionary.generate({ min: 100, max: 999 });
const nameWithNumber = uniqueNamesGenerator({
dictionaries: [adjectives, animals, numberDict],
separator: ''
}); // "cleverfox847"
// Generate numbers by length
const threeDigits = NumberDictionary.generate({ length: 3 });
const codeName = uniqueNamesGenerator({
dictionaries: [['Agent'], threeDigits],
separator: '-'
}); // "Agent-247"
// Default range (1-999)
const defaultNumbers = NumberDictionary.generate();
const simpleName = uniqueNamesGenerator({
dictionaries: [animals, defaultNumbers]
}); // "elephant_42"Pre-built word collections for immediate use.
/** Array of 1400+ adjectives */
const adjectives: string[];
/** Array of 350+ animal names */
const animals: string[];
/** Array of 50+ color names */
const colors: string[];
/** Array of 250+ country names */
const countries: string[];
/** Array of 4900+ personal names */
const names: string[];
/** Array of language names */
const languages: string[];
/** Array of 80+ Star Wars character names */
const starWars: string[];Usage Examples:
// Single dictionary
const animalName = uniqueNamesGenerator({
dictionaries: [animals]
}); // "elephant"
// Multiple built-in dictionaries
const countryName = uniqueNamesGenerator({
dictionaries: [adjectives, countries],
separator: ' '
}); // "beautiful France"
const characterName = uniqueNamesGenerator({
dictionaries: [colors, starWars],
separator: ' ',
length: 2
}); // "blue Luke Skywalker"
// Mixing built-in and custom
const customAdjectives = [...adjectives, 'stellar', 'cosmic', 'quantum'];
const mixedName = uniqueNamesGenerator({
dictionaries: [customAdjectives, colors, animals]
}); // "stellar_purple_tiger"The library throws descriptive errors for invalid configurations:
// Missing dictionaries
uniqueNamesGenerator({});
// Throws: 'A "dictionaries" array must be provided...'
// Invalid length
uniqueNamesGenerator({
dictionaries: [animals, colors],
length: 5
});
// Throws: 'The length cannot be bigger than the number of dictionaries...'
// Invalid length value
uniqueNamesGenerator({
dictionaries: [animals],
length: 0
});
// Throws: 'Invalid length provided'Use seeds for reproducible results across sessions:
const config = {
dictionaries: [adjectives, colors, animals],
seed: 'my-app-user-123'
};
const name1 = uniqueNamesGenerator(config); // "continuous_gray_dragonfly"
const name2 = uniqueNamesGenerator(config); // "continuous_gray_dragonfly" (same result)
// Numeric seeds work too
const numericSeed = uniqueNamesGenerator({
dictionaries: [colors, animals],
seed: 42
}); // Always produces the same resultCombine built-in dictionaries with custom ones:
// Extend existing dictionaries
const enhancedAdjectives = [
...adjectives,
'magnificent', 'extraordinary', 'phenomenal'
];
const teamNames = [
'Team', 'Squad', 'Crew', 'Guild', 'Alliance'
];
const projectName = uniqueNamesGenerator({
dictionaries: [teamNames, enhancedAdjectives, colors],
separator: ' ',
style: 'capital'
}); // "Team Magnificent Blue"Generate different name styles for different purposes:
const baseConfig = {
dictionaries: [adjectives, animals],
seed: 'consistent-seed'
};
// Username style
const username = uniqueNamesGenerator({
...baseConfig,
separator: '_',
style: 'lowerCase'
}); // "clever_fox"
// Display name style
const displayName = uniqueNamesGenerator({
...baseConfig,
separator: ' ',
style: 'capital'
}); // "Clever Fox"
// Code name style
const codeName = uniqueNamesGenerator({
...baseConfig,
separator: '-',
style: 'upperCase'
}); // "CLEVER-FOX"