mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
38 lines
884 B
TypeScript
38 lines
884 B
TypeScript
import { extract, FuzzballExtractOptions } from 'fuzzball';
|
|
import { createLogger } from '../utils';
|
|
|
|
const logger = createLogger('parser');
|
|
|
|
export function titleMatch(
|
|
parsedTitle: string,
|
|
titles: string[],
|
|
options: {
|
|
threshold: number;
|
|
} & Exclude<FuzzballExtractOptions, 'returnObjects'>
|
|
) {
|
|
const { threshold, ...extractOptions } = options;
|
|
|
|
const results = extract(parsedTitle, titles, {
|
|
...extractOptions,
|
|
returnObjects: true,
|
|
});
|
|
|
|
const highestScore =
|
|
results.reduce(
|
|
(max: number, result: { choice: string; score: number; key: number }) => {
|
|
return Math.max(max, result.score);
|
|
},
|
|
0
|
|
) / 100;
|
|
|
|
return highestScore >= threshold;
|
|
}
|
|
|
|
export function normaliseTitle(title: string) {
|
|
return title
|
|
.normalize('NFD')
|
|
.replace(/[\u0300-\u036f]/g, '')
|
|
.replace(/[^\p{L}\p{N}+]/gu, '')
|
|
.toLowerCase();
|
|
}
|