UNPKG

scrabble-solver

Version:

Scrabble Solver 2 - Free, open-source, cross-platform, multi-language analysis tool for Scrabble, Scrabble Duel, Super Scrabble, Letter League, Crossplay, Literaki, and Kelimelik. Quickly find the top-scoring words using the given board and tiles.

27 lines (22 loc) 870 B
import { Locale } from '@scrabble-solver/types'; import { english, french, german, persian, polish, romanian, spanish, turkish } from './languages'; import { normalizeDefinition, unique } from './lib'; import { type 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, }; };