postcore v0.1.0
postcore

Processor engine for Post* family like PostCSS, PostHTML and PostJSON.
Install
npm i postcore --saveUsage
For more use-cases see the tests
const postcore = require('postcore')PostCore
Initialize
PostCorewithpluginsandoptions. Plugins can also be passed inoptions.plugins. Notice thatPostCoreis built on base, so you have access to all of its builtin methods like.use,.set,.get.has,.define,.visitand so on.
Params
plugins{Array|Object}: plugins to be used, oroptionsobjectoptions{Object}: options to control some stuff
.parse
Parse given
inputusingthis.options.parser.
Params
input{String|Object}: input text to be parsed oroptionsobjectoptions{Object}: options object merged intothis.optionsreturns{Mixed}: the result of the given parser
.process
Passing
inputto.parsemethod and then pass parsed data to the plugins. After all, pass it to the.stringify(so,this.options.stringifier) and return Promise with the result object.
Params
input{String|Object}: input text to be parsed oroptionsobjectoptions{Object}: options object merged intothis.optionsreturns{Promise}: with object containing metadata and stringified result
.stringify
Stringify given
astto string, usingthis.options.stringifier.
Params
ast{Array|Object}: object or array tree, ast to be stringifiedoptions{Object}: options object merged intothis.optionsreturns{Mixed}: the result of the given stringifier
.use
Add plugin to the stack. It follows the "smart" plugins concept coming from base project, because
PostCoreis built on it internally, so you can use any of its plugins here.
Params
fn{Function|Array}: plugin function or array of pluginsopts{Object}: options merged with thethis.optionsreturns{PostCore}: instance for chaining
Example
var postcore = require('postcore')
postcore
.use([plugin, plugin, plugin], { foo: 'bar' })
.use(function (app) {
// `app` and `this` context are the instance of `postcore`
return function plugin (ctx) {
// `ctx` and `this` are the same and comes internally
// from `.process` - it is the `this.cache` object
// which can be used for sharing context between plugins.
}
})
.process('some string', { options: 'foo' })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.