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

@aminnairi/command-parser

v0.5.1

Published

Command Line Parser

Downloads

22

Readme

command-parser

Command Line Arguments Parser

$ code my-cli
'use strict'

const { CommandParser } = require('@aminnairi/command-parser')

const name = 'my-cli'
const version = '0.1.0'
const synopsis = 'My Command Line Interface'
const parser = new CommandParser(name, version, synopsis)

const command = 'name'
const description = 'Your name'
parser.option(command, description)

const { name } = parser.parser()

console.log(`Hello, ${name}!`)
$ node my-cli --name you
Hello, you!

Installation

Using npm

$ npm install --save @aminnairi/command-parser

Or using yarn

$ yarn add @aminnairi/command-parser

Include

Using CommonJS

'use strict'

const { CommandParser, NO_VALUE_EXPECTED } = require('@aminnairi/command-parser')

Using ECMAScript Modules

'use strict'

import { CommandParser, NO_VALUE_EXPECTED } from '@aminnairi/command-parser'

Usage

Instanciation

const name = 'my-cli'
const version = '0.1.0'
const synopsis = 'My Command Line Interface'
const parser = new CommandParser(name, version, synopsis)

Arguments

Configuration

parser
  .option('name', 'Your name')
  .option('mood', 'Your mood')
  .option('robot', 'If you are a robot', NO_VALUE_EXPECTED)

Parsing

const { name, mood, robot } = parser.parse()

if (name) {
  console.log(`Hello, ${name}!`)
}

if (mood) {
  console.log(`Are you really ${mood}?`)
}

if (robot) {
  console.log(`01101100 01101111 01101100 right?`)
}

Command Line

Using node

Double-Dash Syntax

$ node my-cli --name John --mood happy --robot
Hello, John!
Are you really happy?
01101100 01101111 01101100 right?

Single-Dash Syntax

$ node my-cli -n John -m happy -r
Hello, John!
Are you really happy?
01101100 01101111 01101100 right?

Short Single-Dash Syntax

$ node my-cli -rn John -m happy
Hello, John!
Are you really happy?
01101100 01101111 01101100 right?

Version

$ node my-cli --version
my-cli version 0.1.0

Help

$ node my-cli --help
SYNOPSIS

    My Command Line Interface

OPTIONS

    -h, --help
        Display this message

    -v, --version
        Display the name and version of this command

    -n, --name [NAME]
        Your name

    -m, --mood [MOOD]
        Your mood

    -r, --robot
        If you are a robot

TypeScript

$ npm install --save typescript ts-node @aminnairi/command-parser
$ ./node_modules/.bin/tsc --init
$ code my-cli
'use strict'

import { CommandParser, ICommandParserOptions, NO_VALUE_EXPECTED } from '@aminnairi/command-parser'

const name: string = 'my-cli'
const version: string = '0.1.0'
const synopsis: string = 'My Command Line Interface'
const parser: CommandParser = new CommandParser(name, version, synopsis)

parser
  .option('name', 'Your name')
  .option('mood', 'Your mood')
  .option('robot', 'If you are a robot')

const { name, mood, robot }: ICommandParserOptions =  parser.parse()

if (name) {
  console.log(`Hello, ${name}!`)
}

if (mood) {
  console.log(`Are you really ${mood}?`)
}

if (robot) {
  console.log(`01101100 01101111 01101100 right?`)
}
$ ./node_modules/.bin/ts-node my-cli -rn John -m happy
Hello, John!
Are you really happy?
01101100 01101111 01101100 right?

Contributing

See CONTRIBUTING.md.