nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
27 lines (26 loc) • 1.32 kB
TypeScript
import type { TupleOf } from '../utils/types';
/**
* Calculates the similarity between two strings using the Levenshtein edit distance.
*
* @param str1 The first string to compare.
* @param str2 The second string to compare.
* @returns A score between `0` and `1`, where `1` means identical and `0` means completely different.
*/
export declare function _calculateSimilarity(str1: string, str2: string): number;
/**
* Builds an LCS (Longest Common Subsequence) table for two strings at the character level.
*
* @param original The original string.
* @param modified The modified string.
* @returns A 2D matrix where each cell `[i][j]` holds the LCS length of `original[0..i-1]` and `modified[0..j-1]`.
*/
export declare function _buildCharLcsTable(original: string, modified: string): number[][];
/**
* Backtracks through an LCS table to extract matched character indices in both strings.
*
* @param original The original string.
* @param modified The modified string.
* @param lcs The precomputed LCS table from {@link buildCharLcsTable}.
* @returns A tuple `[origMatched, modMatched]` — sets of matched character indices for the original and modified strings respectively.
*/
export declare function _getLcsIndices(original: string, modified: string, lcs: number[][]): TupleOf<Set<number>, 2>;