"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 DOES_NOT_EXIST_MESSAGE = "The word you've entered isn't in the dictionary. Click on a spelling suggestion below or try again using the search bar above.";
const crawl = (word) => {
    return (0, lib_1.request)({
        protocol: 'https',
        hostname: 'www.merriam-webster.com',
        path: `/dictionary/${encodeURIComponent(word)}`,
    });
};
exports.crawl = crawl;
const parse = (html) => {
    const $ = (0, cheerio_1.load)(html);
    $('strong.mw_t_bc').replaceWith(', ');
    $('.text-lowercase').remove();
    $('.sub-content-thread').remove();
    const $definitions = $('[id^=dictionary-entry]').find('.dtText, .cxl-ref');
    return {
        definitions: Array.from($definitions).map((definition) => $(definition).text().replace(/\n/g, '')),
        exists: $('.spelling-suggestion-text').text().trim() !== DOES_NOT_EXIST_MESSAGE,
    };
};
exports.parse = parse;
