# @kristopherpaulsen/slrp

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

Latest version **2.4.2** (published 2021-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kristopherpaulsen/slrp
pnpm add @kristopherpaulsen/slrp
yarn add @kristopherpaulsen/slrp
bun add @kristopherpaulsen/slrp
```

Provides the command `slrp`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.2 |
| Published | 2021-09-25 |
| First published | 2021-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kristopher C. Paulsen |
| Maintainers | kristopherpaulsen |
| Keywords | cli |

## Links

- npm: https://www.npmjs.com/package/@kristopherpaulsen/slrp
- Repository: https://github.com/kristopherpaulsen/slrp
- Homepage: https://github.com/kristopherpaulsen/slrp#readme
- Issues: https://github.com/kristopherpaulsen/slrp/issues
- npm.io page: https://npm.io/package/@kristopherpaulsen/slrp

## Dependencies (10)

- [esm](https://npm.io/package/esm.md) ^3.2.25
- [tmp](https://npm.io/package/tmp.md) ^0.2.1
- [yaml](https://npm.io/package/yaml.md) ^1.10.0
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [yargs](https://npm.io/package/yargs.md) ^15.3.1
- [xml-js](https://npm.io/package/xml-js.md) ^1.6.11
- [get-stdin](https://npm.io/package/get-stdin.md) ^7.0.0
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.6.3
- [indent-string](https://npm.io/package/indent-string.md) ^4.0.0
- [json-colorizer](https://npm.io/package/json-colorizer.md) ^2.2.1

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.4.2 (latest) — 2021-09-25
- 2.4.0 — 2021-08-09

## README

# slrp

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


## Getting Started

```bash
npm install -g @kristopherpaulsen/slrp
```

```bash
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.

```bash
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

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

or

```bash
echo "Get that length" | slrp .length
```

or

```bash
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)

```bash
  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

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

  # Hello
```

`-w`

split stdin into array of strings by whitespace

```bash
  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`

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

`-p`

slurp file without auto parsing, treated as text

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

`-l`

slrp file and work line-by-line

```bash
  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);

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

`-i -f`

slurp file and edit in place with auto parsing

```bash
  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;

```bash
  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!
```shell
  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!

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

# 11
```


## About

Heavily inspired by fx and other node command line utilities

---
_Source: https://npm.io/package/@kristopherpaulsen/slrp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
