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

runit-on-cli

v1.0.8

Published

Run node modules directly on CLI

Downloads

14

Readme

runit-on-cli

Run node modules directly on CLI

CircleCI

Install

npm install -g runit-on-cli

API

$ runit-on-cli <module-name> <named-export> [-c] [-f [functionName]] [-n [version]] [-p [parameters...]] [-s] [-t [transformFunction]] [-u [subModule]]
  • -c, --call-module-as-function: call the exported module as a function intead of object
  • -f, --function-name [functionName]: call a specific function from exported module
  • -n, --npm-module-version [version]: run a specific version of the npm module
  • -p, --params [parameters...]: list of params that will be passed to the module/function call
  • -s, --silent: print only the module output, without progress or logs
  • -t, --transform-output [transformFunction]: define a function to modify module/function return
  • -u, --sub-module [subModule]: import a submodule, such as 'crypto-js/sha256'

Examples

Running a module with default export, passing one string parameter:

$ runit-on-cli jwt-decode -p \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"

Image

The above example using silent mode (-s option) will output only the return content:

{ sub: '1234567890', name: 'John Doe', iat: 1516239022 }

Running a module with a named export, passing two parameters, an object and an array:

$ runit-on-cli -s lodash orderBy -p '[{name:"banana"},{name:"apple"}]' '["name"]'
[ { name: 'apple' }, { name: 'banana' } ]

Passing a parameter from a file content:

$ runit-on-cli -s lodash orderBy -p "$(cat ./users.json)" '["first"]'
[
  { first: 'ane', last: 'mcfly' },
  { first: 'john', last: 'mayer' },
  { first: 'mary', last: 'jane' }
]

A more complex example using lodash map:

$ runit-on-cli -s lodash map -p "$(cat ./users.json)" 'e => {e.full = e.first + " " + e.last; return e;}'
[
  { first: 'mary', last: 'jane', full: 'mary jane' },
  { first: 'john', last: 'mayer', full: 'john mayer' },
  { first: 'ane', last: 'mcfly', full: 'ane mcfly' }
]

Running async functions and transform the output to return a specific property:

$ runit-on-cli -s axios get -p \'http://universities.hipolabs.com\' -t 'output.data'
{
    data: {
        author: { name: 'hipo', website: 'http://hipolabs.com' },
        github: 'https://github.com/Hipo/university-domains-list',
        example: 'http://universities.hipolabs.com/search?name=middle&country=Turkey'
    }
}

A more complex example of using -t option:

$ runit-on-cli -s moment -t 'moment().add(7, "days").format("YYYY/MM/DD")'
2021/08/01

Using the -t option is possible to use the node environment, actually.

Using the node environment by -t option:

$ runit-on-cli -s axios get -p \'http://universities.hipolabs.com\' -t 'Object.keys(output.data)'
[ 'author', 'github', 'example' ]

Call a specific function from exported module:

$ runit-on-cli chalk -f blue -p \"Hello World\"

Image

The same result is got by using -t option: runit-on-cli chalk -p \"Hello World\" -t 'chalk.blue(output)'

Another example of calling a specific function from exported module:

$ runit-on-cli -s faker -f phone.phoneNumber
550-681-2495

Running a module with a named export, without parameters:

$ runit-on-cli -s uuid v4
2a7bb8f8-ac20-46ea-a0eb-ea58df26d48e

Running the exported module as a function intead of object, and call a specific function:

$ runit-on-cli moment -c -f add -p 7 \'days\'

Image

The -c options is necessary for this case because moment export is a function: moment().add(7,'days')

Running a submodule:

$ runit-on-cli crypto-js -u sha256 -p \'test\'

Image

License

MIT © Danilo Sampaio