### Install Pipeable JavaScript (pjs) CLI Tool Source: https://github.com/danielstjules/pjs/blob/master/README.md Provides the command to globally install the `pipeable-js` CLI tool using npm, making it available for use in the terminal. ```Bash npm install -g pipeable-js ``` -------------------------------- ### Reduce Lines with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md Examples demonstrating the `-r` (reduce) option in `pjs` for aggregating data. It shows how to count lines, sum numbers, and concatenate lines using both built-in reduce functions and custom expressions. ```Bash # Count lines in file # wc -l file # awk 'END { print NR }' file pjs -r length file # Sum all decimal numbers in a file # awk '{ sum += $1 } END { print sum }' file # perl -nle '$sum += $_ } END { print $sum' file pjs -r 'Number(prev) + Number(curr)' file pjs -r '(+prev) + (+curr)' file pjs -r sum file # Concatenate all lines in multiple files # awk '{printf $0;}' file1 file2 # cat file1 file2 | tr -d '\n' pjs -r concat file1 file2 ``` -------------------------------- ### Apply Ramda Functions in pjs Expressions Source: https://github.com/danielstjules/pjs/blob/master/README.md Demonstrates how to use Ramda functions, accessible via the `R` object, within `pjs` expressions. This example showcases a point-free style for string manipulation. ```Bash echo 'please-titleize-this-sentence' | \ pjs -m "R.compose(R.replace(/(^|\s)\w/g, R.toUpper), R.replace(/-/g, ' '))" # Please Titleize This Sentence ``` -------------------------------- ### Map Lines with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md Examples illustrating the use of the `-m` (map) option in `pjs` to transform lines. It covers removing digits from lines and extracting specific fields from CSV formatted lines. ```Bash # Remove all digits # tr -d 0-9 < file pjs -m "replace(/\d/g, '')" file # Get second item of each line in csv # awk -F "," '{print $2}' file pjs -m 'split(",")[1]' file ``` -------------------------------- ### Filter Lines with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md Examples demonstrating how to use the `-f` (filter) option in `pjs` to select lines based on conditions. It shows filtering by line index (odd lines) and by line length. ```Bash # Print all odd lines # awk 'NR % 2 == 1' file pjs -f 'i % 2 == 0' file # Print all lines greater than 80 chars in length # awk 'length($0) > 80' file pjs -f 'length > 80' file ``` -------------------------------- ### Combine Map and Reduce Operations with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md An example showing how to combine map and reduce operations in `pjs` to find the length of the longest line in a file. It first maps each line to its length, then reduces the resulting lengths to find the maximum. ```Bash # Print the length of the longest line # awk '{ if (length($0) > max) max = length($0) } END { print max }' file pjs -m 'length' -r max file ``` -------------------------------- ### pjs Command Line Interface (CLI) Options Source: https://github.com/danielstjules/pjs/blob/master/README.md Documents the command-line options and arguments for the `pjs` tool. It details how functions and expressions are applied, available built-in reduce functions, and support for Lodash and Ramda. ```APIDOC Usage: pjs [options] [files ...] Functions and expressions are invoked in the following order: filter, map, reduce All functions are passed the line ($) and index (i) Built-in reduce functions: length, min, max, sum, avg, concat Custom reduce expressions accept: prev, curr, i, array Includes lodash (_), and can be chained using $$ Supports Ramda (R) and point-free style Options: -h, --help output usage information -V, --version output the version number -i, --ignore ignore empty lines -j, --json output as json -f, --filter filter by a boolean expression -m, --map map values using the expression -r, --reduce reduce using a function or expression ``` -------------------------------- ### Filter and Map Text Streams with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md Demonstrates basic `pjs` usage for filtering lines by length, mapping lines to their length or uppercased versions, and combining filter/map operations. It highlights how `pjs` binds string methods directly to the current line. ```Bash # Return all lines longer than 5 chars # => lines.filter(function(line) { return line.length > 5; }); ls -1 | pjs -f 'length > 5' # Count characters in each line # => lines.map(function(line) { return line.length; }); ls -1 | pjs -m 'length' # Uppercase and pad each line # => lines.map(function(line) { return ' ' + line.toUpperCase()"; }); ls -1 | pjs -m '" " + toUpperCase()' # Return lines longer than 5 chars, and remove any digits # => lines # .filter(function(line) { return line.length > 5; }) # .map(function(line) { return line.replace(/\d/g, ''); }); ls -1 | pjs -f 'length > 5' -m 'replace(/\d/g, "")' ``` -------------------------------- ### Generate JSON Output with pjs Source: https://github.com/danielstjules/pjs/blob/master/README.md Illustrates how to use `pjs` to transform input lines into JSON objects. The `$` variable represents the current line, allowing for dynamic object creation. ```Bash (echo 'foo' && echo 'foobar') | pjs -jm '{name: $, length: length}' ``` -------------------------------- ### Integrate Lodash Functions in pjs Expressions Source: https://github.com/danielstjules/pjs/blob/master/README.md Shows how `pjs` provides access to Lodash functions via the `_` object. It also demonstrates chaining operations using the `$$` variable for more complex transformations. ```Bash echo 'hello' | pjs -m '_.upperFirst($)' # Hello echo 'please-titleize-this-sentence' | \ pjs -m '$$.lowerCase().split(" ").map(_.upperFirst).join(" ")' # Please Titleize This Sentence ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.