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 (20 loc) • 656 B
text/typescript
import { load } from 'cheerio';
import { request } from '../lib';
import type { ParsingResult } from '../types';
export const crawl = (word: string): Promise<string> => {
return request({
protocol: 'https',
hostname: 'sjp.pl',
path: `/${encodeURIComponent(word)}`,
});
};
export const parse = (html: string): ParsingResult => {
const $ = load(html);
const $header = $($('h1')[0]);
const $isAllowed = $header.next();
const $definitions = $header.next().next().next().next();
return {
definitions: $definitions.text().trim().split(/\d+\./),
exists: $isAllowed.text().trim().indexOf('dopuszczalne w grach') >= 0,
};
};