/** * Miscellaneous utility functions * * @copyright (c) Aaron Wells 2019 * @author Aaron Wells */ /** * Generate a predictable but randomish number generator. Specifically, this is * the algorithm known as "MINSTD" * * @see https://en.wikipedia.org/wiki/Lehmer_random_number_generator#cite_ref-6 * @description * * Inspired by https://gist.github.com/blixt/f17b47c62508be59987b * * Returns a rand() function that can be called repeatedly to get the same * sorta-random-seeming sequence of integers each time. * * @param {number} [initialSeed = 1] * @returns {() => number} */ export declare function getRandFn(initialSeed?: number): () => number; export declare namespace getRandFn { var PSEUDO_RAND_MAX: number; } /** * * @param {string} letter */ export declare function isUpperCase(letter: string): boolean; /** * A helper function equivalent to the "SSUB/SESUB" macro in the original. It creates * a regex replace callback method, which will make sure the replacement text * has the same initial capitalization as the original text. * @param {string} match * @param {string} replacement */ export declare function sameCap(match: string, replacement: string): string; /** * Creates a String.prototype.replace() callback method, which will make sure * the replacement text has the same initial capitalization as the original text. * (Equivalent to SSUB/SESUB macro in the Lexer based scripts) * * @param {string} replacement * @return {(match: string) => string} */ export declare function sameCapReplacer(replacement: string): (match: string) => string; declare type SimulexUtils = { rand: () => number; }; export declare type SimulexReplacerFn = (match: string, util: U & SimulexUtils) => string; export declare type SimulexRule = [RegExp, SimulexReplacerFn]; export declare type SimulexRawRule = [string, SimulexReplacerFn]; /** * Simulates the operation of the Lex parser. * @param originalString * @param rules An array of `[RegExp, replacerFn] tuples. For any * string that matches the RegExp, it will transform it using the replacerFn. * The replaceFn will be passed a "util" object that contains a seeded prng, * and anything from `extraUtils` * @param extraUtils * @returns */ export declare function simuLex(originalString: string, rules: SimulexRule[], extraUtils?: U): string; export declare namespace simuLex { var preprocessRules: (rawRules: SimulexRawRule[]) => SimulexRule[]; } /** * Emulates perl's tr/// aka y/// "translate" operator. * @see https://perldoc.perl.org/perlop.html#Quote-Like-Operators * @param {string} initialString * @param {string} searchList * @param {string} replacementList */ export declare function tr(initialString: string, searchList: string, replacementList: string): string; export {};