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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ryantate/js-cli

v1.1.4

Published

Quickly pipe stdin from scripts to a JS lambda or expression

Downloads

17

Readme

CI Status codecov

js-cli

Command line script to transform stdout from shell scripts using a JS lambda or expression. Inspired by fx but meant to be more general for parsing either raw text or JSON. CSV, TOML and YAML support is provided in the scope of the lambda or expression by the corresponding global variables CSV, TOML and YAML, each offering a similar parse/stringify interface as that of the native JSON (with some caveats, refer to example code below to see where parse or stringify might accept a second options argument for a given data type).

Installation

npm i -g @ryantate/js-cli

Usage

js (-s | -h | -v) 'handler_code'
    -s | --stream - Streaming mode, handle input line by line
    -h | --help - Show this help message and quit
    -v | --version Show the version number and quit

Pipe data in to js and supply a lambda or expression to parse it with. The invoked expression or lambda will have this bound to either all of stdin when processing line by line, or the individual line when in streaming mode. The value returned from a lambda or the result of an inline expression will be logged to the console. Undefined or null values will not be logged. Promises returned will be resolved and then logged.

Packages installed either globally or in the current working directory are accessible via require in this scope (see examples below).

Examples

Working with CSV, TOML or YAML data

Powered by the Papa Parse, @ltd/j-toml and yaml libraries respectively. Refer to external documentation for specifics as to their functionality. Each library is available to handler functions as the global variables CSV, TOML and YAML. The CSV global is actually a wrapper around Papa Parse to enable header parsing by default for csv data and to offer a stringify function (vs. the upstream unparse), bringing it in line with the interface available in JSON and the other supported data formats.

# csv with header row
cat file.csv | js 'CSV.parse(this)'
# csv without headers
cat file.csv | js 'CSV.parse(this, {headers: false})'
# output csv data
cat array_of_objects.json | js 'CSV.stringify(JSON.parse(this))' > out.csv # keys of first object become header row
cat array_of_arrays.json | js 'CSV.stringify(JSON.parse(this))' > out.csv # no headers in output csv

# reading TOML data
cat Cargo.toml | js 'TOML.parse(this)'
# outputting TOML
curl my.api | js 'TOML.stringify(JSON.parse(this), {newline: "\n"})' # note that it is necessary to specify newline character

# single yaml document
cat file.yaml | js 'YAML.parse(this)'
# multi-document yaml
cat multi.yaml | js 'YAML.parseAllDocuments(this).map(doc => doc.toJSON())'
# outputting YAML
cat data.csv | js 'YAML.stringify(CSV.parse(this))'

Sum all numbers in a file

js 'this.trim().split(/\s/+).map(Number).reduce((a,b) => a+b, 0)' < file_of_numbers.txt

Curl-like

npm i -g node-fetch
cat urls.txt | js --stream 'require("node-fetch")(this).then(res => res.json())'

HTML Parsing

npm i -g cheerio
curl https://some_website.org | js 'html => require("cheerio").load(html).find("p").length'

Largest number per line in a CSV file

cat data.csv | js --stream 'line => Math.max(...line.split(",").map(val => Number(val) || -Infinity))'

Create a directory index

find . -type f | sort | js 'JSON.stringify(this.split("\n").filter(Boolean), null, 2)' > index.json

Update all dependencies in package.json

cat package.json | js 'Object.keys(JSON.parse(this).dependecies).forEach(d => console.log(d))' | xargs npm install

Concatenate MP3 files with ffmpeg

ffmpeg \
	-i \
	concat:$(find . -type f -name '*.mp3' | js 'this.split("\n").sort().join("|")') \
	-codec:a libmp3lame \
	concatenated.mp3

Convert CSV to JSON

cat data.csv | js 'JSON.stringify(CSV.parse(this))'