did-you-mean.js 446 B

1234567891011121314151617
  1. var meant = require('meant')
  2. function didYouMean (scmd, commands) {
  3. var bestSimilarity = meant(scmd, commands).map(function (str) {
  4. return ' ' + str
  5. })
  6. if (bestSimilarity.length === 0) return ''
  7. if (bestSimilarity.length === 1) {
  8. return '\nDid you mean this?\n' + bestSimilarity[0]
  9. } else {
  10. return ['\nDid you mean one of these?']
  11. .concat(bestSimilarity.slice(0, 3)).join('\n')
  12. }
  13. }
  14. module.exports = didYouMean