UNPKG

vegan-ipsum

Version:

Generates passages of vegan-themed placeholder text suitable for use in web pages, graphics, and more. Works in the browser, NodeJS, and React Native.

100 lines (99 loc) 2.91 kB
/** * Represents a range with minimum and maximum bounds. */ export interface Bounds { min: number; max: number; } /** * Type for a pseudo-random number generator function. */ export type Prng = () => number; /** * Type for a seedable random number generator constructor. */ export type SeedRandom = new (seed?: string) => Prng; /** * Interface for math utilities with a seedable random number generator. */ export interface Math { seedrandom: SeedRandom; } /** * Options for configuring the `Generator` class. */ export interface GeneratorOptions { /** * Range for the number of sentences per paragraph. */ sentencesPerParagraph?: Bounds; /** * Range for the number of words per sentence. */ wordsPerSentence?: Bounds; /** * Custom random number generator function. */ random?: Prng; /** * Custom word list to use for generating text. */ words?: string[]; } /** * A class for generating random text (words, sentences, paragraphs). */ declare class Generator { sentencesPerParagraph: Bounds; wordsPerSentence: Bounds; random: Prng; words: string[]; /** * Creates an instance of the `Generator` class. * * @param {GeneratorOptions} options - Configuration options for the generator. * * @throws {Error} If the minimum exceeds the maximum in the provided bounds. */ constructor({ sentencesPerParagraph, wordsPerSentence, random, words, }?: GeneratorOptions); /** * Generates a random integer between the specified minimum and maximum values. * * @param {number} min - The minimum value (inclusive). * @param {number} max - The maximum value (inclusive). * * @returns {number} A random integer between `min` and `max`. */ generateRandomInteger(min: number, max: number): number; /** * Generates a random sequence of words. * * @param {number} [num] - The number of words to generate. If not provided, a random number is used. * * @returns {string} A string of randomly generated words. */ generateRandomWords(num?: number): string; /** * Generates a random sentence. * * @param {number} [num] - The number of words in the sentence. If not provided, a random number is used. * * @returns {string} A randomly generated sentence. */ generateRandomSentence(num?: number): string; /** * Generates a random paragraph. * * @param {number} [num] - The number of sentences in the paragraph. If not provided, a random number is used. * * @returns {string} A randomly generated paragraph. */ generateRandomParagraph(num?: number): string; /** * Selects a random word from the word list. * * @returns {string} A randomly selected word. */ pluckRandomWord(): string; } export default Generator;