UNPKG

europa-core

Version:

Europa core engine for converting HTML into valid Markdown

65 lines 2.8 kB
"use strict"; /* * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EuropaOptionsParser = void 0; const _environment = Symbol(); /** * A parser for {@link EuropaOptions} that provides null safety and supports default value resolution. */ class EuropaOptionsParser { /** * Creates an instance of {@link EuropaOptionsParser} using the `options` provided. * * @param options - The options to be used. */ constructor(options) { this[_environment] = options.environment; } /** * Parses the specified `options`, extracting only properties that match valid options and applying default values * where required. * * @param options - The options to be parsed. * @return The parsed options. */ parse(options) { function setOption(options, name, value) { options[name] = value; } const definitions = { absolute: false, baseUri: () => this[_environment].getDefaultBaseUri(), eol: () => this[_environment].getDefaultEndOfLineCharacter(), inline: false, }; return Object.entries(definitions).reduce((acc, [name, defaultValue]) => { var _a; const optionName = name; const optionValue = (_a = options === null || options === void 0 ? void 0 : options[optionName]) !== null && _a !== void 0 ? _a : (typeof defaultValue === 'function' ? defaultValue() : defaultValue); setOption(acc, optionName, optionValue); return acc; }, {}); } } exports.EuropaOptionsParser = EuropaOptionsParser; //# sourceMappingURL=EuropaOptionsParser.js.map