@northscaler/ymlx
v1.0.1
Published
Command-line YAML processing tool
Downloads
21
Readme
Command-line YAML processing tool
Features
- Plain JavaScript to manipulate document(s)
Install
$ npm install -g ymlxUsage
Pipe into ymlx any YAML and anonymous function for reducing it.
$ cat my.yaml | ymlx [code ...]Anonymous function
Use an anonymous function as reducer which gets YAML as an object and processes it:
$ echo 'foo: [bar: value]' | ymlx 'x => x.foo[0].bar'
valuethis Binding
If you don't pass anonymous function param => ..., code will be automatically transformed into anonymous function.
And you can get access to YAML by this keyword:
$ echo 'foo: [bar: value]' | ymlx 'this.foo[0].bar'
valueMultiple Documents
You can pass a YAML file with multiple documents (using the --- separator), and your commands will be applied to each document.
# test.yml
---
foo:
- bar: value
---
foo:
- bar: another$ cat test.yml | ymlx 'this.foo[0].bar'
---
value
---
anotherChain
You can pass any number of anonymous functions for reducing JSON:
$ echo 'foo: [bar: value]' | ymlx 'x => x.foo' 'this[0]' 'this.bar'
valueGenerator
If passed code contains yield keyword, generator expression
will be used:
$ curl ... | ymlx 'for (let user of this) if (user.login.startsWith("a")) yield user'Access to YAML through this keyword:
# test.yml
- a
- b$ cat test.yml | ymlx 'yield* this'
- a
- b$ cat test.yml | ymlx 'yield* this; yield "c";'
- a
- b
- cUpdate
You can update existing YAML using spread operator:
$ echo 'count: 0' | ymlx '{...this, count: 1}'
count: 1Use npm package
Use any npm package by installing globally or in the current working directory:
$ npm install lodash # -g if you want
$ cat 'count: 0' | ymlx 'require("lodash").keys(this)'
- countFormatting
$ echo '[1,2,3]' | ymlx 'this.reduce((a,n) => a += n.toString(), "concat: ")'
'concat: 123'Inspiration
ymlx was inspired by fx
Related
- jq – cli JSON processor on C
- jsawk – like awk, but for JSON
- json – another JSON manipulating cli library
- jl – functional sed for JSON on Haskell
License
MIT
