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