hosejs
javascript pipe, jq alternative
Last updated 2 years ago by deptno .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hosejs 
SYNC missed versions from official npm registry.

HoseJS CircleCI

npm

:tada: Data handling with ramda.js (version 1.3 or higher)

hosejs

100% code coverage.

You can transform JSON(or NOT) data with just JavaScript in terminal.

jq? javascript is clearly better option for people already use javascript.

Feature

Data handling with ramda.js (version 1.3 or higher)

You can use ramda.js

eg. http https://swapi.co/api/people/1/ | j -r "props(['name', 'height'])"
eg. http https://swapi.co/api/people/1/ | j -ramda "props(['name', 'height'])"
eg. http https://swapi.co/api/people/1/ | j "props(['name', 'height'])(_)"

Options

  • --file option provide you to apply pre-defined script first
  • --tab if result is Object, print JSON format with specified tab size (default: 2)

Install

npm -g install hosejs

Command

j or js

Usage

_ is everything you need to know

$ cat some.json | j '_.map(x => x.timestamp)'
$ cat some.json | j '_.map(x => x.timestamp)' --tab 4
$ cat some.json | j '_.map(x => x.timestamp)' --file pre.js --tab 2
$ cat some.json | j '_.map(x => x.timestamp)' > some.json
$ cat some.json | j '[_].map(x => x.some_property + '????')[0]'
$ cat some.json | j '_.map(x => new Date(x.timestamp).toISOString())'
$ cat some.json | j --file preload.js '_.map(x => x.timestamp)'
$ http https://swapi.co/api/people/ | j 'Object.keys(_)'
$ http https://swapi.co/api/people/ | j '_.count'
$ http https://swapi.co/api/people/ | j '_.results.map(x => x.name)'
$ echo 'not json string \n !!' | j '_.split("\n")'
$ http https://swapi.co/api/people/1/ | j -r "props(['name', 'height'])"  
$ http https://swapi.co/api/people/1/ | j -ramda "props(['name', 'height'])"  
$ http https://swapi.co/api/people/1/ | j "props(['name', 'height'])(_)"

Inject script file

IIFE

// cw-oneline.js
(() => {
  const time = time => new Date(time).toISOString().slice(0, -5).replace('T', ' ')
  return _.map(x => `${time(x.timestamp)} ${x.message}`)
})()
cat downloaded-cw-log.json | j -f cw-oneline.js > deptno.latest.json

Hmm ... Is it easy to look upside down?

add _.reverse()

cat downloaded-cw-log.json | j -f cw-oneline.js '_.reverse()' > deptno.latest.json

License

MIT

Current Tags

  • 1.3.0                                ...           latest (2 years ago)

9 Versions

  • 1.3.0                                ...           2 years ago
  • 1.2.0                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |