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

@kristopherpaulsen/slrp

v2.4.2

Published

Command line tool for editing text, json, yaml, and xml, as well as data munging through handy functional one-liners

Downloads

8

Readme

slrp

Command line tool for editing text, json, yaml, and xml, as well as data munging through handy functional one-liners

Getting Started

npm install -g @kristopherpaulsen/slrp
echo -e "Hello\nWorld" | slrp -n .length

echo "Hello, World" | slrp 'x => x.split(" ")' [0].length

echo "Hello World" | slrp -w .length

echo "Hello World" | slrp -w this.length

curl pants.rip/echo | slrp -j .reqHeaders.host .length

slrp -f /path/to/file.json 'json => ({ ...json, newKey: "value" })'

Chaining Functions

slrp allows for chaining results of one function to another.

echo "Hello, World" | slrp 'x => x.split(" ")' 'x => x.map(word => word.length)'

[
  6,
  5
]

Property Assessor Shorthand

You can also use the property assessor shorthand for easier manipulation. You can use this, [], . for easier access

echo "Hello, World" | slrp 'x => x.split(" ")' [0].length

or

echo "Get that length" | slrp .length

or

echo "Hello" | slrp 'split("\w")' this.length

Flags

slrp provides multiple flags for easier one-liners.

-j, -x, -y

convert stdin string (json, xml, yaml) into parsed object. (See property assessor shorthand for easy access and manipulation)

  curl pants.rip/echo | slrp -j .

  {
    "reqCookies": {},
    "url": "/",
    "params": {},
    "body": {},
    "query": {},
    "reqHeaders": {
      "host": "pants.rip",
      "x-real-ip": "136.60.239.136",
      "x-forwarded-proto": "https",
      "x-forwarded-for": "136.60.239.136",
      "x-forwarded-host": "136.60.239.136",
      "connection": "close",
      "user-agent": "curl/7.58.0",
      "accept": "*/*"
    },
    "resHeaders": {
      "x-powered-by": "Express"
    }
  }

-n

split stdin into array of strings by newline

  echo -e "Hello\nWorld" | slrp -n [0]

  # Hello

-w

split stdin into array of strings by whitespace

  echo -e "Hello World" | slrp -w [1]

  # World

-f

slurp file by type, auto parse, and use as stdin. Supports .yaml, .yml, .js, .json, .xml

  slrp -f 'path/to/file/here.json' 'ojbect => object.someKey'

-p

slurp file without auto parsing, treated as text

  slrp -p '/path/to/file/here' 'text => someFunction(text)'

-l

slrp file and work line-by-line

  slrp -i -p '/path/to/file/here.txt' 'line => doSomething(line)' 'line => anotherThing(line)'

-i -p

slurp file and edit in place (no auto parsing);

  slrp -i -p '/path/to/file/here.txt' 'text => someFunction(text)'

-i -f

slurp file and edit in place with auto parsing

  slrp -i -f '/path/to/file/here.json' 'json => ({ ...json, keyHere: "newValue" })'

-l -i -p

slurp file, edit in place (no auto parsing), line-by-line;

  slrp -l -i -p '/path/to/file/here.txt' 'line => doSomethingToLine(line)'

Bash autocompletion

slrp can take advantage of bash autcompletion

slrp --update-bash-completion

Source the script!

  Success!: Add the following to your .bashrc or .bash_profile

  source $HOME/.config/slrp/slrp-bash-completion.sh

Custom Functions

You can include custom functions to be imported / required as part of slrp. Any functions installed globally by npm, and included in the config file will be available

  • Add to $HOME/.config/slrp/index.js
module.exports = {
  globalFunctions: {
    ...require('lodash/fp'),
  }
}

Use Custom functions (like lodash/fp) for elegant functional composition, right from the command line!

echo "Hello, World" | slrp 'split(" ")' 'map(size)' sum

# 11

About

Heavily inspired by fx and other node command line utilities