[READ-ONLY] Mirror of https://github.com/FoxxMD/string-sameness. Compare the sameness of two strings foxxmd.github.io/string-sameness/
compare cosine-similarity dice-coefficient levenshtein-distance sameness string text typescript
0

Configure Feed

Select the types of activity you want to include in your feed.

string-sameness / src / atomic.ts
2.4 kB 77 lines
1export interface StringComparisonOptions { 2 /** 3 * An array of transformations to apply to each string before comparing similarity 4 * */ 5 transforms?: StringTransformFunc[] 6 /** 7 * An array of strategies used to score similarity. All strategies scores are combined for an average high score. 8 * */ 9 strategies?: ComparisonStrategy<ComparisonStrategyResultValue>[] 10 /** 11 * Reorder second string so its token match order of first string as closely as possible 12 * 13 * Useful when only the differences in content are important, but not the order of the content 14 * */ 15 reorder?: boolean 16 17 /** 18 * When `reorder` is used this determines how to split each string into the tokens that will be reordered. 19 * 20 * The value of this property is used in String.split() -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#separator 21 * 22 * @default " " 23 * */ 24 delimiter?: string | RegExp 25} 26 27export interface StringSamenessResult { 28 strategies: { 29 [key: string]: ComparisonStrategyResult 30 }, 31 highScore: number 32 highScoreWeighted: number 33} 34 35export interface ComparisonStrategyResultObject { 36 /** 37 * The normalized (0 to 100) score of this comparison 38 * */ 39 score: number 40 /** 41 * The raw value returned by the comparison (not normalized) 42 * */ 43 rawScore?: number 44 45 [key: string]: any 46} 47 48export interface ComparisonStrategyResult extends ComparisonStrategyResultObject { 49 // TODO maybe add more things in the future 50 //scoreFormatted: string 51} 52 53export interface NamedComparisonStrategyObjectResult extends ComparisonStrategyResultObject { 54 name: string 55} 56 57export type ComparisonStrategyResultValue = number | ComparisonStrategyResultObject; 58 59export type StrategyFunc<T extends ComparisonStrategyResultValue> = (strA: string, strB: string) => T; 60 61export interface ComparisonStrategy<T extends ComparisonStrategyResultValue> { 62 /** 63 * The name of this strategy 64 * */ 65 name: string 66 /** 67 * A function that accepts two string arguments and returns a number 68 * */ 69 strategy: StrategyFunc<T> 70 71 /** 72 * An optional function that accepts two string arguments and returns whether this strategy should be used 73 * */ 74 isValid?: (strA: string, strB: string) => boolean 75} 76 77export type StringTransformFunc = (str: string) => string;