frontend/.pnpm-store/v3/files/ef/4628c992837ea57ded707364b1494cc365104c62a76bbf92353901316027ab0c8f3bdef7361062ad83d4ca53c8552b5a9427f9069422e20d4cec8728fe8797

18 lines
462 B
Plaintext

export default function incrementListIndex(current, dir, opt) {
const len = opt.choices.realLength;
const 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');
}