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

knevee

v3.0.0

Published

**knevee** simplifies running JavaScript directly from the terminal. It enables users to execute scripts efficiently, providing intuitive CLI interactions.

Downloads

155

Readme

knevee

knevee simplifies running JavaScript directly from the terminal. It enables users to execute scripts efficiently, providing intuitive CLI interactions.

Overview

knevee allows you to craft lightweight, customizable command-line tools using JavaScript. Define a module, specify the positional arguments and options, and you're ready to run your script with ease.

Example

Here’s a quick example of how a simple greeting command could be implemented:

#!/usr/bin/env knevee
export const description = "Greetings earthling";
export const positionals = "<name>";

export default async (name) => {
  return `hello ${name}`;
};

Usage

You can execute the script directly, view help, and handle various command-line inputs:

$ greeting --help
Usage: greeting <name>
Greetings earthling
    --help Prints command help message

$ greeting michael
hello michael

$ greeting
Missing required positional arguments: <name>

$ greeting michael jordan
Extra positional arguments: jordan

$ greeting "michael jordan"
hello michael jordan

Installation

Install knevee globally using npm to use it from anywhere on your system:

npm install knevee -g

Alternativley you can execute a single file like this

npx knevee ./file.js

Configuration Options

knevee supports a robust set of configuration options to tailor your scripts. Here's what you can customize:

| option | required | type | description | | ------------ | -------- | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | | name | No | string | The name of the module. (defaults to filename) | | description | No | string | A description of what the module does. | | dependencies | No | strings[] | A list of dependencies required by the module. | | positionals | No | strings | string[] | Positional arguments that the module accepts. Can be specified as an array or a space-separated string. | | flags | No | FlagsOption | A mapping of command line flags to their settings. | | default | Yes | function | The default function that executes when the module is run. | | strictFlags | No | boolean | Specifies if the flags should be strictly validated against the provided flags definitions. | | stdin | No | loop, loopJson, loopLines, true, false | Defines how the stdin should be handled. (defaults to loop) | | | | loop | Enables stdin and both loopJson and loopLines | | | | loopJson | Reads from stdin if JSON input is array loops over each item executing the script multiple times. | | | | loopLines | Reads from stdin and splits it at \n and loops over each item executing the script multiple times. | | | | true | Reads from stdin and passes all of it as one arg. | | | | false | Disables reading from stdin. | | output | No | bool, json, lines, stdout, bash, false | Specifies the output mode of the module. (defaults to stdout) | | | | bool | Expects function to return boolean value, adds --emoji, --int flags to command. | | | | json | Outputs the result as a JSON string, pretty prints the result. | | | | lines | Expects array, and will output each item on a line. | | | | stdout | Prints the value. | | | | bash | Expects function to return string, and executes it using zx, adds --print flag to the command, which prints the string. | | | | false | Disables output. | | unshiftStdin | No | boolean | Determines if stdin should be unshifted into args. (defaults to true) |