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.

40 lines (39 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = exports.crawl = void 0; const cheerio_1 = require("cheerio"); const lib_1 = require("../lib"); const crawl = (word) => { return (0, lib_1.request)({ protocol: 'https', hostname: 'www.diccionarios.com', path: `/diccionario/espanol/${encodeURIComponent(word)}`, }); }; exports.crawl = crawl; const parse = (html) => { const $ = (0, cheerio_1.load)(html); $('.verdBold14 + .gris11 + .gris13').remove(); $('br + .gris13').remove(); $('.grisItalic13 + .gris13').remove(); $('font[class^="verd"]').remove(); $('font.gris11').remove(); $('font[class^="grisBold"]').remove(); $('font[class^="grisItalic"]').remove(); Array.from($('.gris13')).forEach((element) => { const children = $(element).find('.gris13'); if (children && children.length > 0) { children.remove(); } }); const definitions = Array.from($('.dcom-search-result .gris13')); return { definitions: definitions .map((definition) => $(definition).text().trim()) .filter(Boolean) .map((definition) => definition.replace(/\s+\.$/g, '')) .map((definition) => (definition.endsWith('.') ? definition : `${definition}.`)), exists: $('.wrapper > p > strong').text() !== 'No se ha encontrado la palabra exacta', }; }; exports.parse = parse;