How to use the didyoumean.threshold function in didyoumean

To help you get started, we’ve selected a few didyoumean examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-cli / packages / @vue / cli / bin / vue.js View on Github external
#!/usr/bin/env node

// Check node version before requiring/doing anything else
// The user may be on a very old node version

const { chalk, semver } = require('@vue/cli-shared-utils')
const requiredVersion = require('../package.json').engines.node
const didYouMean = require('didyoumean')

// Setting edit distance to 60% of the input string's length
didYouMean.threshold = 0.6

function checkNodeVersion (wanted, id) {
  if (!semver.satisfies(process.version, wanted)) {
    console.log(chalk.red(
      'You are using Node ' + process.version + ', but this version of ' + id +
      ' requires Node ' + wanted + '.\nPlease upgrade your Node version.'
    ))
    process.exit(1)
  }
}

checkNodeVersion(requiredVersion, '@vue/cli')

if (semver.satisfies(process.version, '9.x')) {
  console.log(chalk.red(
    `You are using Node ${process.version}.\n` +
github Aceheliflyer / AceBot / src / events / client / unknownCommand.js View on Github external
// Split prefix and get the invalid command used.
    var commandMessage
    // Global Prefix
    if (message.content.startsWith(client.commandPrefix)) {
      commandMessage = message.content.split(client.commandPrefix)[1]
    // Mention Prefix
    } else if (message.content.startsWith(`<@${client.user.id}>`)) {
      commandMessage = message.content.split(`<@${client.user.id}>`)[1]
    // Guild Prefix
    } else if (message.guild && message.guild.commandPrefix !== '') {
      commandMessage = message.content.split(message.guild.commandPrefix)[1]
    }

    // Find the best result.
    didYouMean.threshold = null
    var verify = didYouMean(commandMessage.trim(), possibleCommands)

    // Create the replyMessage.
    var replyMessage = {}
    replyMessage.content = oneLine`
      unknown command, use
      ${message.anyUsage('help')}
      to view the list of all commands.
    `

    // If a match is found, apply it to the replyMessage.
    if (verify) {
      replyMessage.embed = {}
      replyMessage.embed.description = `Did you mean **\`${verify}\`**?`
      replyMessage.embed.color = client.getClientColor(message)
    }
github netbeast / dashboard / bin / cli.js View on Github external
cli.command('restart ')
.description('Restarts a running app')
.action(restart)

cli.command('launch ')
.description('Launches an installed app')
.action(launch)

cli.parse(process.argv)

// No command specified or unrecognaized command
if (cli.args.length === 0) {
  cli.help()
} else if (ACTIONS_LIST.indexOf(process.argv[2]) === -1) {
  didYouMean.threshold = null
  var matched = didYouMean(process.argv[2], ACTIONS_LIST)
  if (matched != null) {
    console.log('\n\tDid you mean "' + didYouMean(process.argv[2], ACTIONS_LIST) + '"?')
    console.log('\n\tType "beast ' + matched + ' -h" to know its parameters' + '\n')
  } else {
    cli.help()
  }
}
github madlabsinc / mevn-cli / src / cli.js View on Github external
#!/usr/bin/env node

'use strict';

// Require Modules.
import '@babel/polyfill';
import program from 'commander';
import chalk from 'chalk';
import didYouMean from 'didyoumean';
import envinfo from 'envinfo';
import updateNotifier from 'update-notifier';

// Setting edit distance to 60% of the input string's length.
didYouMean.threshold = 0.6;

// Defining action handlers for respective commands.
import initializeProject from './commands/basic/init';
import generateFile from './commands/basic/generate';
import asyncRender from './commands/basic/codesplit';
import addPlugins from './commands/basic/add';
import setupProject from './commands/serve/setup';
import dockerize from './commands/basic/docker';
import deployConfig from './commands/deploy/deploy';
import pkg from '../package';

updateNotifier({ pkg }).notify();

const suggestCommands = cmd => {
  const availableCommands = program.commands.map(c => c._name);
github luoxue-victor / webpack-box / packages / packages-cli / cli / bin / packages-box.js View on Github external
#!/usr/bin/env node
const { chalk, semver } = require('@vue/cli-shared-utils')
const didYouMean = require('didyoumean')
const minimist = require('minimist')
const program = require('commander')
const loadCommand = require('../lib/util/loadCommand')

didYouMean.threshold = 0.6

checkNodeVersionForWarning()

program
  .version(`@jijiang/packages-box ${require('../../package').version}`)
  .usage(' [options]')

program
  .command('create ')
  .description('create a new project powered by vue-cli-service')
  .option('-p, --preset ', 'Skip prompts and use saved or remote preset')
  .option('-d, --default', 'Skip prompts and use default preset')
  .option('-i, --inlinePreset ', 'Skip prompts and use inline JSON string as preset')
  .option('-m, --packageManager ', 'Use specified npm client when installing dependencies')
  .option('-r, --registry ', 'Use specified npm registry when installing dependencies (only for npm)')
  .option('-g, --git [message]', 'Force git initialization with initial commit message')
github luoxue-victor / webpack-box / packages / cli / bin / index.js View on Github external
#!/usr/bin/env node
const { chalk, semver } = require('@pkb/shared-utils')
const didYouMean = require('didyoumean')
const minimist = require('minimist')
const program = require('commander')
const loadCommand = require('../lib/util/loadCommand')

didYouMean.threshold = 0.6

checkNodeVersionForWarning()

program
  .version(`@pkb/cli ${require('../package.json').version}`)
  .usage(' [options]')

program
  .command('create ')
  .description('create a new project powered by vue-cli-service')
  .option('-p, --preset ', 'Skip prompts and use saved or remote preset')
  .option('-d, --default', 'Skip prompts and use default preset')
  .option('-i, --inlinePreset ', 'Skip prompts and use inline JSON string as preset')
  .option('-m, --packageManager ', 'Use specified npm client when installing dependencies')
  .option('-r, --registry ', 'Use specified npm registry when installing dependencies (only for npm)')
  .option('-g, --git [message]', 'Force git initialization with initial commit message')
github userpixel / pk / bin / pk.js View on Github external
function readJSON(fileName) {
    log('Reading file', fileName)
    return JSON.parse(fs.readFileSync(fileName, 'utf8'))
}

let what;
try {
    const path = argv._[0];
    log(path ? `Path is ${path}` : 'There is no path. Operating on the whole file.');
    const jsonContents = readJSON(argv.in);
    let result = jsonContents;
    if (path) {
        result = _get(jsonContents, path)
        if (result === undefined) {
            log(`Could not lookup the path "${path}"`)
            didyoumean.threshold = 0.5
            const possiblePaths = didyoumean(path, completion.getKeys(jsonContents))
            if (possiblePaths) {
                throw new Error(`There is no "${path}". Did you mean:\n${possiblePaths}`)
            }
            throw new Error(`Path not found: ${path}`)
        }
    }
    if (argv.key && argv.val) {
        log('Both keys are values are desired');
        what = result
    } else if (argv.key) {
        log('Only keys are requested');
        what = filter.keys(result);
    } else if (argv.val) {
        log('Only values are requested');
        what = filter.values(result);

didyoumean

Match human-quality input to potential matches by edit distance.

Apache-2.0
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis