npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jyeontu/j-inquirer

v1.0.5

Published

基于inquirer控制台交互的二次封装

Downloads

19

Readme

JInquirer

inquirer插件进行二次封装,支持选择文件和文件夹。

配置参数说明

inquirer原有参数

  • type

表示提问的类型,包括:input、confirm、 list、rawlist、expand、checkbox、password、editor。

  • name

存储当前输入的值。

  • message

问题的描述。

  • default

默认值。

  • choices

列表选项,在某些type下可用,并且包含一个分隔符(separator);

  • validate

对用户的回答进行校验。

  • filter

对用户的回答进行过滤处理,返回处理后的值。

  • when

根据前面问题的回答,判断当前问题是否需要被回答。

  • pageSize

修改某些type类型下的渲染行数。

  • prefix

修改message默认前缀。

  • suffix

修改message默认后缀。

新增参数

type

在原有类型中新增两种类型:file、folder、expandList,分别为文件选择器和目录选择器及多级选择器。

pathType

此项为新增配置,设置目录和文件选择器选中路径输出的格式,默认为相对路径,可以设置为absolute,此时会输出绝对路径。

rowNum

type为expandList时生效,设置当前选中对象每行显示的个数。

notNull

设置该参数输入是否可以为空。

config

  • 1、checkboxTip

type为expandList时生效,列表为最后一级时显示提示语句。

  • 2、listTip

type为expandList时生效,列表非最后一级时显示提示语句。

  • 3、dirname

type为filefolder时,需要传入当前目录的路径作为初始化目录路径

示例

npm install @jyeontu/j-inquirer
const JInquirer = require('@jyeontu/j-inquirer');
let options = [
    {
        type:"input",
        message:"请输入你的姓名:",
        name:"name",
        notNull:true
    },{
        type:"input",
        message:"请输入你的年龄:",
        name:"age",
        default:18,
        validate:(val)=>{
            if(val < 0 || val > 150){
                return "请输入0~150之间的数字";
            }
            return true;
        }
    },{
        type:"file",
        message:"请选择文件:",
        name:"fileName",
        default:"",
        dirname:__dirname,
    },{
        type:"folder",
        message:"请选择文件夹:",
        name:"folderName",
        default:"",
        dirname:__dirname,
    },{
        type:"list",
        message:"请选择你喜欢的水果:",
        name:"fruit",
        default:"Apple",
        choices:[
            "Apple",
            "pear",
            "Banana"
        ],
    },{
        type:"expand",
        message:"请选择一个颜色:",
        name:"color",
        default:"red",
        choices:[
            {
                key : 'R',
                value : "red"
            },
            {
                key : 'B',
                value : "blue"
            },
            {
                key : 'G',
                value : "green"
            }
        ]
    },{
        type:"checkbox",
        message:"选择一至多种颜色:",
        name:"color2",
        choices:[
            "red",
            "blue",
            "green",
            "pink",
            "orange"
        ]
    },{
        type:"password",
        message:"请输入你的密码:",
        name:"pwd"
    },{
        type:"editor",
        message:"写下你想写的东西:",
        name:"editor"
    },{
        type: 'expandList',
        name: 'expandListChoose',
        message: 'your choice:',
        choices:{
            'aa': [ 'aaa1', 'aaa2', 'aaa3', 'aaa4' ],
            'bb': [ 'bbb1', 'bbb2' ],
            'cc': [ 'ccc1' ]
        }
    }
];
let j = new JInquirer(options);
let res = j.prompt().then(res=>{
    console.log(res);
});