{"id":13453636,"url":"https://github.com/danielstjules/pjs","last_synced_at":"2025-04-05T01:09:36.182Z","repository":{"id":19534383,"uuid":"22782106","full_name":"danielstjules/pjs","owner":"danielstjules","description":"Pipeable javascript. Quickly filter, map, and reduce from the terminal","archived":false,"fork":false,"pushed_at":"2023-02-09T08:55:17.000Z","size":59,"stargazers_count":420,"open_issues_count":2,"forks_count":19,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-02T00:38:01.760Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielstjules.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-08-09T08:14:16.000Z","updated_at":"2025-04-01T19:01:15.000Z","dependencies_parsed_at":"2024-01-02T20:54:14.256Z","dependency_job_id":null,"html_url":"https://github.com/danielstjules/pjs","commit_stats":{"total_commits":73,"total_committers":7,"mean_commits":"10.428571428571429","dds":0.09589041095890416,"last_synced_commit":"8621d79152f0d740f91b7f1e538dde8722f9580d"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fpjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fpjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fpjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielstjules%2Fpjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielstjules","download_url":"https://codeload.github.com/danielstjules/pjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271532,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:44.778Z","updated_at":"2025-04-05T01:09:36.164Z","avatar_url":"https://github.com/danielstjules.png","language":"JavaScript","readme":"![pjs](http://danielstjules.com/github/pjs-logo.png)\n\nPipeable JavaScript - another utility like sed/awk/wc... but with JS! Quickly\nfilter, map and reduce from the command line. Features a streaming API.\nInspired by pipeable ruby.\n\n[![Build Status](https://api.travis-ci.org/danielstjules/pjs.svg?branch=master)](https://travis-ci.org/danielstjules/pjs)\n\n## Overview\n\npjs is a cli tool that can accept input on stdin, or read from a list of files.\nIts filter, map and reduce options take expressions to be run, in that order,\nand applies them to the supplied input. The expressions themselves can contain\nidentifiers used by keys in String.prototype, which will automatically be bound\nto the given line. This lets you save a bit of typing with your one-liners,\nwhile still giving you access to all your JS string functions! Check out some\nof the examples below to see how they translate.\n\n``` bash\n# Return all lines longer than 5 chars\n# =\u003e lines.filter(function(line) { return line.length \u003e 5; });\nls -1 | pjs -f 'length \u003e 5'\n\n# Count characters in each line\n# =\u003e lines.map(function(line) { return line.length; });\nls -1 | pjs -m 'length'\n\n# Uppercase and pad each line\n# =\u003e lines.map(function(line) { return '  ' + line.toUpperCase()\"; });\nls -1 | pjs -m '\"  \" + toUpperCase()'\n\n# Return lines longer than 5 chars, and remove any digits\n# =\u003e lines\n#      .filter(function(line) { return line.length \u003e 5; })\n#      .map(function(line) { return line.replace(/\\d/g, ''); });\nls -1 | pjs -f 'length \u003e 5' -m 'replace(/\\d/g, \"\")'\n```\n\nThe current line and value can also be accessed via the `$` variable, and the\ntool supports json output.\n\n``` bash\n(echo 'foo' \u0026\u0026 echo 'foobar') | pjs -jm '{name: $, length: length}'\n[\n{\"name\":\"foo\",\"length\":3},\n{\"name\":\"foobar\",\"length\":6}\n]\n```\n\npjs also includes lodash functions, which can be accessed via the `_` object,\nand chained using $$\n\n``` bash\necho 'hello' | pjs -m '_.upperFirst($)'\n# Hello\n\necho 'please-titleize-this-sentence' | \\\npjs -m '$$.lowerCase().split(\" \").map(_.upperFirst).join(\" \")'\n# Please Titleize This Sentence\n```\n\nas well as Ramda and point-free style\n\n``` bash\necho 'please-titleize-this-sentence' | \\\npjs -m \"R.compose(R.replace(/(^|\\s)\\w/g, R.toUpper), R.replace(/-/g, ' '))\"\n# Please Titleize This Sentence\n```\n\n## Installation\n\nIt can be installed via `npm` using:\n\n```\nnpm install -g pipeable-js\n```\n\n## Usage\n\n```\nUsage: pjs [options] [files ...]\n\nFunctions and expressions are invoked in the following order:\nfilter, map, reduce\n\nAll functions are passed the line ($) and index (i)\nBuilt-in reduce functions: length, min, max, sum, avg, concat\nCustom reduce expressions accept: prev, curr, i, array\nIncludes lodash (_), and can be chained using $$\nSupports Ramda (R) and point-free style\n\nOptions:\n\n  -h, --help               output usage information\n  -V, --version            output the version number\n  -i, --ignore             ignore empty lines\n  -j, --json               output as json\n  -f, --filter \u003cexp\u003e       filter by a boolean expression\n  -m, --map \u003cexp\u003e          map values using the expression\n  -r, --reduce \u003cfunc|exp\u003e  reduce using a function or expression\n```\n\n## Examples\n\n### filter\n\n``` bash\n# Print all odd lines\n# awk 'NR % 2 == 1' file\npjs -f 'i % 2 == 0' file\n\n# Print all lines greater than 80 chars in length\n# awk 'length($0) \u003e 80' file\npjs -f 'length \u003e 80' file\n```\n\n### map\n\n``` bash\n# Remove all digits\n# tr -d 0-9 \u003c file\npjs -m \"replace(/\\d/g, '')\" file\n\n# Get second item of each line in csv\n# awk -F \",\" '{print $2}' file\npjs -m 'split(\",\")[1]' file\n```\n\n### reduce\n\n``` bash\n# Count lines in file\n# wc -l file\n# awk 'END { print NR }' file\npjs -r length file\n\n# Sum all decimal numbers in a file\n# awk '{ sum += $1 } END { print sum }' file\n# perl -nle '$sum += $_ } END { print $sum' file\npjs -r 'Number(prev) + Number(curr)' file\npjs -r '(+prev) + (+curr)' file\npjs -r sum file\n\n# Concatenate all lines in multiple files\n# awk '{printf $0;}' file1 file2\n# cat file1 file2 | tr -d '\\n'\npjs -r concat file1 file2\n```\n\n### mixed\n\n``` bash\n# Print the length of the longest line\n# awk '{ if (length($0) \u003e max) max = length($0) } END { print max }' file\npjs -m 'length' -r max file\n```\n\n## Comparison\n\n| Features              | pjs        | pythonpy               | pru        |\n|-----------------------|------------|------------------------|------------|\n| Language              | JavaScript | Python                 | Ruby       |\n| Streaming             | Yes        | Limited \u003csup\u003e[1]\u003c/sup\u003e | Yes        |\n| Implementation        | Streams    | Iterables              | Generators |\n| Easy JSON output      | Yes        | No                     | No         |\n| Webscale\u003csup\u003eTM\u003c/sup\u003e | YES        | No                     | No         |\n\n\u003csub\u003e[1] Can't perform \"tail -f logfile | py -x x\"\u003c/sub\u003e\n","funding_links":[],"categories":["Packages","JavaScript","包","others","Command-line apps","目录"],"sub_categories":["Command-line apps","命令行程序","命令行应用"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fpjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielstjules%2Fpjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielstjules%2Fpjs/lists"}