tis-cli前端项目快速搭建命令行工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
485 B

4 years ago
  1. function incrementListIndex(current, dir, opt) {
  2. const len = opt.choices.realLength;
  3. const shouldLoop = 'loop' in opt ? Boolean(opt.loop) : true;
  4. if (dir === 'up') {
  5. if (current > 0) {
  6. return current - 1;
  7. }
  8. return shouldLoop ? len - 1 : current;
  9. }
  10. if (dir === 'down') {
  11. if (current < len - 1) {
  12. return current + 1;
  13. }
  14. return shouldLoop ? 0 : current;
  15. }
  16. throw new Error('dir must be up or down');
  17. }
  18. module.exports = incrementListIndex;