postjson
v0.1.3
Published
Transforming JSON with plugins.
Downloads
13
Readme
postjson
Transforming JSON with plugins.
Install
npm i postjson --save
Usage
For more use-cases see the tests
const postjson = require('postjson')
PostJSON
Initialize a PostJSON optionally with
plugins
andoptions
.
Params
plugins
{Array|Function}options
{Object}
.use
Add a
fn
as plugin.
Params
fn
{Functio|Array}options
{Object}returns
{PostJSON}: instance for chaining
.parse
Parse a
str
to abstract syntax tree (AST) and writes it to.tree
property of thethis
instance.
Params
str
{String}options
{Object}returns
{PostJSON}: instance for chaining
.render
Render a given
tree
. Or you can just use it in combination with.parse(str)
which writes thetree
to instance, then.render
will use it. If only one argument is passed it is assumed asoptions
.
Params
tree
{Object}: (optional) Abstract Syntax Tree, otherwise will usethis.tree
options
{Object}returns
{PostJSON}: instance for chaining
.toString
Returns stringified and already modified JSON.
Params
indent
{Object}returns
{String}
.process
Transforms a
val
using previously passed plugins. Think for it like.parse
plus.render
combination.
Params
val
{String}options
{Object}returns
{PostJSON}
.walk
Temporary here, could be plugin. Part of future API sugars for working with AST.
Params
tree
{Object|Array}fn
{Function}returns
{PostJSON}
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.