-
Notifications
You must be signed in to change notification settings - Fork 22
/
parse.ts
26 lines (22 loc) · 865 Bytes
/
parse.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
import { Locale } from '@scrabble-solver/types';
import { english, french, german, persian, polish, romanian, spanish, turkish } from './languages';
import { normalizeDefinition, unique } from './lib';
import { ParsingResult } from './types';
const parsePerLocale: Record<Locale, (html: string) => ParsingResult> = {
[Locale.DE_DE]: german.parse,
[Locale.EN_GB]: english.parse,
[Locale.EN_US]: english.parse,
[Locale.ES_ES]: spanish.parse,
[Locale.FA_IR]: persian.parse,
[Locale.FR_FR]: french.parse,
[Locale.PL_PL]: polish.parse,
[Locale.RO_RO]: romanian.parse,
[Locale.TR_TR]: turkish.parse,
};
export const parse = (locale: Locale, html: string): ParsingResult => {
const { definitions, exists } = parsePerLocale[locale](html);
return {
definitions: unique(definitions.map(normalizeDefinition).filter(Boolean)),
exists,
};
};