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.

95 lines (94 loc) 2.89 kB
/** * Represents a range with minimum and maximum bounds. */ export interface IBounds { min: number; max: number; } /** * Type for a pseudo-random number generator function. */ export type IPrng = () => number; /** * Type for a seedable random number generator constructor. */ export type ISeedRandom = new (seed?: string) => IPrng; /** * Interface for math utilities with a seedable random number generator. */ export interface IMath { seedrandom: ISeedRandom; } /** * Options for configuring the `Generator` class. */ export interface IGeneratorOptions { /** * Range for the number of sentences per paragraph. */ sentencesPerParagraph?: IBounds; /** * Range for the number of words per sentence. */ wordsPerSentence?: IBounds; /** * Custom random number generator function. */ random?: IPrng; /** * Custom word list to use for generating text. */ words?: string[]; } /** * A class for generating random text (words, sentences, paragraphs). */ declare class Generator { sentencesPerParagraph: IBounds; wordsPerSentence: IBounds; random: IPrng; words: string[]; /** * Creates an instance of the `Generator` class. * * @param {IGeneratorOptions} options - Configuration options for the generator. * @throws {Error} If the minimum exceeds the maximum in the provided bounds. */ constructor({ sentencesPerParagraph, wordsPerSentence, random, words, }?: IGeneratorOptions); /** * 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;