object-parser-cli
Object preprocessor
Last updated 5 years ago by 59naga .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install object-parser-cli 
SYNC missed versions from official npm registry.

Object-parser-cli NPM version Build Status Coverage Status

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

JSON / JSON5 / JsonML

# 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>

Traversing the DOM

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.

Get the value of Object

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

License

MIT

Current Tags

  • 0.0.1                                ...           latest (5 years ago)

5 Versions

  • 0.0.1                                ...           5 years ago
  • 0.0.1-alpha.1                                ...           5 years ago
  • 0.0.1-alpha.0                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
  • 0.0.0-alpha.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |