123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- "use strict";
- const process = (options, normalizeSimple, normalizeOptions, fn) => {
-
- const array = items => {
- for (const item of items) {
- if (typeof item === "string") {
- fn(item, normalizeSimple(item, item));
- } else if (item && typeof item === "object") {
- object(item);
- } else {
- throw new Error("Unexpected options format");
- }
- }
- };
-
- const object = obj => {
- for (const [key, value] of Object.entries(obj)) {
- if (typeof value === "string" || Array.isArray(value)) {
- fn(key, normalizeSimple(value, key));
- } else {
- fn(key, normalizeOptions(value, key));
- }
- }
- };
- if (!options) {
-
- } else if (Array.isArray(options)) {
- array(options);
- } else if (typeof options === "object") {
- object(options);
- } else {
- throw new Error("Unexpected options format");
- }
- };
- const parseOptions = (options, normalizeSimple, normalizeOptions) => {
-
- const items = [];
- process(options, normalizeSimple, normalizeOptions, (key, value) => {
- items.push([key, value]);
- });
- return items;
- };
- const scope = (scope, options) => {
-
- const obj = {};
- process(
- options,
- item => (item),
- item => (item),
- (key, value) => {
- obj[
- key.startsWith("./") ? `${scope}${key.slice(1)}` : `${scope}/${key}`
- ] = value;
- }
- );
- return obj;
- };
- module.exports.parseOptions = parseOptions;
- module.exports.scope = scope;
|