postcore
Processor engine for Post* family like PostCSS, PostHTML and PostJSON.
Install
npm i postcore --save
Usage
For more use-cases see the tests
const postcore =
PostCore
Initialize
PostCore
withplugins
andoptions
. Plugins can also be passed inoptions.plugins
. Notice thatPostCore
is built on base, so you have access to all of its builtin methods like.use
,.set
,.get
.has
,.define
,.visit
and so on.
Params
plugins
{Array|Object}: plugins to be used, oroptions
objectoptions
{Object}: options to control some stuff
.parse
Parse given
input
usingthis.options.parser
.
Params
input
{String|Object}: input text to be parsed oroptions
objectoptions
{Object}: options object merged intothis.options
returns
{Mixed}: the result of the given parser
.process
Passing
input
to.parse
method 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 oroptions
objectoptions
{Object}: options object merged intothis.options
returns
{Promise}: with object containing metadata and stringified result
.stringify
Stringify given
ast
to string, usingthis.options.stringifier
.
Params
ast
{Array|Object}: object or array tree, ast to be stringifiedoptions
{Object}: options object merged intothis.options
returns
{Mixed}: the result of the given stringifier
.use
Add plugin to the stack. It follows the "smart" plugins concept coming from base project, because
PostCore
is 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.options
returns
{PostCore}: instance for chaining
Example
var postcore = postcore
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.