Skip to content

Processor engine for Post* family like PostCSS, PostHTML and PostJSON. Built on Base. (@node-base)

License

Notifications You must be signed in to change notification settings

postcore/postcore

Repository files navigation

Processor engine for Post* family like PostCSS, PostHTML and PostJSON.

code climate standard code style travis build status coverage status dependency status

Install

npm i postcore --save

Usage

For more use-cases see the tests

const postcore = require('postcore')

Initialize PostCore with plugins and options. Plugins can also be passed in options.plugins. Notice that PostCore 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, or options object
  • options {Object}: options to control some stuff

Parse given input using this.options.parser.

Params

  • input {String|Object}: input text to be parsed or options object
  • options {Object}: options object merged into this.options
  • returns {Mixed}: the result of the given parser

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 or options object
  • options {Object}: options object merged into this.options
  • returns {Promise}: with object containing metadata and stringified result

Stringify given ast to string, using this.options.stringifier.

Params

  • ast {Array|Object}: object or array tree, ast to be stringified
  • options {Object}: options object merged into this.options
  • returns {Mixed}: the result of the given stringifier

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 plugins
  • opts {Object}: options merged with the this.options
  • returns {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.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Processor engine for Post* family like PostCSS, PostHTML and PostJSON. Built on Base. (@node-base)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages