|
1 |
| -// parse out just the options we care about so we always get a consistent |
2 |
| -// obj with keys in a consistent order. |
3 |
| -const opts = ['includePrerelease', 'loose', 'rtl'] |
4 |
| -const parseOptions = options => |
5 |
| - !options ? {} |
6 |
| - : typeof options !== 'object' ? { loose: true } |
7 |
| - : opts.filter(k => options[k]).reduce((o, k) => { |
8 |
| - o[k] = true |
9 |
| - return o |
10 |
| - }, {}) |
| 1 | +// parse out just the options we care about |
| 2 | +const isParsedConfigSymbol = Symbol('isParsedConfig'); |
| 3 | +const var1 = Object.freeze({ includePrerelease: true, loose: true, rtl: true, [isParsedConfigSymbol]: true }) |
| 4 | +const var2 = Object.freeze({ includePrerelease: true, loose: true, [isParsedConfigSymbol]: true }) |
| 5 | +const var3 = Object.freeze({ includePrerelease: true, rtl: true, [isParsedConfigSymbol]: true }) |
| 6 | +const var4 = Object.freeze({ includePrerelease: true, [isParsedConfigSymbol]: true }) |
| 7 | +const var5 = Object.freeze({ loose: true, rtl: true, [isParsedConfigSymbol]: true }) |
| 8 | +const var6 = Object.freeze({ loose: true, [isParsedConfigSymbol]: true }) |
| 9 | +const var7 = Object.freeze({ rtl: true, [isParsedConfigSymbol]: true }) |
| 10 | +const emptyOpts = Object.freeze({ [isParsedConfigSymbol]: true }) |
| 11 | + |
| 12 | +const parseOptions = options => { |
| 13 | + if (!options) return emptyOpts |
| 14 | + |
| 15 | + if (typeof options !== 'object') return var6 |
| 16 | + |
| 17 | + if (options[isParsedConfigSymbol]) |
| 18 | + return options; |
| 19 | + |
| 20 | + if (options.includePrerelease) { |
| 21 | + if (options.loose && options.rtl) { |
| 22 | + return var1 |
| 23 | + } |
| 24 | + |
| 25 | + if (options.loose) { |
| 26 | + return var2 |
| 27 | + } |
| 28 | + |
| 29 | + if (options.rtl) { |
| 30 | + return var3 |
| 31 | + } |
| 32 | + |
| 33 | + return var4 |
| 34 | + } else if (options.loose) { |
| 35 | + if (options.rtl) { |
| 36 | + return var5 |
| 37 | + } |
| 38 | + |
| 39 | + return var6 |
| 40 | + } else if (options.rtl) { |
| 41 | + return var7 |
| 42 | + } else { |
| 43 | + return emptyOpts |
| 44 | + } |
| 45 | +} |
11 | 46 | module.exports = parseOptions
|
0 commit comments