UNPKG

extra-string

Version:

A [string] is a sequence of characters.

1,097 lines (1,096 loc) 34.8 kB
/** Decimal digits 0-9. */ export declare const DIGITS: string; /** Octal digits 0-7. */ export declare const OCT_DIGITS: string; /** Hexadecimal digits 0-9, A-F, a-f. */ export declare const HEX_DIGITS: string; /** English letters A-Z. */ export declare const UPPERCASE: string; /** English letters a-z. */ export declare const LOWERCASE: string; /** Combination of uppercase, lowercase english letters. */ export declare const LETTERS: string; /** Punctuation symbols (ASCII). */ export declare const PUNCTUATION: string; /** The string "\t\n\x0b\x0c\r ". */ export declare const WHITESPACE: string; /** Combination of digits, letters, punctuation, and whitespace (ASCII). */ export declare const PRINTABLE: string; /** Minimum unicode code point. */ export declare const MIN_CODE_POINT: number; /** Maximum unicode code point. */ export declare const MAX_CODE_POINT: number; /** * Get characters whose UTF-16 code units are given. * @param codes UTF-16 code units * @returns characters */ export declare function fromCharCode(...codes: number[]): string; /** * Get characters whose unicode code points are given. * @param codes unicode code points * @returns characters */ export declare function fromCodePoint(...codes: number[]): string; /** * Combine multiple values into a string. * @param values values * @returns combined string */ export declare function concat(...values: unknown[]): string; /** * Repeat string given number of times. * @param x a string * @param times number of times * @returns repeated string */ export declare function repeat(x: string, times: number): string; /** * Get primitive value of string object. * @param x a string object * @returns primitive value */ export declare function valueOf(x: string): string; /** * Get length of string. * @param x a string * @returns length of string */ export declare function length(x: string): number; export { length as size }; /** * Get character at given index in string. * @param x a string * @param at character index * @return character */ export declare function charAt(x: string, at: number): string; /** * Get UTF-16 code unit of a character in string. * @param x a string * @param at character index * @returns UTF-16 code unit */ export declare function charCodeAt(x: string, at: number): number; /** * Get unicode code point of a character in string. * @param x a string * @param at character index * @returns unicode code point */ export declare function codePointAt(x: string, at: number): number | undefined; /** * Compare two strings in the current or given locale. * @param x a string * @param y another string * @param locales language or locale tag(s) * @param options comparison options * @returns x<y: -ve, x=y: 0, x>y: +ve * @example * ```javascript * xstring.localeCompare('abra', 'bulbasaur'); * // → -1 * * xstring.localeCompare('bulbasaur', 'bulbasaur'); * // → 0 * * xstring.localeCompare('charmeleon', 'bulbasaur'); * // → 1 * ``` */ export declare function localeCompare(x: string, y: string, locales?: string | string[], options?: Intl.CollatorOptions): number; /** * Check if string has a given infix. * @param x a string * @param infix infix to look for * @param start start index [0] * @returns has infix? */ export declare function includes(x: string, infix: string, start?: number): boolean; /** * Check if string has a given prefix. * @param x a string * @param prefix prefix to look for * @param start start index [0] * @returns has prefix? */ export declare function startsWith(x: string, prefix: string, start?: number): boolean; /** * Check if string has a given suffix. * @param x a string * @param suffix suffix to look for * @param end end index [end] * @returns has suffix? */ export declare function endsWith(x: string, suffix: string, end?: number): boolean; /** * Get first index of a given infix in string. * @param x a string * @param infix infix to look for * @param start start index [0] * @returns first index of infix */ export declare function indexOf(x: string, infix: string, start?: number): number; /** * Get last index of a given infix in string. * @param x a string * @param infix infix to look for * @param rstart reverse start index [end-1] * @returns last index of infix */ export declare function lastIndexOf(x: string, infix: string, rstart?: number): number; /** * Get first index of regular expression match in string. * @param x a string * @param regexp regular expression * @returns first index of match */ export declare function search(x: string, regexp: string | RegExp): number; /** * Get results of matching string with regular expression. * @param x a string * @param regexp regular expression * @returns /g: all matches, else: match with capturing groups or null */ export declare function match(x: string, regexp: string | RegExp): RegExpMatchArray | null; /** * Get detailed results of matching string with regular expression. * @param x a string * @param regexp regular expression (with /g) * @returns match with capturing groups ... */ export declare function matchAll(x: string, regexp: RegExp): IterableIterator<RegExpMatchArray>; /** * Get string representation of string. * @param x a string * @returns string representation */ export declare function toString(x: string): string; /** * Extract section of string. * @param x a string * @param start start index (-ve ⇒ from right) [0] * @param end end index (-ve ⇒ from right) [end] * @returns section of string */ export declare function slice(x: string, start?: number, end?: number): string; /** * Extract section of string. * @param x a string * @param start start index (-ve ⇒ 0) [0] * @param end end index (-ve ⇒ 0) [end] * @returns section of string */ export declare function substring(x: string, start: number, end?: number): string; /** * Split string by a given separator into substrings. * @param x a string * @param separator separator string or regular expression * @param limit maximum number of substrings * @returns substrings */ export declare function split(x: string, separator?: string | RegExp, limit?: number): string[]; /** * Remove whitespace from begining of string. * @param x a string * @returns trimmed string */ export declare function trimStart(x: string): string; /** * Remove whitespace from end of string. * @param x a string * @returns trimmed string */ export declare function trimEnd(x: string): string; /** * Remove whitespace from begining and end of string. * @param x a string * @returns trimmed string */ export declare function trim(x: string): string; /** * Pad start of string to fit a desired length. * @param x a string * @param length desired length * @param padding pad with [ ] * @returns padded string */ export declare function padStart(x: string, length: number, padding?: string): string; /** * Pad end of string to fit a desired length. * @param x a string * @param length desired length * @param padding pad with [ ] * @returns padded string */ export declare function padEnd(x: string, length: number, padding?: string): string; /** * Convert string to upper case. * @param x a string * @returns upper cased string */ export declare function toUpperCase(x: string): string; /** * Convert string to upper case, as per locale-specific case mappings. * @param x a string * @param locales BCP 47 language tag(s) * @returns upper cased string */ export declare function toLocaleUpperCase(x: string, locales?: string | string[]): string; /** * Convert string to lower case. * @param x a string * @returns lower cased string */ export declare function toLowerCase(x: string): string; /** * Convert string to lower case, as per locale-specific case mappings. * @param x a string * @param locales BCP 47 language tag(s) * @returns lower cased string */ export declare function toLocaleLowerCase(x: string, locales?: string | string[]): string; /** Handle replacement of matched string and parameters with another string. */ export type ReplaceFunction = (substring: string, ...args: unknown[]) => string; /** * Replace first match of given pattern by replacement. * @param x a string * @param pattern substring to match * @param replacement replacement substring * @returns replaced string */ export declare function replace(x: string, pattern: string, replacement: string): string; /** * Replace first or all matches of given pattern by replacement. * @param x a string * @param pattern pattern to match * @param replacement replacement substring or replacer * @returns replaced string */ export declare function replace(x: string, pattern: string | RegExp, replacement: string | ReplaceFunction): string; /** * Normalize string by given form, as per Unicode Standard Annex #15. * @param x a string * @param form normalization form (NFC, NFD, NFKC, NFKD) * @returns normalized string */ export declare function normalize(x: string, form?: string): string; /** * Create string from arguments, like `Array.of()`. * @param args arguments * @returns p + q + ... | [p, q, ...] = args * @example * ```javascript * xstring.of('a', 1); * // → 'a1' * * xstring.of(1, 2); * // → '12' * * xstring.of(); * // → '' * ``` */ export declare function of(...args: string[]): string; /** * Handle transformation of a substring (or character) to another. * @param v a substring (or character) * @param i index of substring * @param x string containing the substring * @returns transformed substring */ export type MapFunction = (v: string, i: number, x?: string) => string; /** * Create string from iterable, like `Array.from()`. * @param xs list of strings (iterable) * @param fm map function (x, i) * @param ths this argument * @returns p + q + ... | [p, q, ...] = xs * @example * ```javascript * xstring.from(['a', 'b']); * // → 'ab' * * xstring.from('abc', (v) => String.fromCharCode(v.charCodeAt()+1)); * // → 'bcd' * * xstring.from(new Set().add('a').add('b')); * // → 'ab' * * xstring.from(new Map().set('a', 1).set('b', 2)); * // → 'a,1b,2' * ``` */ export declare function from(xs: Iterable<string>, fm?: MapFunction, ths?: unknown): string; /** * Remove/replace characters in a string. * @param x a string * @param start start index * @param remove number of characters to remove * @param add substring to add * @returns x[0:i] + add + x[i+r] | i = start, r = remove */ export declare function splice(x: string, start: number, remove?: number, add?: string): string; /** * Reverse a string. * @param x a string * @returns reversed string */ export declare function reverse(x: string): string; /** * Handle comparison of two strings. * @param a a string * @param b another string * @returns x<y: -ve, x=y: 0, x>y: +ve */ export type CompareFunction = (a: string, b: string) => number; /** * Arrange characters in an order. * @param x a string * @param fc compare function (a, b) */ export declare function sort(x: string, fc?: CompareFunction): string; /** * Handle selection of a substring (or character) in string. * @param v a substring (or character) * @param i index of substring in string * @param x string containing the substring * @returns whether it is selected */ export type TestFunction = (v: string, i: number, x: string) => boolean; /** * Filter characters which pass a test. * @param x a string * @param ft test function (v, i, x) * @param ths this argument * @returns characters which pass the test * @example * ```javascript * xstring.filter('g00df00d', (v) => v<='f'); * // → '00df00d' * * xstring.filter('badfood', (v) => v<='f'); * // → 'badfd' * * xstring.filter('', (v) => v<='f'); * // → '' * ``` */ export declare function filter(x: string, ft: TestFunction, ths?: unknown): string; /** * Get a string of spaces. * @param n number of spaces * @returns string of spaces * @example * ```javascript * xstring.spaces(4); * // → ' ' * * xstring.spaces(6); * // → ' ' * * xstring.spaces(0); * // → '' * * xstring.spaces(-1); * // → '' * ``` */ export declare function spaces(n: number): string; /** * Check if value is a string. * @param v a value * @returns whether value is a string * @example * ```javascript * xstring.is('panini'); * // → true * * xstring.is("valmiki"); * // → true * * xstring.is(String('vyasa')); * // → true * * xstring.is({shakespeare: 'literature'}); * // → false * * xstring.is(71811313518); * // → false (what's this?) * * xstring.is(); * // → false * ``` */ export declare function is(v: unknown): boolean; /** * Check if string is empty. * @param x a string * @returns whether string is empty */ export declare function isEmpty(x: string): boolean; /** * Check if string is a character. * @param x a string * @returns whether string is a character */ export declare function isCharacter(x: string): boolean; /** * Get non-negative index within string. * @param x a string * @param at character index * @returns +ve index */ export declare function index(x: string, at: number): number; /** * Get non-negative index range within string. * @param x a string * @param start start index * @param end end index * @returns +ve index range [start, end] */ export declare function indexRange(x: string, start: number, end: number): [number, number]; /** * Get unicode code point range of string. * @param x a string * @returns code point range [min, max] */ export declare function codePointRange(x: string): [number, number]; /** * Compare two strings. * @param x a string * @param y another string * @returns x<y: -ve, x=y: 0, x>y: +ve */ export declare function compare(x: string, y: string): number; /** * Check if two strings are equal. * @param x a string * @param y another string * @returns x=y? */ export declare function isEqual(x: string, y: string): boolean; export { startsWith as isPrefix }; export { endsWith as isSuffix }; export { includes as isInfix }; /** * Get character at a given index in string. * @param x a string * @param at character index (-ve ⇒ from right) * @returns x[i] | i = at */ export declare function get(x: string, at: number): string; export { get as at }; /** * Get characters at indices. * @param x a string * @param ats character indices (-ve ⇒ from right) * @returns x[i] + x[j] + ... | [i, j, ...] = ats */ export declare function getAll(x: string, ats: Iterable<number>): string; /** * Write a substring at specified index in string. * @param x a string * @param at write index (-ve ⇒ from right) * @param write substring to write * @returns x[0:i] + w + x[i+|w|:] | i = at, w = write */ export declare function set(x: string, at: number, write: string): string; /** * Get leftmost part of string. * @param x a string * @param count number of characters [1] * @returns x[0:n] | n = count * @example * ```javascript * xstring.begin('Thai Sweet Chilli Sauce', 4); * // → 'Thai' * * xstring.begin('Thai Sweet Chilli Sauce', 10); * // → 'Thai Sweet' * * xstring.begin('Thai Sweet Chilli Sauce', 80); * // → 'Thai Sweet Chilli Sauce' * * xstring.begin('Thai Sweet Chilli Sauce', -1); * // → '' * ``` */ export declare function begin(x: string, count?: number): string; export { begin as prefix }; export { begin as left }; /** * Get a portion of string from middle. * @param x a string * @param start start index * @param count number of characters [1] * @returns x[i:i+n] | i = start, n = count * @example * ```javascript * xstring.mid('Thai Sweet Chilli Sauce', 5, 5); * // → 'Sweet' * * xstring.mid('Thai Sweet Chilli Sauce', 5, 12); * // → 'Sweet Chilli' * * xstring.mid('Thai Sweet Chilli Sauce', 5); * // → 'Sweet Chilli Sauce' * * xstring.mid('Thai Sweet Chilli Sauce', 5, -1); * // → '' * * xstring.mid('Thai Sweet Chilli Sauce', -5); * // → 'Sauce' * ``` */ export declare function middle(x: string, start: number, count?: number): string; export { middle as infix }; /** * Get rightmost part of string. * @param x a string * @param count number of characters [1] * @returns x[|x|-n:] | n = count * @example * ```javascript * xstring.end('Thai Sweet Chilli Sauce', 5); * // → 'Sauce' * * xstring.end('Thai Sweet Chilli Sauce', 12); * // → 'Chilli Sauce' * * xstring.end('Thai Sweet Chilli Sauce', 80); * // → 'Thai Sweet Chilli Sauce' * * xstring.end('Thai Sweet Chilli Sauce', -1); * // → '' * ``` */ export declare function end(x: string, count?: number): string; export { end as suffix }; export { end as right }; /** * Get the longest common infix between strings. * @param x a string * @param y another string * @returns longest common infix * @example * ```javascript * xstring.longestCommonInfix('mangala', 'mangalyaan'); * // → 'mangal' * * xstring.longestCommonInfix('easter', 'tertiary'); * // → 'ter' * * xstring.longestCommonInfix('dismiss', 'mississipi'); * // → 'miss' * ``` */ export declare function longestCommonInfix(x: string, y: string): string; /** * Get the longest common prefix of strings. * @param x a string * @param y another string * @returns longest common prefix * @example * ```javascript * xstring.longestCommonPrefix('peacock', 'peahen'); * // → 'pea' * * xstring.longestCommonPrefix('inception', 'interstellar'); * // → 'in' * * xstring.longestCommonPrefix('mars', 'tars'); * // → '' * ``` */ export declare function longestCommonPrefix(x: string, y: string): string; /** * Get the longest common suffix of strings. * @param x a string * @param y another string * @returns longest common suffix * @example * ```javascript * xstring.longestCommonSuffix('peacock', 'hancock'); * // → 'cock' * * xstring.longestCommonSuffix('mars', 'tars'); * // → 'ars' * * xstring.longestCommonSuffix('chief', 'master'); * // → '' * ``` */ export declare function longestCommonSuffix(x: string, y: string): string; /** * Get the longest uncommon infixes of strings. * @param x a string * @param y another string * @returns [infix1, infix2] * @example * ```javascript * xstring.longestUncommonInfixes('rollcage', 'ridecage'); * // → ['oll', 'ide'] * * xstring.longestUncommonInfixes('riverbed', 'roverbed'); * // → ['i', 'o'] * * xstring.longestUncommonInfixes('chocolatier', 'engineer'); * // → ['chocolati', 'engine'] * ``` */ export declare function longestUncommonInfixes(x: string, y: string): [string, string]; /** * Convert a string to baseline characters (limited support). * @param x a string * @param fsup map function for superscript characters (v, i, x) * @param fsub map function for subscript characters (v, i, x) * @returns baselined string * @example * ```javascript * xstring.toBaseline('ax²+bx+c'); * // → 'ax2+bx+c' * * xstring.toBaseline('H₂SO₄ beaker'); * // → 'H2SO4 beaker' * * xstring.toBaseline('6.626 x 10⁻³⁴', ['^']); * // → '6.626 x 10^-34' * * xstring.toBaseline('1010₂', null, [' (base-', ')']); * // → '1010 (base-2)' * ``` */ export declare function toBaseline(x: string, fsup?: MapFunction | null, fsub?: MapFunction | null): string; /** * Convert a string to superscript characters (limited support). * @param x a string * @returns superscripted characters * @example * ```javascript * xstring.toSuperscript('hello world'); * // → 'ʰᵉˡˡᵒ ʷᵒʳˡᵈ' * * xstring.toSuperscript('DECCAN PLATEAU'); * // → 'ᴰᴱCCᴬᴺ ᴾᴸᴬᵀᴱᴬᵁ' * * '6.626 x 10' + xstring.toSuperscript('-34'); * // → '6.626 x 10⁻³⁴' (Planck's constant) * ``` */ export declare function toSuperscript(x: string): string; /** * Convert a string to superscript characters (limited support). * @param x a string * @returns superscripted characters * @example * ```javascript * xstring.toSubscript('hello world'); * // → 'ₕₑₗₗₒ wₒᵣₗd' * * xstring.toSubscript('DECCAN PLATEAU'); * // → 'DECCAN PLATEAU' * * 'KNO' + xstring.toSubscript('3'); * // → 'KNO₃' (Potassium Nitrate) * ``` */ export declare function toSubscript(x: string): string; /** * Split a string into words, after de-casing it. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @returns words in the string * @example * ```javascript * xstring.toWords('Malwa Plateau'); * // → ['Malwa', 'Plateau'] * * xstring.toWords('::chota::nagpur::'); * // → ['chota', 'nagpur'] * * xstring.toWords('deccan___plateau'); * // → ['deccan', 'plateau'] * * xstring.toWords('westernGhats'); * // → ['western', 'Ghats'] * * xstring.toWords('parseURLToJSON'); * // → ['parse', 'URL', 'To', 'JSON'] */ export declare function toWords(x: string, re?: RegExp | null): string[]; /** * Convert a string to title-case. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @returns Title Case * @example * ```javascript * xstring.toTitleCase('Geminid meteor shower'); * // → 'Geminid Meteor Shower' * * xstring.toTitleCase('deccan___plateau'); * // → 'Deccan Plateau' * * xstring.toTitleCase('parseURLToJSON', null, '_'); * // → 'Parse_URL_To_JSON' * ``` */ export declare function toTitleCase(x: string, re?: RegExp | null, sep?: string): string; /** * Convert a string to kebab-case. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @param sep separator to join with [-] * @returns kebab-case | kebab<join>case */ export declare function toKebabCase(x: string, re?: RegExp | null, sep?: string): string; /** * Convert a string to snake-case. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @returns snake_case * @example * ```javascript * xstring.toSnakeCase('Malwa Plateau'); * // → 'malwa_plateau' * * xstring.toSnakeCase('::chota::nagpur::', '-'); * // → 'chota-nagpur' * * xstring.toSnakeCase('deccan___plateau', '.', '_'); * // → 'deccan.plateau' * ``` */ export declare function toSnakeCase(x: string, re?: RegExp | null): string; /** * Convert a string to camel-case. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @param upper upper camel case? * @returns camelCase | CamelCase * @example * ```javascript * xstring.toCamelCase('Western Ghats'); * // → 'westernGhats' * * xstring.toCamelCase('cardamom--hills', 1); * // → 'CardamomHills' * * xstring.toCamelCase('EAstErn__ghAts', 1, '_'); * // → 'EasternGhats' * ``` */ export declare function toCamelCase(x: string, re?: RegExp | null, upper?: boolean): string; /** * Convert a string to pascal-case. * @param x a string * @param re word seperator pattern [/[^0-9A-Za-z]+/g] * @returns PascalCase */ export declare function toPascalCase(x: string, re?: RegExp | null): string; /** * Convert a string to slug-case (URL-friendly kebab-case). * @param x a string * @param re word separator pattern [/[^0-9A-Za-z]+/g] * @param sep separator to join with [-] * @returns slug-case | slug<join>case */ export declare function toSlugCase(x: string, re?: RegExp | null, sep?: string): string; export { toSlugCase as slugify }; /** * Get characters that cycle through string. * @param x a string * @param start start index * @param count number of characters [length] */ export declare function cycle(x: string, start: number, count?: number): string; /** * Rotate characters in string. * @param x a string * @param n rotate amount (+ve: left, -ve: right) */ export declare function rotate(x: string, n: number): string; /** * Breaks string at given indices. * @param x a string * @param is split indices (sorted) */ /** * Breaks string after given indices. * @param x a string * @param is split indices (sorted) */ /** * Gives characters present in any string. * @param x a string * @param y another string * @param fc compare function (a, b) * @param fm map function (v, i, x) */ /** * Get n-grams of a string. * @param x a string * @param n n-gram length * @returns [x[0:n], x[1:n+1], ...] * @example * ```javascript * xstring.ngrams('card', 2); * // → ['ca', 'ar', 'rd'] * * xstring.ngrams('triple-h', 3); * // → ['tri', 'rip', 'ipl', 'ple', 'le-', 'e-h'] * * xstring.ngrams('brocklesner', 10); * // → ['brocklesne', 'rocklesner'] * ``` */ export declare function ngrams(x: string, n: number): string[]; /** * Find unique n-grams of a string. * @param x a string * @param n n-gram length * @returns Set \{gᵢ\} | gᵢ = iᵗʰ n-gram */ export declare function uniqueNgrams(x: string, n: number): Set<string>; /** * Count the total number of n-grams of a string. * @param x a string * @param n n-gram length * @returns |gᵢ| | gᵢ = iᵗʰ n-gram */ export declare function countNgrams(x: string, n: number): number; /** * Count the total number of unique n-grams of a string. * @param x a string * @param n n-gram length * @returns |Set \{gᵢ\}| | gᵢ = iᵗʰ n-gram */ export declare function countUniqueNgrams(x: string, n: number): number; /** * Count each n-gram of a string. * @param x a string * @param n n-gram length * @returns Map \{gᵢ: count(gᵢ)\} | gᵢ = iᵗʰ n-gram */ export declare function countEachNgram(x: string, n: number): Map<string, number>; /** * Get matching n-grams between strings. * @param x a string * @param y another string * @param n n-gram length * @returns [gᵢ] | gᵢ = iᵗʰ matching n-gram * @example * ```javascript * xstring.matchingNgrams('worm', 'storm', 2); * // → ['or', 'rm'] * * xstring.matchingNgrams('astronaut', 'astronomer', 3); * // → ['ast', 'str', 'tro', 'ron'] * * xstring.matchingNgrams('coconut', 'cotton', 2); * // → ['co', 'on'] * ``` */ export declare function matchingNgrams(x: string, y: string, n: number): string[]; /** * Get unique matching n-grams between strings. * @param x a string * @param y another string * @param n n-gram length * @returns Set \{gᵢ\} | gᵢ = iᵗʰ unique matching n-gram */ export declare function uniqueMatchingNgrams(x: string, y: string, n: number): Set<string>; /** * Count the total number of matching n-grams between strings. * @param x a string * @param y another string * @param n n-gram length * @returns |[gᵢ]| | gᵢ = iᵗʰ matching n-gram * @example * ```javascript * xstring.countMatchingNgrams('worm', 'storm', 2); * // → 2 ('or', 'rm') * * xstring.countMatchingNgrams('astronaut', 'astronomer', 3); * // → 4 ('ast', 'str', 'tro', 'ron') * * xstring.countMatchingNgrams('coconut', 'cotton', 2); * // → 2 ('co', 'on') * ``` */ export declare function countMatchingNgrams(x: string, y: string, n: number): number; /** * Count each matching n-gram between strings. * @param x a string * @param y another string * @param n n-gram length * @returns Map \{gᵢ: count(gᵢ)\} | gᵢ = iᵗʰ matching n-gram */ export declare function countEachMatchingNgram(x: string, y: string, n: number): Map<string, number>; /** * Count the total number of unique matching n-grams between strings. * @param x a string * @param y another string * @param n n-gram length * @returns |Set \{gᵢ\}| | gᵢ = iᵗʰ unique matching n-gram */ export declare function countUniqueMatchingNgrams(x: string, y: string, n: number): number; /** * Get euclidean distance between strings. * @param x a string * @param y another string * @returns euclidean distance * @example * ```javascript * xstring.euclideanDistance('a', 'b'); * // → 1 * * xstring.euclideanDistance('logo', 'pogo'); * // → 4 * * xstring.euclideanDistance('doctor', 'broker'); * // → 18.384776310850235 * ``` */ export declare function euclideanDistance(x: string, y: string): number; /** * Get hamming distance between strings. * @param x a string * @param y another string * @returns hamming distance * @example * ```javascript * xstring.hammingDistance('rowan', 'raven'); * // → 3 * * xstring.hammingDistance('atkinson', 'atkinson'); * // → 0 * * xstring.hammingDistance('bean', 'green'); * // → NaN (strings are of different length) * ``` */ export declare function hammingDistance(x: string, y: string): number; /** * Get jaccard index between strings. * @param x a string * @param y another string * @param n n-gram length * @returns |X ∩ Y|/|X ∪ Y| | X,Y = n-grams of x,y * @example * ```javascript * xstring.jaccardIndex('pocket', 'pocket'); * // → 1 * * xstring.jaccardIndex('monster', 'rocket'); * // → 0 * * xstring.jaccardIndex('pikachu', 'raichu', 3); * // → 0.125 * ``` */ export declare function jaccardIndex(x: string, y: string, n: number): number; /** * Get jaccard distance between strings. * @param x a string * @param y another string * @param n n-gram length * @returns 1 - jaccardIndex(x, y) * @example * ```javascript * xstring.jaccardDistance('pocket', 'pocket'); * // → 0 * * xstring.jaccardDistance('monster', 'rocket'); * // → 1 * * xstring.jaccardDistance('pikachu', 'raichu', 3); * // → 0.875 * ``` */ export declare function jaccardDistance(x: string, y: string, n: number): number; /** * Get Sørensen-Dice index between strings. * @param x a string * @param y another string * @param n n-gram length * @returns 2|X ∩ Y|/(|X| + |Y|) | X,Y = n-grams of x,y * @example * ```javascript * xstring.sorensenDiceIndex('pocket', 'pocket'); * // → 1 * * xstring.sorensenDiceIndex('monster', 'rocket'); * // → 0 * * xstring.sorensenDiceIndex('pikachu', 'raichu', 3); * // → 0.2222222222222222 * ``` */ export declare function sorensenDiceIndex(x: string, y: string, n: number): number; /** * Get Sørensen-Dice distance between strings. * @param x a string * @param y another string * @param n n-gram length * @returns 1 - sorensenDiceIndex(x, y) * @example * ```javascript * xstring.sorensenDiceDistance('pocket', 'pocket'); * // → 0 * * xstring.sorensenDiceDistance('monster', 'rocket'); * // → 1 * * xstring.sorensenDiceDistance('pikachu', 'raichu', 3); * // → 0.7777777777777778 * ``` */ export declare function sorensenDiceDistance(x: string, y: string, n: number): number; /** * Get Tversky index between strings. * @param x a string * @param y another string * @param n n-gram length * @param a alpha [1] * @param b beta [1] * @returns |X ∩ Y|/(|X ∩ Y| + α|X \ Y| + β|Y \ X|) | X,Y = n-grams of x,y * @example * ```javascript * xstring.tverskyIndex('pocket', 'pocket'); * // → 1 * * xstring.tverskyIndex('monster', 'rocket'); * // → 0 * * xstring.tverskyIndex('pikachu', 'raichu', 0.2, 0.4, 3); * // → 0.3333333333333333 * ``` */ export declare function tverskyIndex(x: string, y: string, n: number, a?: number, b?: number): number; /** * Get Tversky distance between strings. * @param x a string * @param y another string * @param n n-gram length * @param a alpha [1] * @param b beta [1] * @returns 1 - tverskyIndex(x, y) * @example * ```javascript * xstring.tverskyDistance('pocket', 'pocket'); * // → 0 * * xstring.tverskyDistance('monster', 'rocket'); * // → 1 * * xstring.tverskyDistance('pikachu', 'raichu', 0.2, 0.4, 3); * // → 0.6666666666666667 * ``` */ export declare function tverskyDistance(x: string, y: string, n: number, a?: number, b?: number): number; /** * Get Jaro similarity between strings. * @param x a string * @param y another string * @returns (m/|x| + m/|y| + (m-t)/m)/3 | m = # matches, t = # transpositions * @example * ```javascript * xstring.jaroSimilarity('no', 'match'); * // → 0 * * xstring.jaroSimilarity('teapot', 'teapot'); * // → 1 * * xstring.jaroSimilarity('jellyfish', 'smellyfish'); * // → 0.8962962962962964 * ``` */ export declare function jaroSimilarity(x: string, y: string): number; /** * Get Jaro distance between strings. * @param x a string * @param y another string * @returns 1 - jaroSimilarity(x, y) * @example * ```javascript * xstring.jaroDistance('no', 'match'); * // → 1 * * xstring.jaroDistance('teapot', 'teapot'); * // → 0 * * xstring.jaroDistance('jellyfish', 'smellyfish'); * // → 0.10370370370370363 * ``` */ export declare function jaroDistance(x: string, y: string): number; /** * Get Jaro-Winkler similarity between strings. * @param x a string * @param y another string * @param p scaling factor for common prefix (0.1 - 0.25) [0.1] * @returns simⱼ + ℓp(1 - simⱼ) | simⱼ = jaro similarity, ℓ = |longest common prefix| * @example * ```javascript * xstring.jaroWinklerSimilarity('no', 'match'); * // → 0 * * xstring.jaroWinklerSimilarity('teapot', 'teapot'); * // → 1 * * xstring.jaroWinklerSimilarity('jelly', 'jellyfish'); * // → 0.9111111111111111 * ``` */ export declare function jaroWinklerSimilarity(x: string, y: string, p?: number): number; /** * Get Jaro-Winkler distance between strings. * @param x a string * @param y another string * @param p scaling factor for common prefix (0.1 - 0.25) [0.1] * @returns 1 - jaroWinklerSimilarity(x, y) * @example * ```javascript * xstring.jaroWinklerDistance('no', 'match'); * // → 1 * * xstring.jaroWinklerDistance('teapot', 'teapot'); * // → 0 * * xstring.jaroWinklerDistance('jelly', 'jellyfish'); * // → 0.0888888888888889 * ``` */ export declare function jaroWinklerDistance(x: string, y: string, p?: number): number; /** * Get Levenshtein distance between strings. * @param x a string * @param y another string * @param ins insertion cost [1] * @param del deletion cost [1] * @param sub substitution cost [1] * @returns levenshtein distance * @example * ```javascript * xstring.levenshteinDistance('hareram', 'hareram'); * // → 0 * * xstring.levenshteinDistance('church', 'torch'); * // → 3 * * xstring.levenshteinDistance('mr. bean', 'ben 10', 1, 0.1, 1); * // → 3.5 * ``` */ export declare function levenshteinDistance(x: string, y: string, ins?: number, del?: number, sub?: number): number; /** * Get Damerau–Levenshtein distance between strings. * @param x a string * @param y another string * @param ins insertion cost [1] * @param del deletion cost [1] * @param sub substitution cost [1] * @param tra transposition cost [1] * @returns damerau–levenshtein distance * @example * ```javascript * xstring.damerauLevenshteinDistance('gnu', 'gun'); * // → 1 * * xstring.damerauLevenshteinDistance('software', 'softwear'); * // → 2 * * xstring.damerauLevenshteinDistance('level field', 'lvele feidl', 1, 1, 1, 0.1); * // → 0.4 * ``` */ export declare function damerauLevenshteinDistance(x: string, y: string, ins?: number, del?: number, sub?: number, tra?: number): number;