@kcpaulsen/slrp
Making node one-liners great again
Last updated a month ago by kcpaulsen .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @kcpaulsen/slrp 
SYNC missed versions from official npm registry.

slrp

Make the node command line great again

Getting Started

npm install -g @kcpaulsen/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", "[]" or "." 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

slurp stdin string 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-convert, and use as stdin

  slrp -f 'path/to/file/here' 'x => someFunctionHere()'

Bash autocompletion

slrp can take advantage of 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

Current Tags

  • 2.0.0                                ...           latest (a month ago)

68 Versions

  • 2.0.0                                ...           a month ago
  • 1.8.4                                ...           3 months ago
  • 1.8.3                                ...           3 months ago
  • 1.8.2                                ...           3 months ago
  • 1.8.1                                ...           4 months ago
  • 1.8.0                                ...           4 months ago
  • 1.7.13                                ...           4 months ago
  • 1.7.12                                ...           5 months ago
  • 1.7.11                                ...           5 months ago
  • 1.7.10                                ...           5 months ago
  • 1.7.9                                ...           5 months ago
  • 1.7.8                                ...           5 months ago
  • 1.7.7                                ...           5 months ago
  • 1.7.6                                ...           5 months ago
  • 1.7.5                                ...           5 months ago
  • 1.7.4                                ...           5 months ago
  • 1.7.3                                ...           5 months ago
  • 1.7.2                                ...           5 months ago
  • 1.7.1                                ...           5 months ago
  • 1.7.0                                ...           5 months ago
  • 1.6.6                                ...           5 months ago
  • 1.6.5                                ...           5 months ago
  • 1.6.4                                ...           5 months ago
  • 1.6.3                                ...           5 months ago
  • 1.6.2                                ...           5 months ago
  • 1.6.1                                ...           5 months ago
  • 1.6.0                                ...           5 months ago
  • 1.5.4                                ...           6 months ago
  • 1.5.3                                ...           6 months ago
  • 1.5.2                                ...           6 months ago
  • 1.5.1                                ...           6 months ago
  • 1.5.0                                ...           6 months ago
  • 1.4.3                                ...           6 months ago
  • 1.4.2                                ...           6 months ago
  • 1.4.1                                ...           6 months ago
  • 1.4.0                                ...           6 months ago
  • 1.3.5                                ...           6 months ago
  • 1.3.4                                ...           6 months ago
  • 1.3.3                                ...           6 months ago
  • 1.3.2                                ...           6 months ago
  • 1.3.1                                ...           6 months ago
  • 1.3.0                                ...           6 months ago
  • 1.2.15                                ...           6 months ago
  • 1.2.14                                ...           6 months ago
  • 1.2.13                                ...           6 months ago
  • 1.2.12                                ...           6 months ago
  • 1.2.11                                ...           6 months ago
  • 1.2.10                                ...           6 months ago
  • 1.2.9                                ...           6 months ago
  • 1.2.8                                ...           6 months ago
  • 1.2.7                                ...           6 months ago
  • 1.2.6                                ...           6 months ago
  • 1.2.5                                ...           6 months ago
  • 1.2.4                                ...           6 months ago
  • 1.2.3                                ...           6 months ago
  • 1.2.2                                ...           6 months ago
  • 1.2.1                                ...           6 months ago
  • 1.2.0                                ...           6 months ago
  • 1.1.7                                ...           6 months ago
  • 1.1.6                                ...           6 months ago
  • 1.1.5                                ...           6 months ago
  • 1.1.4                                ...           6 months ago
  • 1.1.3                                ...           6 months ago
  • 1.1.2                                ...           6 months ago
  • 1.1.1                                ...           6 months ago
  • 1.1.0                                ...           7 months ago
  • 1.0.1                                ...           7 months ago
  • 1.0.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 68
This Month 68
Last Day 0
Last Week 0
Last Month 11
Dependencies (7)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |