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

left-hook-scaffold

v0.1.0-beta

Published

### Install This CLI App is currently unpublished. To install the CLI ```shell $ git clone <left-hook-scaffold repository> && cd left-hook-scaffold $ npm i -g # The lhs command has been added to your PATH exports ```

Downloads

2

Readme

Left Hook Scaffold

CLI App Creation Framework

Install

This CLI App is currently unpublished. To install the CLI

$ git clone <left-hook-scaffold repository> && cd left-hook-scaffold
$ npm i -g 
# The lhs command has been added to your PATH exports

Usage

The left-hook-scaffold CLI framework creates a command line application from a pre-defined schema. Once a schema is defined, the lhs CLI class constructor can be invoked on it to expose the parse method. In your CLI application's bin, simply invoke the CLI parse method on process.argv.slice(2)

#!/usr/bin/env node
/* myPackage/bin/myCLI.js */
const lhs = require("lhs")
const myCLI = new lhs.CLI( <schema> )
CLI.parse(process.argv.slice(2))

NOTE: The expression require("lhs") is currently invalid. Instead, require /lib directly.

Take the example command line input for myCLI:

$ myCLI doSomething -f --someOption someValue

When the myCLI.parse method is invoked, the command line arguments will be formatted in terms of verbs and phrases

   console.log(args)
   /*OUTPUT
   {
      verbs : ["doSomething"],
      phrases : {
         f: true,
         someOption: "someValue"
      }
   }
   */

Schema Definition

To start the schema definition, we must first define a Verb. A Verb reflects a top-level "action" or "command" the CLI user may use.

let lhs = require("lhs")
let test = new lhs.Verb({
   name: "test",
   alias: ["t"],
   operation: (phrases) => {
      console.log("[verb] test:")
   },
   phrases: [
   ]
})

let myCli = new lhs.CLI({
   verbs: [
      test
   ]
})

myCli.parse(process.argv.slice(2))

If this file is in our /bin directory and listed in the package.json bin field, we can now use the test command.

$ myCli test
# output : [verb] test:
$ myCli t
# output : [verb] test:

To add options to our verb, we can add a Phrase to our Verb's phrases array. A Phrase may describe any number of options - a flag, a key:value parameter, or a sub-operation

let echo = new lhs.Phrase({
   name: "echo",
   alias: ["fooEcho", "ech"],
   operation: (phrases) => {
      console.log("[phrase] echo:")
      console.log(phrases)
   }
})

Now that we've declared a echo with a name, alias, and operation, we can reference it from within the verb test's operation. The Phrase method isMemberOf allows us to check whether or not any alias of the echo phrase has been passed in as a command line argument.

The operation of the echo phrase is to simply console.log the phrases passed to it.

let echo = new lhs.Phrase({
   name: "echo",
   alias: ["fooEcho", "ech"],
   operation: (phrases) => {
      console.log("[phrase] echo:")
      console.log(phrases)
   }
})

let test = new lhs.Verb({
   name: "test",
   alias: ["t"],
   operation: (phrases) => {
      console.log("[verb] test:")
      /* if 'echo' or any respective alias is present in the 'phrases' object */
      if (echo.isMemberOf(phrases)) {
         /* invoke the 'echo' operation on the 'phrases`' */
         echo.operation(phrases)
      }
   },
   phrases: [
      echo
   ]
})

let myCli = new lhs.CLI({
   verbs: [
      test
   ]
})

myCli.parse(process.argv.slice(2))

Used in the terminal...

$ myCli test --echo
# output : [verb] test:
#          { echo : true }

Chaining Phrases

We can conditionally chain Phrases to allow us to execute lower level operations. In this example, we use the chalk library to color our output based on command line args.

const lhs = require("../../lib")
const chalk = require("chalk")

let color = new lhs.Phrase({
   name: "color",
   alias: ["col"],
   options: [
      {
         name: "blue",
         operation: (phrases) => {
            console.log(chalk.blue(phrases))
         }
      },
      {
         name: "red",
         operation: (phrases) => {
            console.log(chalk.red(phrases))
         }
      },
      {
         name: "magenta",
         operation: (phrases) => {
            console.log(chalk.magenta(phrases))
         }
      },
   ]
})

let echo = new lhs.Phrase({
   name: "echo",
   alias: ["fooEcho", "ech"],
   description : "Echo command line parameters",
   operation: (phrases) => {
      console.log("[phrase]: echo")
      if (color.isMemberOf(phrases)) {
         let colorOptionValue = color.captureValue(phrases)
         let colorOption = color.getOption(colorOptionValue)
         colorOption.operation(phrases)
      } else {
         console.log(phrases)
      }
   }
})

let test = new lhs.Verb({
   name: "test",
   alias: ["t"],
   operation: (phrases) => {
      console.log("[verb] test:")
      if (echo.isMemberOf(phrases)) {
         echo.operation(phrases)
      }
   },
   phrases: [
      echo
   ]
})

let myCli = new lhs.CLI({
   verbs: [
      test
   ]
})

myCli.parse(process.argv.slice(2))

Used in the terminal...

$ myCli test --echo
# output : [verb] test:
#          { echo : true }
$ myCli test --echo --color blue
# output : [verb] test:
#          [object Object] {{ blue-colored }}
$ myCli test --echo --color red
# output : [verb] test:
#          [object Object] {{ red-colored }}
$ myCli test --echo --color magenta
# output : [verb] test:
#          [object Object] {{ magenta-colored }}