Home

Awesome

parser-cache NPM version

Cache and load parsers, similiar to consolidate.js engines.

Install

Install with npm

npm i parser-cache --save

Usage

var parsers = require('parser-cache');

API

Parsers

var Parsers = require('parser-cache');
var parsers = new Parsers();

.register

Register the given parser callback fn as ext. If ext is not given, the parser fn will be pushed into the default parser stack.

// Default stack
parsers.register(require('parser-front-matter'));

// Associated with `.hbs` file extension
parsers.register('hbs', require('parser-front-matter'));

.registerSync

Register the given parser callback fn as ext. If ext is not given, the parser fn will be pushed into the default parser stack.

// Default stack
parsers.register(require('parser-front-matter'));

// Associated with `.hbs` file extension
parsers.register('hbs', require('parser-front-matter'));

.parse

Run a stack of async parsers for the given file. If file is an object with an ext property, then ext is used to get the parser stack. If ext doesn't have a stack, the default noop parser will be used.

var str = fs.readFileSync('some-file.md', 'utf8');
template.parse({ext: '.md', content: str}, function (err, file) {
  console.log(file);
});

Or, explicitly pass an array of parser functions as a section argument.

template.parse(file, [a, b, c], function (err, file) {
  console.log(file);
});

.parseSync

Run a stack of sync parsers for the given file. If file is an object with an ext property, then ext is used to get the parser stack. If ext doesn't have a stack, the default noop parser will be used.

var str = fs.readFileSync('some-file.md', 'utf8');
template.parseSync({ext: '.md', content: str});

Or, explicitly pass an array of parser functions as a section argument.

template.parseSync(file, [a, b, c]);

.parseStream

Run a stack of stream parsers for input files.

gulp.src('path/to/files/*.md')
  .pipe(template.parseStream({ext: '.md'}))
  .pipe(gulp.dest('dist'));

Or, explicitly pass an array of parser functions as a section argument.

gulp.src('path/to/files/*.md')
  .pipe(template.parseStream([a, b, c], {ext: '.md'}))
  .pipe(gulp.dest('dist'));

.get

Return the parser stored by ext. If no ext is passed, the entire parsers is returned.

parser.get('md')
// => [function]

.clear

Remove the parser stack for the given ext, or if no value is specified the entire parsers object is clear.

Example:

parsers.clear()

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on October 01, 2014.