UNPKG

scrabble-solver

Version:

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

28 lines (22 loc) 788 B
import { load } from 'cheerio'; import { request } from '../lib'; import { ParsingResult } from '../types'; export const crawl = (word: string): Promise<string> => { return request({ protocol: 'https', hostname: 'dexonline.ro', path: `/definitie/${encodeURIComponent(word)}`, }); }; export const parse = (html: string): ParsingResult => { const $ = load(html); const $activeTab = $('.tab-pane.show.active'); $('.type-example').remove(); const $definitions = $activeTab.find('li.type-meaning.depth-0 > .meaningContainer .def.html'); $definitions.find('.meaningTree').remove(); const definitions = Array.from($definitions).map((definition) => $(definition).text().replace(/\n/g, '')); return { definitions, exists: definitions.length > 0, }; };