@abhisekp/inquirer-npm-name 中文文档教程
inquirer-npm-name
使用 inquirer 来验证提示中提供的值的辅助函数不作为 npm 包存在。
如果该值已被用作 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 个参数:
prompt
an Inquirer prompt configuration.inquirer
or any object with aobj.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.
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:
prompt
an Inquirer prompt configuration.inquirer
or any object with aobj.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