didYouMean.js 893 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = didYouMean;
  6. var MAX_SUGGESTIONS = 5;
  7. /**
  8. * Given [ A, B, C ] return ' Did you mean A, B, or C?'.
  9. */
  10. // eslint-disable-next-line no-redeclare
  11. function didYouMean(firstArg, secondArg) {
  12. var _ref = typeof firstArg === 'string' ? [firstArg, secondArg] : [undefined, firstArg],
  13. subMessage = _ref[0],
  14. suggestions = _ref[1];
  15. var message = ' Did you mean ';
  16. if (subMessage) {
  17. message += subMessage + ' ';
  18. }
  19. switch (suggestions.length) {
  20. case 0:
  21. return '';
  22. case 1:
  23. return message + suggestions[0] + '?';
  24. case 2:
  25. return message + suggestions[0] + ' or ' + suggestions[1] + '?';
  26. }
  27. var selected = suggestions.slice(0, MAX_SUGGESTIONS);
  28. var lastItem = selected.pop();
  29. return message + selected.join(', ') + ', or ' + lastItem + '?';
  30. }