UNPKG

mam-helpers

Version:
66 lines (65 loc) 2.67 kB
/** * Calculates the Levenshtein distance between two strings. * * Levenshtein distance, also known as edit distance, is a measure of difference between two sequences. * It's defined as the minimum number of single-character edits (insertions, deletions or substitutions) * required to change one word into the other. * * @param {string} a - The first string to compare. * @param {string} b - The second string to compare. * @returns {number} - The Levenshtein distance between the two input strings. */ export declare const getEditDistance: (a: string, b: string) => number; /** * Returns a random boolean value * * @returns {boolean} - A random boolean value. It returns true if the randomly generated number is greater or equal to 0.5, false otherwise. */ export declare const getRandomBoolean: () => boolean; /** * Generates a random number between min and max inclusive. * Throws an error if min and max are not defined or are not numbers, * or if min is greater than or equal to max. * @param {number} min - The lower bound for the random number. * @param {number} max - The upper bound for the random number. * @returns {number} - A random number between min and max inclusive. */ export declare const getRandomNumber: (min: number, max: number) => number; /** * Returns a random element from an array. * * @param {Array} array - The array to pick a random element from. * @returns {any} A random element from the array. Returns undefined if the array is empty. */ export declare const getRandomElement: <T>(array: T[]) => T | undefined; /** * Shuffles an array using Fisher-Yates algorithm. * * @param {Array} array - The array to shuffle. * @returns {Array} New array shuffled. */ export declare const shuffleArray: <T>(array: T[]) => T[]; /** * Capitalizes the first letter of a string. * * @param {string} data - The string to capitalize. * @returns {string} The capitalized string. */ export declare const capitalizeFirstLetter: (data: string) => string; /** * Capitalizes the first letter of each word in a string. * * @param {string} data - The string to capitalize. * @returns {string} The capitalized string. */ export declare const capitalizeEachWord: (data: string) => string; /** * Gets distance between 2 coordinates * * @param {number} lat1 - latitude of the first point * @param {number} lng1 - longitude of the first point * @param {number} lat2 - latitude of the second point * @param {number} lng2 - longitude of the second point * @returns {number} distance between 2 coordinates */ export declare const getHaversineDistance: (lat1: number, lng1: number, lat2: number, lng2: number) => number;