Socket
Socket
Sign inDemoInstall

jeval

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jeval

Map Reduce Filter etc using JS on the command line


Version published
Weekly downloads
9
Maintainers
1
Install size
5.33 kB
Created
Weekly downloads
 

Readme

Source

JEval

What is this?

A tool that allows you to use Javascript when mapping over lines from stdin. Meant to be used when mapping over results from a shell command. This can also handle reduce and filter and probably other functional methods that I have not demoed below.

For a similar tool with more options checkout jsin

Example of map - Print out each line with an @ symbol appended
echo "hey\nthere\n" | jeval "console.log(this.l + \"@\")"
Example of filter - filtering for only strings including "there"
echo "hey\nthere\n" | jeval "this.l.includes(\"there\") && console.log(this.l + \"@\")"
Example of reduce - Start with an empty array, push each line onto the array, when done iterating over everything run the last line
  • The final eval string occurs so that you can figure out how to want to return the accumulator. As JSON for example or maybe line by line to be mapped over again
echo "hey\nthere\n" | jeval "[]" "console.log(this.l + \"@\"); this.a.push(this.l);" "console.log(this);"
  • A demo showing map then reduce
echo "hey\nthere\nmy\nname\nis\nbrad" | jeval "console.log(this.l.toUpperCase())" | jeval "([])" "this.l.length > 3 && this.a.push(this.l);" "console.log(this);"

FAQs

Last updated on 05 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc