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

command-helper

v1.0.11

Published

lib/index.js

Downloads

29

Readme

command-helper

npm package Build Status codecov

Motivation

  • Command Helper is used to get result from the given commands and provides to remove current command from the given command array if needed.
  • You can use standart readers (boolean, string, array ) to read command and also you can define custom readers to read commands.

Type Docs

Template Format

Main Template

  • name : name of your bin js file.
  • version: version of your library.
  • commands: command reference to find your command template.
  • options: holds each command template options.
{
  "name": "command-helper",
  "version": "1.0.0",
  "commands": {
    ...
  },
  "options": {
    ...
  }
}

Command Template

  • Main Template -> options[key]: Define command template in ${Main Template}.options{variable name}
    • reader: Reader is read command and find value of command in the given arguments.
      • name: Its shown on help board.
      • main: it is reader function to read the command and find its values.
      • related: called by main reader if exist.
    • defaultValue: it is default value for the command.
    • remove: Indicates if the command read in the given arguments then remove all things about the command from the given arguments.
    • infinity: read command recursively from the given arguments.
    • description: Its shown on help board.
    • usage: Its used on help board.
      • usage = 0 then --command
      • usage = 1 then --command value
      • usage = -1 then --files value1, [value2, ...]
      • else shows usage if exist.
  • Short Template: It used when the template file keeps as json.
{
    "reader": "Boolean",
    "defaultValue": false,
    "description": "Renderer Description",
    "usage": 0
}
  • Full Template: If you need to set custom readers then you can use full template.
{
    "reader": {
        "name": "Array<JsonFile>",
        "main": Readers.Array,
        "related": Readers.JsonFile
      },
      "defaultValue": [],
      "remove": true,
      "infinity": false,
      "description": "Json Files Description",
      "usage": -1
}

Standart Readers

  • Boolean [...,"--command",....]

  • String -> [...,"--command", "value",....] or [...,"--command=value",....]

  • Array (Array) ["--command", "value1", "value2", "value3"]

  • TextFile -> [...,"--command", "path",....] or [...,"--command=path",....]

  • JsonFile -> [...,"--command", "path",....] or [...,"--command=path",....]

  • Array [...,"--command", "path1", "path2", "path3",....]

  • Array [...,"--command", "path1", "path2", "path3",....]

  • You can override standard readers when you call Helper file.

import {  } "api/Api";
let customReaders = {
     Boolean: (state: CommandState, opts) => {
         if (!has(opts[state.name]) && state.args.length > state.i) {
             let def = state.template.defaultValue;
             opts[state.name] = has(def) ? !def : true;
             return true;
         }
         return false;
     },
     NewType: (state: CommandState, opts) => {
         if (!has(opts[state.name]) && state.args.length > state.i) {
             let def = state.template.defaultValue;
             opts[state.name] = has(def) ? !def : true;
             return true;
         }
         return false;
     } 
}

let helper = new Helper(template, customerReaders)

Examples

  • Json Template Example
let templateJson = {
  "name": "command-helper",
  "version": "1.0.0",
  "commands": {
    "--renderer": "renderer",
    "--interactive": "interactive",
    "--base-url": "baseUrl",
    "--root-list": "rootList",
    "--opts": "opts",
    "--tdd-json": "tddJson",
    "--files": "files",
    "--another-files": "anotherFiles",
    "--json-files": "jsonFiles"
  },
  "options": {
    "renderer": {
      "reader": "Boolean",
      "defaultValue": false,
      "description": "Renderer Description",
      "usage": 0
    },
    "interactive": {
      "reader": "Boolean",
      "defaultValue": false,
      "description": "Interactive Description",
      "usage": 0
    },
    "baseUrl": {
      "reader": "String",
      "defaultValue": "",
      "description": "Base Url Description",
      "usage": 1
    },
    "rootList": {
      "reader": "Array",
      "defaultValue": [],
      "description": "Root List Description",
      "usage": -1
    },
    "opts": {
      "reader": "TextFile",
      "defaultValue": "",
      "description": "Opts Description",
      "usage": 1
    },
    "tddJson": {
      "reader": "JsonFile",
      "defaultValue": {},
      "description": "Tdd Json Description",
      "usage": 1
    },
    "files": {
      "reader": "Array<TextFile>",
      "defaultValue": [],
      "description": "Files Description",
      "usage": -1
    },
    "jsonFiles": {
      "reader": "Array<JsonFile>",
      "defaultValue": [],
      "description": "Json Files Description",
      "usage": -1
    }
  }
}
let helper = new Helper(template);
let result = helper.parse(process.argv);

Contribute

  • Install
$ git clone https://github.com/wasabi-io/command-helper.git`
$ cd command-helper
$ npm install
  • Test
$ npm test
  • Coverage
$ npm run coverage
  • Export Docs
$ npm run docs
  • Build Code as javascript (common-js)
$ npm build