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

jpipe

v1.2.0

Published

stream editor using javascript expressions

Downloads

7

Readme

JPipe npm

stream editor using javascript

Installation

Run npm install -g jpipe, and then use the jp command as described:

  Usage: jp [options] <expression>

  A stream editor in javascript. Evaluates <expression> for each
  line of STDIN, where:

       _ = the current line
   _line = the current line number (starting at 0)
   _prev = the previous result of the expression
           (starts as '' or as [value] if --initial is set)

   chalk = the 'chalk' module.

   other modules are included with the -m flag. For example,
   '-m "module-name"' assigns 'require("module-name")' to
   'moduleName'.

  Options:

    -h, --help             output usage information
    -V, --version          output the version number
    -m, --module [module]  include a module in your expression
    -r, --reduce           print only the last value computed
    -i, --initial [value]  set the inital value of "_prev"
    -s, --swallow          swallow errors
    -t, --trim             trim whitespace from output
    -n, --nonewline        don't add newline (as `echo -n`)
    -f, --falsey           don't remove any falsy values

Usage

cat numbers.txt | jp '+_ + 10' > numbers_plus_ten.txt

Each line of the file numbers.txt is assigned to the variable _, and the result of +_ + 10 is printed to STDOUT, which is then redirected into numbers_plus_ten.txt.

If the result of this computation is a falsey value (other than 0, which is allowed for convenience), then it will not be output.

Bindings

Some special values come bound in the expression you give jp:

  • _ is bound to the current line of the file.
  • _line is bound to the current line number of the file (starting at 0).
  • _prev is bound to the result of the last expression.
  • chalk is bound to the module chalk, which is very convenient for coloring output.

any additional modules you include with the -m flag will be required, and assigned to a camel-case variable name (module-name is assigned to moduleName). If you wish to include globally installed modules, make sure to add your global node_modules to NODE_PATH:

export NODE_PATH="$(npm prefix -g)/lib/node_modules:$NODE_PATH"

Examples

Print all lines of a file in yellow

cat text.txt | jp --falsey 'chalk.yellow(_)'

Sum all numbers in a file

cat numbers.txt | jp --reduce '+_prev + +_'

Sum second whitespace-separated column in a file

cat tabular.txt | jp --reduce '+_prev + +(_.split(/\s+/)[1])'`

Prepend every line with some random hex

cat text.txt | jp --module 'crypto' 'crypto.randomBytes(2).toString("hex") + " " + _'

Get field value from each line of a file (where each line is a JSON object)

cat objs.txt | jp 'JSON.parse(_).value'

Concatenate all arrays in a file of JSON arrays

cat rows.txt | jp --reduce --initial '[]' 'JSON.parse(_prev).concat(JSON.parse(_))'

List all .js files in green

ls | jp '_.match(/\.js$/)? chalk.green(_):_'

Print all git commits whose hashes begin in a 7

git log --pretty=oneline | jp '_.charAt(0) === "7" && _'

Print some funky colored lines

yes | jp -n 'r = (Math.random() * 6) | 0;
  [chalk.red, chalk.green, chalk.yellow, chalk.blue, chalk.magenta, chalk.cyan][r]
  ((Math.random() * 2 | 0 % 2)? "____":"_/^\\_")'