Object-parser-cli
the Object preprocessor.
Installation
$ npm install object-parser-cli --global$ opc -V# 0.0.0-alpha.0
$ opc # Usage: opc <file/url> [path/locator...] [options...] # # Options: # # -h, --help output usage information # -S, --stdin use the stdin # -V, --version output the version number # -t, --transform <type> Transform to <json/json5/yaml/html> # -i, --indent <digit> Adjust indents <2>
Transform
opc <file/url> --transfrom <type>
Convert other format the passed value. (alias -t
)
Support the <type>
: json
, json5
, yaml
, html
JsonML
JSON / JSON5 /# foo.json: [["body",["h1",{"foo":"bar"},"baz"]]] $ opc foo.json --transfrom json5# [["body",["h1",{foo:"bar"},"baz"]]] $ opc foo.json --transfrom yaml# - # - body # - [h1, {foo: bar}, baz] $ opc foo.json --transfrom html# <body> # <h1 foo="bar">baz</h1> # </body>
YAML
# foo.yml: '-\n - body\n - [h1, {foo: bar}, baz]' > $ opc foo.yml --transfrom json# [["body",["h1",{"foo":"bar"},"baz"]]] $ opc foo.yml --transfrom json5# [["body",["h1",{foo:"bar"},"baz"]]] $ opc foo.yml --transfrom html# <body> # <h1 foo="bar">baz</h1> # </body>
DOM
Traversing the opc <file/url> locator [locator...]
# example.html: <title>foo</title> $ opc example.html title # foo # example.xml: <body id="baz"><h1>bar</h1></body> $ opc example.xml body # bar $ opc example.xml body?id # baz # example.json: [["li",["a",{"href":"booooop"}],"beep"]] $ opc example.json li # beep $ opc example.json "li a"?href # booooop
locator
is selector?attribute
.
selector
is https://github.com/fb55/css-select#supported-selectors
Get text() if selector hasn't ?attribute
.
Object
Get the value of opc <file/url> path [path...]
# bower.json: {"name":"bar","ignore":["baz","beep","boop"]} $ opc bower name # bar $ opc bower ignore # baz beep boop $ opc bower name ignore # bar baz beep boop # .travis.yml: language: node_js $ opc .travis.yml language # node_js
Note: extension .json
is optional.
path
is https://lodash.com/docs#get
Options
-s
, --separator
$ opc bower name ignore --separator " && " # bar && baz && beep && boop