@abhisekp/inquirer-npm-name

Helper function using inquirer to validate a value provided in a prompt does not exist as an npm package.


Keywords
inquirer, npm, name, yeoman, package
License
MIT
Install
npm install @abhisekp/inquirer-npm-name@2.0.3

Documentation

inquirer-npm-name

Helper function using inquirer to validate a value provided in a prompt does not exist as a npm package.

NPM version Build Status Dependency Status Coverage percentage All Contributors

If the value is already used as a npm package, then the users will be prompted and asked if they want to choose another one. If so, we'll recurse through the same validation process until we have a name that is unused on the npm registry. This is a helper to catch naming issue in advance, it is not a validation rule as the user can always decide to continue with the same name.

Install

$ npm install --save @abhisekp/inquirer-npm-name # npm i -S @abhisekp/inquirer-npm-name

Usage

const inquirer = require('inquirer');
const askName = require('@abhisekp/inquirer-npm-name');

askName({
  name: 'name',
  message: 'Module Name'
}, inquirer).then(answers => {
  console.log(answers.name);
});

Inside a Yeoman Generator you'd call it this way:

const generators = require('yeoman-generator');
const inquirer = require('inquirer');
const askName = require('@abhisekp/inquirer-npm-name');

module.exports = generators.Base.extend({
  prompting: function () {
    const appNamePrompt = {
      type: 'input',
      name: 'appname',
      message: 'What would you like to name the app?',
      default: answers => this.appname, // optional
      filter: appname => appname.trim().replace(/\s+/g, '-').toLowerCase() // optional
    };

    const prompts = []; // other prompts

    return askName(appNamePrompt, this)
      .then(name =>
        this.prompt(prompts)
          .then(answers => this.answers = answers)
      );
  }
});

askName takes 2 parameters:

  1. prompt an Inquirer prompt configuration.
  2. inquirer or any object with a obj.prompt() method.

Returns: A Promise resolved with the answer object.

Contributors

Thanks goes to these wonderful people (emoji key):


Abhisek Pattnaik

💻 💡

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Simon Boudrias