@ironarachne/word-generator
    Preparing search index...

    Class WordGenerator

    A word generator.

    After initializing the word generator by adding patterns to the internal patterns array, you can generate words by calling the generate method.

    import { WordGenerator } from "@ironarachne/word-generator";

    const generator = new WordGenerator();
    generator.patterns.push("vccv");
    generator.patterns.push("vccvc");

    const word = generator.generate();
    Index

    Constructors

    • Creates a new WordGenerator.

      Parameters

      • rng: RNG = ...

        Optional instance of an RNG to use.

      • customElements: default[] = []

        Optional additional or replacement custom element sets to inject.

      Returns WordGenerator

    Properties

    elements: default[]

    The active element set used to parse phonetic elements.

    patterns: string[]

    The list of generic patterns available.

    rng: RNG

    The Random Number Generator.

    Methods

    • Generates a single word based on the loaded patterns.

      Returns string

      A generated word following a randomly selected pattern.

      An Error if there are no active patterns to choose from.

    • Generates a set of example words.

      Parameters

      • count: number

        The number of unique words to generate.

      • maxAttempts: number = ...

        The maximum number of attempts to generate unique words.

      Returns Set<string>

      A Set of generated words.

    • Retrieves all loaded symbols available for pattern generation.

      Returns string[]

      An array of string symbols.

    • Retrieves all known element sets, sorted in alphabetical order by name.

      Returns default[]

      An array of all available WordElementSets.

    • Parses a pattern element into an appropriately matched phoneme.

      Parameters

      • element: string

        The symbol to parse (e.g. "v" or "c").

      Returns string

      A phonetic string corresponding to the element symbol, or the original element cast to lowercase.

    • Validates a pattern before attempting generation.

      Parameters

      • pattern: string

        The word generation pattern to validate.

      Returns boolean

      True if valid, throws if invalid.