diff --git a/internal/parse-options.js b/internal/parse-options.js index f7e6df6c..10d64ce0 100644 --- a/internal/parse-options.js +++ b/internal/parse-options.js @@ -1,51 +1,15 @@ // parse out just the options we care about -const isParsedConfigSymbol = Symbol('isParsedConfig') -const var1 = Object.freeze({ includePrerelease: true, loose: true, rtl: true, [isParsedConfigSymbol]: true }) -const var2 = Object.freeze({ includePrerelease: true, loose: true, [isParsedConfigSymbol]: true }) -const var3 = Object.freeze({ includePrerelease: true, rtl: true, [isParsedConfigSymbol]: true }) -const var4 = Object.freeze({ includePrerelease: true, [isParsedConfigSymbol]: true }) -const var5 = Object.freeze({ loose: true, rtl: true, [isParsedConfigSymbol]: true }) -const var6 = Object.freeze({ loose: true, [isParsedConfigSymbol]: true }) -const var7 = Object.freeze({ rtl: true, [isParsedConfigSymbol]: true }) -const emptyOpts = Object.freeze({ [isParsedConfigSymbol]: true }) - +const looseOption = Object.freeze({ loose: true }) +const emptyOpts = Object.freeze({ }) const parseOptions = options => { if (!options) { return emptyOpts } if (typeof options !== 'object') { - return var6 - } - - if (options[isParsedConfigSymbol]) { - return options + return looseOption } - if (options.includePrerelease) { - if (options.loose && options.rtl) { - return var1 - } - - if (options.loose) { - return var2 - } - - if (options.rtl) { - return var3 - } - - return var4 - } else if (options.loose) { - if (options.rtl) { - return var5 - } - - return var6 - } else if (options.rtl) { - return var7 - } else { - return emptyOpts - } + return options } module.exports = parseOptions diff --git a/test/internal/parse-options.js b/test/internal/parse-options.js index e219eb71..9e1aa726 100644 --- a/test/internal/parse-options.js +++ b/test/internal/parse-options.js @@ -18,15 +18,11 @@ t.test('truthy non-objects always loose mode, for backwards comp', t => { t.end() }) -t.test('objects only include truthy flags we know about, set to true', t => { - t.strictSame(parseOptions(/asdf/), {}) - t.strictSame(parseOptions(new Error('hello')), {}) - t.strictSame(parseOptions({ loose: true, a: 1, rtl: false }), { loose: true }) - t.strictSame(parseOptions({ loose: 1, rtl: 2, includePrerelease: 10 }), { - loose: true, - rtl: true, - includePrerelease: true, - }) +t.test('any object passed is returned', t => { + t.strictSame(parseOptions(/asdf/), /asdf/) + t.strictSame(parseOptions(new Error('hello')), new Error('hello')) + t.strictSame(parseOptions({ loose: true, a: 1, rtl: false }), { loose: true, a: 1, rtl: false }) + t.strictSame(parseOptions({ loose: 1, rtl: 2, includePrerelease: 10 }), { loose: 1, rtl: 2, includePrerelease: 10 }) t.strictSame(parseOptions({ loose: true }), { loose: true }) t.strictSame(parseOptions({ rtl: true }), { rtl: true }) t.strictSame(parseOptions({ includePrerelease: true }), { includePrerelease: true }) @@ -35,12 +31,3 @@ t.test('objects only include truthy flags we know about, set to true', t => { t.strictSame(parseOptions({ rtl: true, includePrerelease: true }), { rtl: true, includePrerelease: true }) t.end() }) - -t.test('should skip validation when options is already parsed', t => { - const options = { loose: true, rtl: true } - const parsedOptions = parseOptions(options) - - t.equal(parseOptions(parsedOptions) === parsedOptions, true) - t.not(parseOptions(options) === parsedOptions, false) - t.end() -})