@abhisekp/inquirer-npm-name 中文文档教程

发布于 8年前 浏览 20 项目主页 更新于 3年前

inquirer-npm-name

使用 inquirer 来验证提示中提供的值的辅助函数不作为 npm 包存在。

NPM 版本构建状态依赖状态覆盖率All Contributors

如果该值已被用作 npm 包,则会提示用户并询问他们是否要选择另一个。 如果是这样,我们将递归执行相同的验证过程,直到我们有一个在 npm 注册表中未使用的名称。 这是提前捕获命名问题的帮助程序,它不是验证规则,因为用户始终可以决定继续使用相同的名称。

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);
});

Yeoman Generator 中,您可以这样称呼它:

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 接受 2 个参数:

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

返回: 已解决的 Promise与答案对象。

Contributors

感谢这些很棒的人 (emoji key):


Abhisek Pattnaik

???? ????

这个项目遵循 all-contributors 规范。 欢迎任何形式的贡献!

License

麻省理工学院 © Simon Boudrias

inquirer-npm-name

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

NPM versionBuild StatusDependency StatusCoverage percentageAll 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

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文