@dicelette/core 1.26.0 → 1.27.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -318,7 +318,7 @@ declare function calculateSimilarity(str1: string, str2: string): number;
|
|
|
318
318
|
* Calculates the Levenshtein distance between two strings.
|
|
319
319
|
*/
|
|
320
320
|
declare function levenshteinDistance(str1: string, str2: string): number;
|
|
321
|
-
declare function findBestStatMatch<T>(searchTerm: string, normalizedStats: Map<string, T>, similarityThreshold?: number
|
|
321
|
+
declare function findBestStatMatch<T>(searchTerm: string, normalizedStats: Map<string, T>, similarityThreshold?: number): T | undefined;
|
|
322
322
|
/**
|
|
323
323
|
* Find the snippet name with the highest similarity to `macroName`.
|
|
324
324
|
* Single-pass O(n) algorithm: keeps the best (name, similarity) seen so far.
|
package/dist/index.d.ts
CHANGED
|
@@ -318,7 +318,7 @@ declare function calculateSimilarity(str1: string, str2: string): number;
|
|
|
318
318
|
* Calculates the Levenshtein distance between two strings.
|
|
319
319
|
*/
|
|
320
320
|
declare function levenshteinDistance(str1: string, str2: string): number;
|
|
321
|
-
declare function findBestStatMatch<T>(searchTerm: string, normalizedStats: Map<string, T>, similarityThreshold?: number
|
|
321
|
+
declare function findBestStatMatch<T>(searchTerm: string, normalizedStats: Map<string, T>, similarityThreshold?: number): T | undefined;
|
|
322
322
|
/**
|
|
323
323
|
* Find the snippet name with the highest similarity to `macroName`.
|
|
324
324
|
* Single-pass O(n) algorithm: keeps the best (name, similarity) seen so far.
|
package/dist/index.js
CHANGED
|
@@ -275,23 +275,18 @@ function levenshteinDistance(str1, str2) {
|
|
|
275
275
|
}
|
|
276
276
|
return matrix[str2.length][str1.length];
|
|
277
277
|
}
|
|
278
|
-
function findBestStatMatch(searchTerm, normalizedStats, similarityThreshold = MIN_THRESHOLD_MATCH
|
|
278
|
+
function findBestStatMatch(searchTerm, normalizedStats, similarityThreshold = MIN_THRESHOLD_MATCH) {
|
|
279
279
|
const exact = normalizedStats.get(searchTerm);
|
|
280
280
|
if (exact) return exact;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
if (candidates.length > 0) {
|
|
292
|
-
candidates.sort((a, b) => a[1] - b[1]);
|
|
293
|
-
return candidates[0][0];
|
|
294
|
-
}
|
|
281
|
+
const candidates = [];
|
|
282
|
+
for (const [normalizedKey, original] of normalizedStats) {
|
|
283
|
+
if (normalizedKey.startsWith(searchTerm))
|
|
284
|
+
candidates.push([original, calculateSimilarity(searchTerm, normalizedKey)]);
|
|
285
|
+
}
|
|
286
|
+
if (candidates.length === 1) return candidates[0][0];
|
|
287
|
+
if (candidates.length > 0) {
|
|
288
|
+
candidates.sort((a, b) => b[1] - a[1]);
|
|
289
|
+
if (candidates[0][1] >= similarityThreshold) return candidates[0][0];
|
|
295
290
|
}
|
|
296
291
|
let bestMatch;
|
|
297
292
|
let bestSimilarity = 0;
|
|
@@ -313,8 +308,7 @@ function findBestRecord(record, searchTerm, similarityThreshold = MIN_THRESHOLD_
|
|
|
313
308
|
return findBestStatMatch(
|
|
314
309
|
searchTerm.standardize(),
|
|
315
310
|
normalizeRecord,
|
|
316
|
-
similarityThreshold
|
|
317
|
-
false
|
|
311
|
+
similarityThreshold
|
|
318
312
|
) || null;
|
|
319
313
|
}
|
|
320
314
|
|
|
@@ -333,7 +327,7 @@ function handleDiceAfterD(tokenStd, normalizedStats) {
|
|
|
333
327
|
if (!diceMatch) return null;
|
|
334
328
|
const diceCount = diceMatch[1] || "";
|
|
335
329
|
const afterD = diceMatch[2];
|
|
336
|
-
const bestMatch = findBestStatMatch(afterD, normalizedStats, 1
|
|
330
|
+
const bestMatch = findBestStatMatch(afterD, normalizedStats, 1);
|
|
337
331
|
if (bestMatch) {
|
|
338
332
|
const [, value] = bestMatch;
|
|
339
333
|
return `${diceCount}d${value.toString()}`;
|
|
@@ -341,7 +335,7 @@ function handleDiceAfterD(tokenStd, normalizedStats) {
|
|
|
341
335
|
return null;
|
|
342
336
|
}
|
|
343
337
|
function handleSimpleToken(tokenStd, token, normalizedStats, minThreshold) {
|
|
344
|
-
const bestMatch = findBestStatMatch(tokenStd, normalizedStats, minThreshold
|
|
338
|
+
const bestMatch = findBestStatMatch(tokenStd, normalizedStats, minThreshold);
|
|
345
339
|
if (bestMatch) {
|
|
346
340
|
const [, value] = bestMatch;
|
|
347
341
|
return value.toString();
|