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

hemsl

v1.2.7

Published

A lightweight Node.js command line argv parser and command executor

Downloads

1,125

Readme

hemsl

hemsl is a lightweight Node.js command line argv parser and command executor

Build Status Build status codecov js-semistandard-style npm npm

White flowers Komatsu, scientific name: Villadia batesii (Hemsl.) Baehni & Macbride, Sedum, Tulian perennial multi-meat plants, flowering generally 4 to 5 months. White flowers Komatsu leaves more beautiful, there is a certain ornamental value; potted plants can be placed on the TV, the computer can absorb radiation, can also be planted in the room to absorb formaldehyde and other substances, purify the air.

Install

Use npm

$ npm install hemsl --save

Use yarn

$ yarn add hemsl

Usages

Create an instance

var Args = require('hemsl');
var args = new Args();

Set app version and bin name

args
  .version('1.1.0')
  .bin('example');

Add global option

args
  .option(, {
    option: 'debug',
    default: true,
    describe: 'Print debug log (global option)',
    alias: 'd'
  })
  .option({
    option: 'grep <expression>',
    default: true,
    describe: 'Debug log filter (global option)',
    alias: 'g'
  });

Add command

args.command({
  command: 'start <port> [ip]',
  describe: 'Start a local server',
  usage: 'example start <port> [ip] [options]',
  /**
    * The `start` command handle
    * Start a local server
    */
  fn: function(port, ip){
    console.log('Server started at', 'http://' + ip + ':' + port);

    var http = require('http');

    var server = http.createServer(function(req, res){
        console.log(req.method.bold.gray, req.url);
        res.end(req.url);
    })

    server.listen(port, ip);
  }
})

Add option to command

There are two ways to add an option to a command:

  • Method 1: Call the args.command() method and set the configuration field options
  • Method 2: Call the args.command().option() method

Method 1

args.command({
  command: 'start <port> [ip]',
  describe: '...',
  usage: '...',
  fn: function(port, ip){
      //...
  },
  options: {
    'p': {
      default: '',
      describe: 'service port',
      alias: 'port',
      usage: ''
    },
    'hot-reload': {
      alias: 'H',
      describe: 'enable hot reload'
    }
  }
});

Method 2

args.command({
  command: 'start <port> [ip]', 
  // ...
})
.option({
  option: 'date-format', 
  default: 'yyyy-MM-dd',
  alias: 'R',
  describe: 'date format string'
})
.option({
  option: 'time-format',  
  alias: 'm',
  default: 'HH:mm:ss',
  describe: 'time format string'
})

Other Example

API

Classes

Args

Kind: global class

new Args(config)

参数解析

| Param | Type | Default | Description | | --- | --- | --- | --- | | config | Object | | 配置对象 | | [config.__] | Boolean | false | 是否停止解析--后面的内容 | | [config.colors] | Object | | 文本颜色配置 | | [config.colors.title] | String | 'white' | 标题文本颜色 | | [config.colors.command] | String | 'white' | 命令名称文本颜色 | | [config.colors.option] | String | 'white' | Option文本颜色 | | [config.colors.paragraph] | String | 'gray' | 段落文本颜色 | | [config.colors.parameter] | String | 'gray' | 参数文本颜色 |

args.parse([argv], [execute]) ⇒ Object

解析参数,返回解析后的参数对象。如果参数executetrue,自动执行argv中的命令

Kind: instance method of Args
Returns: Object - 解析后的对象
Access: public

| Param | Type | Default | Description | | --- | --- | --- | --- | | [argv] | Array | process.argv.slice(2) | 要解析的参数数组 | | [execute] | Boolean | false | 是否自动执行参数中的命令 |

args.execute() ⇒ Args

执行命令

Kind: instance method of Args
Access: public

args.option(key, config) ⇒ Args

添加全局选项

Kind: instance method of Args
Access: public

| Param | Type | Description | | --- | --- | --- | | key | String | 选项名称 | | config | Object | 选项配置 |

args.command(cmd, config) ⇒ Command

添加命令

Kind: instance method of Args
Access: public

| Param | Type | Description | | --- | --- | --- | | cmd | String | 命令名称 | | config | Object | 命令配置 |

args.help([cmdName]) ⇒ Args

显示自动生成的帮助信息,如果指定了命令名称,则显示对应命令的帮助信息

Kind: instance method of Args
Access: public

| Param | Type | Description | | --- | --- | --- | | [cmdName] | String | 命令名称 |

args.version(ver) ⇒ Args

设置App版本号,默认值为1.0.0。这个版本号会在全局-v/--version的时候显示

Kind: instance method of Args
Access: public

| Param | Type | Description | | --- | --- | --- | | ver | String | 版本号 |

args.bin(binName) ⇒ Args

设置App的命令名称

Kind: instance method of Args
Access: public

| Param | Type | Description | | --- | --- | --- | | binName | String | 名称 |

Command

Kind: global class

new Command(cmd, config)

创建命令

| Param | Type | Description | | --- | --- | --- | | cmd | String | 命令名称 | | config | Object | 配置参数 | | config.usage | String | 命令使用帮助 | | config.describe | String | 命令描述信息 | | config.fn | function | 执行命令时调用的函数 | | config.options | Object | 命令支持的选项(option) |

command.option(key, opt) ⇒ Command

为命令创建一个选项

Kind: instance method of Command
Access: public

| Param | Type | Description | | --- | --- | --- | | key | String | 选项名称 | | opt | Object | 选项配置 |