CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-unique-names-generator

Generate unique and memorable names by combining words from various built-in dictionaries with flexible configuration options

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Unique Names Generator

Unique 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.

Package Information

  • Package Name: unique-names-generator
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install unique-names-generator

Core Imports

import { uniqueNamesGenerator, Config, adjectives, colors, animals, NumberDictionary } from "unique-names-generator";

For CommonJS:

const { uniqueNamesGenerator, Config, adjectives, colors, animals, NumberDictionary } = require("unique-names-generator");

Basic Usage

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 seed

Capabilities

Name Generation

Core 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:

  • dictionaries (required): Array of string arrays. Each sub-array contains words for that position
  • separator: Custom separator between words (default: "_"). Can be any string, emoji, or word
  • length: Number of words to include (must be ≤ number of dictionaries provided)
  • style: Text formatting - 'lowerCase', 'upperCase', 'capital', or none (default: undefined, no transformation)
  • seed: Number or string for deterministic generation

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"

Dynamic Number Generation

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"

Built-in Dictionaries

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"

Error Handling

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'

Advanced Usage Patterns

Deterministic Generation

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 result

Complex Dictionary Combinations

Combine 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"

Multiple Configurations

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"

docs

index.md

tile.json