frontend/.pnpm-store/v3/files/3c/714e3b5ff8399e9c04e9963f8e6a9af0a028bbc58f5e21358d0056ccbea6b80a9bb660d561e65bdf1a80c793c73f60224ec92b7db44e87243c2b882e1291d1

20 lines
481 B
Plaintext

function incrementListIndex(current, dir, opt) {
var len = opt.choices.realLength;
var shouldLoop = 'loop' in opt ? Boolean(opt.loop) : true;
if (dir === 'up') {
if (current > 0) {
return current - 1;
}
return shouldLoop ? len - 1 : current;
}
if (dir === 'down') {
if (current < len - 1) {
return current + 1;
}
return shouldLoop ? 0 : current;
}
throw new Error('dir must be up or down');
}
module.exports = incrementListIndex;