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

fsk-argparse

v1.1.0

Published

'参数解析'

Downloads

7

Readme

fsk-argparse

参数解析工具

安装

npm install fsk-argparse

示例

var ArgumentParser = require('fsk-argparse');
var argsParser = new ArgumentParser([options]);
argsParser.add('-s', {
  dest: 'start',
  desc: '启动服务器',
  callback: function(args) {
    if (args && args.start === true){
      //启动服务器
    }
  }
});
var args = argsParser.parse();
  • options: 可选参数
    • sync: 是否同步, 默认异步
    • done: 所有事件完成后的回调
    • version: 版本号, 支持-v查看版本号

add

parser.add(argName[, options]);
argName: 参数名 必选
options: 参数配置项 可选

options

dest: 参数全名 不填默认为参数名
desc: 说明
defaultValue: 默认值
sort: 回调函数执行顺序, 按从大到小的顺序执行 3 > 2 > 1这样
required: 是否必选项 此项设为true之后 无此参数则抛出异常
callback: 回调函数 参数 args 解析之后的args 与parse方法返回值相同; 此方法在parse解析完成后执行

parse

parser.parse([arguments])
arguments: 字符串数组 可选, 没有则解析process.argv

更多示例

var ArgumentParser = require('fsk-argparse');
var argsParser = new ArgumentParser();
argsParser.add('-s', {
  dest: 'start',
  desc: '启动服务器',
  callback: function(args) {
    if (args && args.start === true){
      console.log('启动服务器');
    }
  }
});
argsParser.add('-c', {
  dest: 'close',
  desc: '关闭服务器'
});
argsParser.add('-t', {
  dest: 'switch',
  desc: '重置配置文件'
});
argsParser.parse();
>test -s //{start: true, close: null, switch: null}
>test -s start //{start: 'start', close: null, switch: null}
>test -c -c close -t //{start: null, close: [true, close], switch; true}

//同步
var ArgumentParser = require('fsk-argparse');
var argsParser = new ArgumentParser({sync:true});
var result = [];
argsParser.add('test2', {
  sort: 2,
  callback: function() {
    result.push(2)
  }
});
argsParser.add('test1', {
  sort: 3,
  callback: function() {
    result.push(3)
  }
});
argsParser.add('test3', {
  sort: 1,
  callback: function() {
    result.push(1)
  }
});
argsParser.parse(); // result = [3, 2, 1]