postcore

0.1.0 • Public • Published

postcore npmjs.com The MIT License npm downloads

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')

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

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

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

.stringify

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

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

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Readme

Keywords

Package Sidebar

Install

npm i postcore

Weekly Downloads

3

Version

0.1.0

License

MIT

Last publish

Collaborators

  • vanchoy
  • tunnckocore