foswig
Version:
A library that can generate legible pseudo random words based off an input dictionary using markov chains
40 lines (39 loc) • 1.61 kB
TypeScript
/**
@license Foswig.js | (c) Glenn Conner. | https://github.com/mrsharpoblunto/foswig.js/blob/master/LICENSE
@format
*/
declare type RandomGenerator = () => number;
export default class MarkovChain {
private order;
private duplicates;
private start;
/**
* order indicates how many previous characters to take into account when picking the next. A lower number represents more random words, whereas a higher number will result in words that match the input words more closely.
*/
constructor(order: number, words: Array<string>);
private init;
/**
* Adds a word and all its substrings to a duplicates trie to
* ensure that generated words are never an exact match or substring
* of a word in the input dictionary. Building a trie allows us
* to efficiently search for these duplicates later without
* having to do O(N) comparision checks over the entire dictionary
*/
private addToDuplicatesTrie;
/**
* Check to see if a word is a match to any substring in the input
* dictionary in O(N) time, where N is the number of characters in the
* word rather than the number of words in the dictionary.
* @param {string} word The word we want to find out whether it is a
* duplicate of a substring in the input dictionary.
*/
private isDuplicate;
generate({ minLength, maxLength, allowDuplicates, maxAttempts, random, }: {
minLength?: number;
maxLength?: number;
allowDuplicates?: boolean;
maxAttempts?: number;
random?: RandomGenerator;
}): string;
}
export {};