Normalize the API of any jstransformer
npm install jstransformerNormalize the API of any jstransformer
npm install jstransformer
``js
var transformer = require('jstransformer');
var marked = transformer(require('jstransformer-marked'));
var options = {};
var res = marked.render('Some markdown', options);
// => {body: 'Some markdown', dependencies: []}
`
This gives the same API regardless of the jstransformer passed in.
A transformer, once normalised using this module, will implement the following methods. Note that if the underlying transformer cannot be used to implement the functionality, it may ultimately just throw an error.
`js`
{body: String, dependencies: Array.
- body represents the result as a stringdependencies
- is an array of files that were read in as part of the render process (or an empty array if there were no dependencies)
`js`
transformer.render(str, options, locals);
=> {body: String, dependencies: Array.
_requires the underlying transform to implement .render or .compile_
Transform a string and return an object.
`js`
transformer.renderAsync(str[, options], locals, callback);
`js`
transformer.renderAsync(str[, options], locals);
=> Promise({body: String, dependencies: Array.
_requires the underlying transform to implement .renderAsync or .render_
Transform a string asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.
`js`
transformer.renderFile(filename, options, locals)
=> {body: String, dependencies: Array.
_requires the underlying transform to implement .renderFile, .render, .compileFile, or .compile_
Transform a file and return an object.
`js`
transformer.renderFileAsync(filename[, options], locals, callback);
`js`
transformer.renderFileAsync(filename[, options], locals);
=> Promise({body: String, dependencies: Array.
_requires the underlying transform to implement .renderFileAsync, .renderFile, .renderAsync, .render, .compileFileAsync, .compileFile, .compileAsync, or .compileFile_
Transform a file asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.
`js`
var formats = transformer.inputFormats;
=> ['md', 'markdown']
Returns an array of strings representing potential input formats for the transform. If not provided directly by the transform, results in an array containing the name of the transform.
`js`
var md = require('jstransformer')(require('jstransformer-markdown'))
var outputFormat = md.outputFormat
=> 'html'
Returns a string representing the default output format the transform would be expected to return when calling .render()`.
MIT