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

@tslib/argv

v1.0.26

Published

parse argument for TypeScript

Downloads

10

Readme

@tslib/argv

极简 TypeScript 命令行解析库

  • 完整的代码提示和类型解析
  • 支持标准的命令行语法:program run -p 9000 -h 127.0.0.1
  • 支持长短参数,如:"-p" 或者 "--port"
  • 命令和所有参数均支持默认值
  • 自动生成帮助信息
  • 干净和非常简单的代码,含注释不超过200行
  • 独立代码,无第三方依赖库
  • 便捷的引用方式
  • 示例工程参考 /example 目录
  • 支持环境变量覆盖命令行参数,大写的同名环境变量将覆盖cmdline参数

安装

  yarn add @tslib/argv

参考:

  • 参见目录: '/src/test'

引用

1. 引入argv库

  1. 添加命令行定义文件:"cmdline.ts"
import argv from '@tslib/argv';
// 自动导入版本信息,也可手工定义
import pkg = require('../package.json');

/**
 * 导出解析后的命令行
 */
export default argv(
  pkg.name,
  pkg.version,
  `  Example using for Test ts argv library
  you can using: "${pkg.name} [cmd] params ..." to test it
  `,
  {
    cmd: {
      short: null,// 定义short为null,设置cmd为命令参数解析模式
      desc: 'default cmd is "run",other:"test","build"',
      value: 'run', // 缺省值
    },
    port: {
      short: 'p',
      desc: 'service listen port,default:3000',
      value: 3000, // 缺省值
    },
    boo: {
      short: 'b',
      desc: 'service listen port,default:3000',
      value: true, // 缺省值      
    }
  }
);

2. 创建 .json 导入文件定义 [可选].

jsonImport.ts 添加到工程源文件目录即可,无需使用import导入

declare module "*.json" {
  const value: any;
  export = value;
}

3. 使用命令行参数


import cmdline from './cmdline';

console.log('cmd', cmdline.cmd);
console.log('port', cmdline.port);
console.log('boo', cmdline.boo);

其他注意事项

  • import cmdline 为只读对象,防止意外改变变量
  • boolean 类型参数接收: null,0,false为 false值,其他为true

@tslib

TypeScript全栈开发库,致力于全部类型化的前后端组件开发