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.

25 lines (19 loc) 664 B
import { load } from 'cheerio'; import { request } from '../lib'; import type { ParsingResult } from '../types'; const DOES_NOT_EXIST_MESSAGE = '404 Page Not Found'; export const crawl = (word: string): Promise<string> => { return request({ protocol: 'https', hostname: 'www.vajehyab.com', path: `/moein/${encodeURIComponent(word)}`, }); }; export const parse = (html: string): ParsingResult => { const $ = load(html); const $definitions = $('[itemprop=articleBody]'); return { definitions: Array.from($definitions).map((definition) => $(definition).text()), exists: $('#container h1').text() !== DOES_NOT_EXIST_MESSAGE, }; };