Innovenergy_trunk/frontend/node_modules/testcafe/lib/utils/get-options/base.js

38 lines
6.1 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const convert_to_best_fit_type_1 = __importDefault(require("../convert-to-best-fit-type"));
const DEFAULT_OPTIONS_SEPARATOR = ',';
const DEFAULT_KEY_VALUE_SEPARATOR = '=';
function convertOptionValueType(value) {
// NOTE: threat a key without a separator and a value as a boolean flag
if (value === void 0)
return true;
return (0, convert_to_best_fit_type_1.default)(value);
}
function parseOptionsString(optionsStr, optionsSeparator, keyValueSeparator) {
return optionsStr
.split(optionsSeparator)
.map(keyValueString => keyValueString.split(keyValueSeparator))
.map(([key, ...value]) => [key, value.length > 1 ? value.join(keyValueSeparator) : value[0]]);
}
async function default_1(sourceOptions = '', optionsConfig = {}) {
const { optionsSeparator = DEFAULT_OPTIONS_SEPARATOR, keyValueSeparator = DEFAULT_KEY_VALUE_SEPARATOR, skipOptionValueTypeConversion = false, onOptionParsed = void 0, } = optionsConfig;
const optionsList = typeof sourceOptions === 'string' ?
parseOptionsString(sourceOptions, optionsSeparator, keyValueSeparator) :
Object.entries(sourceOptions);
const resultOptions = Object.create(null);
await Promise.all(optionsList.map(async ([key, value]) => {
if (!skipOptionValueTypeConversion)
value = convertOptionValueType(value);
if (onOptionParsed)
value = await onOptionParsed(key, value);
resultOptions[key] = value;
}));
return resultOptions;
}
exports.default = default_1;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmFzZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy91dGlscy9nZXQtb3B0aW9ucy9iYXNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsMkZBQStEO0FBRy9ELE1BQU0seUJBQXlCLEdBQUssR0FBR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