linguee-client
Version:
A simple node.js Linguee client.
48 lines • 1.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Endpoint = exports.URL_COMPONENTS = void 0;
const Lang_1 = __importDefault(require("./Lang"));
exports.URL_COMPONENTS = {
scheme: 'https://',
host: 'www.linguee.com',
path: '/',
parameters: {
source: 'auto',
ajax: '1',
query: '',
},
};
class Endpoint {
static createSearchUrl(term = '', from = '', to = '') {
term = term.toString().trim();
const fromLang = Lang_1.default.get(from);
const toLang = Lang_1.default.get(to);
if (!term.length) {
throw new Error('Empty term');
}
if (!fromLang) {
throw new Error(`"from" parameter ("${from} language") is not available`);
}
if (!toLang) {
throw new Error(`"to" parameter ("${to} language") is not available`);
}
const url = Endpoint.getURL();
url.pathname = `${fromLang.name}-${toLang.name}/search/search`;
url.searchParams.set('source', exports.URL_COMPONENTS.parameters.source);
url.searchParams.set('ajax', exports.URL_COMPONENTS.parameters.ajax);
url.searchParams.set('query', term);
return url.toString();
}
static getURL() {
return new URL(`${exports.URL_COMPONENTS.scheme}${exports.URL_COMPONENTS.host}${exports.URL_COMPONENTS.path}`);
}
static getDomain() {
return Endpoint.getURL().toString();
}
}
exports.Endpoint = Endpoint;
exports.default = Endpoint;
//# sourceMappingURL=Endpoint.js.map