@atlaskit/tokens 1.49.0 → 1.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1589 -1591
- package/README.md +14 -8
- package/codemods/css-to-design-tokens/lib/colors.tsx +47 -49
- package/codemods/css-to-design-tokens/lib/declaration.tsx +26 -26
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +326 -326
- package/codemods/css-to-design-tokens/lib/meta.tsx +116 -122
- package/codemods/css-to-design-tokens/lib/tokens.tsx +28 -35
- package/codemods/css-to-design-tokens/lib/value.tsx +70 -72
- package/codemods/css-to-design-tokens/transform.tsx +68 -72
- package/codemods/hypermod.config.tsx +5 -5
- package/codemods/remove-fallbacks-color/transform.tsx +16 -18
- package/codemods/theme-to-design-tokens/transform.tsx +505 -588
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +139 -147
- package/codemods/theme-to-design-tokens/utils/ast.tsx +23 -34
- package/codemods/theme-to-design-tokens/utils/color.tsx +25 -26
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +27 -30
- package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +272 -290
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +224 -224
- package/codemods/theme-to-design-tokens/utils/named-colors.tsx +148 -148
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +10 -16
- package/codemods/utils/tokens.tsx +371 -371
- package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/cjs/artifacts/generated-pairs.js +1 -1
- package/dist/cjs/artifacts/palettes-raw/typography-palette.js +45 -30
- package/dist/cjs/artifacts/theme-import-map.js +1 -1
- package/dist/cjs/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +1 -1
- package/dist/cjs/artifacts/token-names.js +1 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography-adg3.js +20 -20
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography-minor3.js +13 -13
- package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/es2019/artifacts/generated-pairs.js +1 -1
- package/dist/es2019/artifacts/palettes-raw/typography-palette.js +45 -30
- package/dist/es2019/artifacts/theme-import-map.js +1 -1
- package/dist/es2019/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/es2019/artifacts/token-default-values.js +1 -1
- package/dist/es2019/artifacts/token-names.js +1 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography-adg3.js +20 -20
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography-minor3.js +13 -13
- package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/esm/artifacts/generated-pairs.js +1 -1
- package/dist/esm/artifacts/palettes-raw/typography-palette.js +45 -30
- package/dist/esm/artifacts/theme-import-map.js +1 -1
- package/dist/esm/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +1 -1
- package/dist/esm/artifacts/token-names.js +1 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-typography-adg3.js +20 -20
- package/dist/esm/artifacts/tokens-raw/atlassian-typography-minor3.js +13 -13
- package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types/artifacts/palettes-raw/typography-palette.d.ts +1 -1
- package/dist/types/artifacts/theme-import-map.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +1 -1
- package/dist/types/artifacts/token-names.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-typography-adg3.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +1 -1
- package/dist/types/artifacts/types.d.ts +1 -1
- package/dist/types/babel-plugin/plugin.d.ts +1 -1
- package/dist/types/custom-theme.d.ts +2 -2
- package/dist/types/enable-global-theme.d.ts +2 -2
- package/dist/types/entry-points/css-type-schema.codegen.d.ts +1 -1
- package/dist/types/entry-points/token-ids.d.ts +1 -1
- package/dist/types/get-global-theme.d.ts +1 -1
- package/dist/types/get-ssr-auto-script.d.ts +1 -1
- package/dist/types/get-theme-html-attrs.d.ts +1 -1
- package/dist/types/get-theme-styles.d.ts +1 -1
- package/dist/types/get-token.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/load-custom-theme-styles.d.ts +1 -1
- package/dist/types/set-global-theme.d.ts +2 -2
- package/dist/types/theme-state-transformer.d.ts +1 -1
- package/dist/types/utils/color-detection.d.ts +1 -1
- package/dist/types/utils/color-mode-listeners.d.ts +1 -1
- package/dist/types/utils/configure-page.d.ts +1 -1
- package/dist/types/utils/contrast-mode-listeners.d.ts +1 -1
- package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -1
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +1 -1
- package/dist/types/utils/generate-custom-color-ramp.d.ts +2 -2
- package/dist/types/utils/get-increased-contrast-theme.d.ts +1 -1
- package/dist/types/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types/utils/theme-loading.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/palettes-raw/typography-palette.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/theme-import-map.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/token-names.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-adg3.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types.d.ts +1 -1
- package/dist/types-ts4.5/babel-plugin/plugin.d.ts +1 -1
- package/dist/types-ts4.5/custom-theme.d.ts +2 -2
- package/dist/types-ts4.5/enable-global-theme.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/css-type-schema.codegen.d.ts +1 -1
- package/dist/types-ts4.5/entry-points/token-ids.d.ts +1 -1
- package/dist/types-ts4.5/get-global-theme.d.ts +1 -1
- package/dist/types-ts4.5/get-ssr-auto-script.d.ts +1 -1
- package/dist/types-ts4.5/get-theme-html-attrs.d.ts +1 -1
- package/dist/types-ts4.5/get-theme-styles.d.ts +1 -1
- package/dist/types-ts4.5/get-token.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/load-custom-theme-styles.d.ts +1 -1
- package/dist/types-ts4.5/set-global-theme.d.ts +2 -2
- package/dist/types-ts4.5/theme-state-transformer.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-detection.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-mode-listeners.d.ts +1 -1
- package/dist/types-ts4.5/utils/configure-page.d.ts +1 -1
- package/dist/types-ts4.5/utils/contrast-mode-listeners.d.ts +1 -1
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -1
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +2 -2
- package/dist/types-ts4.5/utils/get-increased-contrast-theme.d.ts +1 -1
- package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -1
- package/package.json +3 -5
- package/report.api.md +2071 -2090
|
@@ -4,323 +4,305 @@
|
|
|
4
4
|
* Fuzzy search ripped from the internet.
|
|
5
5
|
*/
|
|
6
6
|
const FuzzySet = function (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
arr: string[] = [],
|
|
8
|
+
useLevenshtein?: boolean,
|
|
9
|
+
gramSizeLower: number = 2,
|
|
10
|
+
gramSizeUpper: number = 3,
|
|
11
11
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
var fuzzyset: any = {
|
|
13
|
+
gramSizeLower: gramSizeLower,
|
|
14
|
+
gramSizeUpper: gramSizeUpper,
|
|
15
|
+
useLevenshtein: typeof useLevenshtein !== 'boolean' ? true : useLevenshtein,
|
|
16
|
+
exactSet: {},
|
|
17
|
+
matchDict: {},
|
|
18
|
+
items: {},
|
|
19
|
+
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
var levenshtein = function (str1: string, str2: string) {
|
|
22
|
+
var current: number[] = [];
|
|
23
|
+
var prev: number;
|
|
24
|
+
var value: number;
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
for (var i = 0; i <= str2.length; i++) {
|
|
27
|
+
for (var j = 0; j <= str1.length; j++) {
|
|
28
|
+
if (i && j) {
|
|
29
|
+
if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
value = prev;
|
|
32
|
+
} else {
|
|
33
|
+
// @ts-expect-error
|
|
34
|
+
value = Math.min(current[j], current[j - 1], prev) + 1;
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
value = i + j;
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
prev = current[j];
|
|
41
|
+
current[j] = value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
return current.pop() as number;
|
|
46
|
+
};
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// return an edit distance from 0 to 1
|
|
49
|
+
var _distance = function (str1: string, str2: string) {
|
|
50
|
+
if (str1 === null && str2 === null) {
|
|
51
|
+
throw new Error('Trying to compare two null values');
|
|
52
|
+
}
|
|
53
|
+
if (str1 === null || str2 === null) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
str1 = String(str1);
|
|
57
|
+
str2 = String(str2);
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
var distance = levenshtein(str1, str2);
|
|
60
|
+
if (str1.length > str2.length) {
|
|
61
|
+
return 1 - distance / str1.length;
|
|
62
|
+
} else {
|
|
63
|
+
return 1 - distance / str2.length;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF, ]+/g;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
var _iterateGrams = function (value: any, gramSize: any) {
|
|
69
|
+
gramSize = gramSize || 2;
|
|
70
|
+
var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
|
|
71
|
+
lenDiff = gramSize - simplified.length,
|
|
72
|
+
results = [];
|
|
73
|
+
if (lenDiff > 0) {
|
|
74
|
+
for (var i = 0; i < lenDiff; ++i) {
|
|
75
|
+
simplified += '-';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (var i = 0; i < simplified.length - gramSize + 1; ++i) {
|
|
79
|
+
results.push(simplified.slice(i, i + gramSize));
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
};
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
var _gramCounter = function (value: string, gramSize: number) {
|
|
85
|
+
// return an object where key=gram, value=number of occurrences
|
|
86
|
+
gramSize = gramSize || 2;
|
|
87
|
+
var result = {},
|
|
88
|
+
grams = _iterateGrams(value, gramSize),
|
|
89
|
+
i = 0;
|
|
90
|
+
for (i; i < grams.length; ++i) {
|
|
91
|
+
if (grams[i] in result) {
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
result[grams[i]] += 1;
|
|
94
|
+
} else {
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
result[grams[i]] = 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return defaultValue;
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
};
|
|
102
|
+
// the main functions
|
|
103
|
+
fuzzyset.get = function (value: string, defaultValue: string, minMatchScore: number) {
|
|
104
|
+
// check for value in set, returning defaultValue or null if none found
|
|
105
|
+
if (minMatchScore === undefined) {
|
|
106
|
+
minMatchScore = 0.33;
|
|
107
|
+
}
|
|
108
|
+
var result = this._get(value, minMatchScore);
|
|
109
|
+
if (!result && typeof defaultValue !== 'undefined') {
|
|
110
|
+
return defaultValue;
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
118
114
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
};
|
|
115
|
+
fuzzyset._get = function (value: string, minMatchScore: number) {
|
|
116
|
+
var results = [];
|
|
117
|
+
// start with high gram size and if there are no results, go to lower gram sizes
|
|
118
|
+
for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) {
|
|
119
|
+
results = this.__get(value, gramSize, minMatchScore);
|
|
120
|
+
if (results && results.length > 0) {
|
|
121
|
+
return results;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
134
126
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
gramCount,
|
|
147
|
-
i,
|
|
148
|
-
index,
|
|
149
|
-
otherGramCount;
|
|
127
|
+
fuzzyset.__get = function (value: string, gramSize: number, minMatchScore: number) {
|
|
128
|
+
var normalizedValue = this._normalizeStr(value),
|
|
129
|
+
matches = {},
|
|
130
|
+
gramCounts = _gramCounter(normalizedValue, gramSize),
|
|
131
|
+
items = this.items[gramSize],
|
|
132
|
+
sumOfSquareGramCounts = 0,
|
|
133
|
+
gram,
|
|
134
|
+
gramCount,
|
|
135
|
+
i,
|
|
136
|
+
index,
|
|
137
|
+
otherGramCount;
|
|
150
138
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
139
|
+
for (gram in gramCounts) {
|
|
140
|
+
// @ts-expect-error
|
|
141
|
+
gramCount = gramCounts[gram];
|
|
142
|
+
sumOfSquareGramCounts += Math.pow(gramCount, 2);
|
|
143
|
+
if (gram in this.matchDict) {
|
|
144
|
+
for (i = 0; i < this.matchDict[gram].length; ++i) {
|
|
145
|
+
index = this.matchDict[gram][i][0];
|
|
146
|
+
otherGramCount = this.matchDict[gram][i][1];
|
|
147
|
+
if (index in matches) {
|
|
148
|
+
// @ts-expect-error
|
|
149
|
+
matches[index] += gramCount * otherGramCount;
|
|
150
|
+
} else {
|
|
151
|
+
// @ts-expect-error
|
|
152
|
+
matches[index] = gramCount * otherGramCount;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
169
157
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
158
|
+
function isEmptyObject(obj: any) {
|
|
159
|
+
for (var prop in obj) {
|
|
160
|
+
if (obj.hasOwnProperty(prop)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
178
166
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
167
|
+
if (isEmptyObject(matches)) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
182
170
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
|
|
227
|
-
}
|
|
228
|
-
}.bind(this),
|
|
229
|
-
);
|
|
230
|
-
return newResults;
|
|
231
|
-
};
|
|
171
|
+
var vectorNormal = Math.sqrt(sumOfSquareGramCounts),
|
|
172
|
+
results: string[] = [],
|
|
173
|
+
matchScore;
|
|
174
|
+
// build a results list of [score, str]
|
|
175
|
+
for (var matchIndex in matches) {
|
|
176
|
+
// @ts-expect-error
|
|
177
|
+
matchScore = matches[matchIndex];
|
|
178
|
+
// @ts-expect-error
|
|
179
|
+
results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
|
|
180
|
+
}
|
|
181
|
+
var sortDescending = function (a: any, b: any) {
|
|
182
|
+
if (a[0] < b[0]) {
|
|
183
|
+
return 1;
|
|
184
|
+
} else if (a[0] > b[0]) {
|
|
185
|
+
return -1;
|
|
186
|
+
} else {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
results.sort(sortDescending);
|
|
191
|
+
if (this.useLevenshtein) {
|
|
192
|
+
var newResults: string[] = [],
|
|
193
|
+
endIndex = Math.min(50, results.length);
|
|
194
|
+
// truncate somewhat arbitrarily to 50
|
|
195
|
+
// @ts-expect-error
|
|
196
|
+
for (var i = 0; i < endIndex; ++i) {
|
|
197
|
+
// @ts-expect-error
|
|
198
|
+
newResults.push([_distance(results[i][1], normalizedValue), results[i][1]]);
|
|
199
|
+
}
|
|
200
|
+
results = newResults;
|
|
201
|
+
results.sort(sortDescending);
|
|
202
|
+
}
|
|
203
|
+
newResults = [];
|
|
204
|
+
results.forEach(
|
|
205
|
+
function (scoreWordPair: any) {
|
|
206
|
+
if (scoreWordPair[0] >= minMatchScore) {
|
|
207
|
+
// @ts-expect-error
|
|
208
|
+
newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
|
|
209
|
+
}
|
|
210
|
+
}.bind(this),
|
|
211
|
+
);
|
|
212
|
+
return newResults;
|
|
213
|
+
};
|
|
232
214
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
215
|
+
fuzzyset.add = function (value: any) {
|
|
216
|
+
var normalizedValue = this._normalizeStr(value);
|
|
217
|
+
if (normalizedValue in this.exactSet) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
238
220
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
221
|
+
var i = this.gramSizeLower;
|
|
222
|
+
for (i; i < this.gramSizeUpper + 1; ++i) {
|
|
223
|
+
this._add(value, i);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
244
226
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
227
|
+
fuzzyset._add = function (value: string, gramSize: number) {
|
|
228
|
+
var normalizedValue = this._normalizeStr(value),
|
|
229
|
+
items = this.items[gramSize] || [],
|
|
230
|
+
index = items.length;
|
|
249
231
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
232
|
+
items.push(0);
|
|
233
|
+
var gramCounts = _gramCounter(normalizedValue, gramSize);
|
|
234
|
+
var sumOfSquareGramCounts = 0;
|
|
235
|
+
var gram: string;
|
|
236
|
+
var gramCount: number;
|
|
255
237
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
238
|
+
for (gram in gramCounts) {
|
|
239
|
+
// @ts-expect-error
|
|
240
|
+
gramCount = gramCounts[gram];
|
|
241
|
+
sumOfSquareGramCounts += Math.pow(gramCount, 2);
|
|
242
|
+
if (gram in this.matchDict) {
|
|
243
|
+
this.matchDict[gram].push([index, gramCount]);
|
|
244
|
+
} else {
|
|
245
|
+
this.matchDict[gram] = [[index, gramCount]];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
var vectorNormal = Math.sqrt(sumOfSquareGramCounts);
|
|
249
|
+
items[index] = [vectorNormal, normalizedValue];
|
|
250
|
+
this.items[gramSize] = items;
|
|
251
|
+
this.exactSet[normalizedValue] = value;
|
|
252
|
+
};
|
|
271
253
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
254
|
+
fuzzyset._normalizeStr = function (str: string) {
|
|
255
|
+
if (Object.prototype.toString.call(str) !== '[object String]') {
|
|
256
|
+
throw new Error('Must use a string as argument to FuzzySet functions');
|
|
257
|
+
}
|
|
258
|
+
return str.toLowerCase();
|
|
259
|
+
};
|
|
278
260
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
261
|
+
// return length of items in set
|
|
262
|
+
fuzzyset.length = function () {
|
|
263
|
+
var count = 0,
|
|
264
|
+
prop;
|
|
265
|
+
for (prop in this.exactSet) {
|
|
266
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
267
|
+
count += 1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return count;
|
|
271
|
+
};
|
|
290
272
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
273
|
+
// return is set is empty
|
|
274
|
+
fuzzyset.isEmpty = function () {
|
|
275
|
+
for (var prop in this.exactSet) {
|
|
276
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
};
|
|
300
282
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
283
|
+
// return list of values loaded into set
|
|
284
|
+
fuzzyset.values = function () {
|
|
285
|
+
var values = [],
|
|
286
|
+
prop;
|
|
287
|
+
for (prop in this.exactSet) {
|
|
288
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
289
|
+
values.push(this.exactSet[prop]);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return values;
|
|
293
|
+
};
|
|
312
294
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
295
|
+
// initialization
|
|
296
|
+
var i = fuzzyset.gramSizeLower;
|
|
297
|
+
for (i; i < fuzzyset.gramSizeUpper + 1; ++i) {
|
|
298
|
+
fuzzyset.items[i] = [];
|
|
299
|
+
}
|
|
300
|
+
// add all the items to the set
|
|
301
|
+
for (i = 0; i < arr.length; ++i) {
|
|
302
|
+
fuzzyset.add(arr[i]);
|
|
303
|
+
}
|
|
322
304
|
|
|
323
|
-
|
|
305
|
+
return fuzzyset;
|
|
324
306
|
};
|
|
325
307
|
|
|
326
308
|
export default FuzzySet;
|