diff --git a/lib/index.js b/lib/index.js index 5122e1f..a9c0a19 100644 --- a/lib/index.js +++ b/lib/index.js @@ -37,7 +37,7 @@ async function discover(params, options = {}) { async function sanitizeDiscoverParams(params) { return getDiscoverOptions().then( options => { - const getOptionValue = (optArr, value) => { + const getOptionValue = (optArr, value, defaultIndex = 0) => { if (value !== undefined && optArr) { const opt = optArr.find( o => o.value == value ); if (opt) { @@ -45,7 +45,7 @@ async function sanitizeDiscoverParams(params) { } } if (optArr) { - return optArr[0].value; + return optArr[defaultIndex].value; } else { return null; @@ -66,7 +66,7 @@ async function sanitizeDiscoverParams(params) { // or subgenre is 'all-metal') const timeAllowed = sanitized.subgenre === undefined || sanitized.subgenre == subgenreOptions[0].value; if (timeAllowed) { - sanitized.time = getOptionValue(options.times, params.time); + sanitized.time = getOptionValue(options.times, params.time, 1); } sanitized.location = getOptionValue(options.locations, params.location); sanitized.format = getOptionValue(options.formats, params.format);