Detalhes do pacote

jstransformer

jstransformers7.6mMIT1.0.0

Normalize the API of any jstransformer

jstransformer

readme (leia-me)

JSTransformer

Normalize the API of any jstransformer

Build Status Dependency Status Developers' Dependency Status Coverage Status NPM version

Installation

npm install jstransformer

Usage

var transformer = require('jstransformer');
var marked = transformer(require('jstransformer-marked'));

var options = {};
var res = marked.render('Some **markdown**', options);
// => {body: 'Some <strong>markdown</strong>', dependencies: []}

This gives the same API regardless of the jstransformer passed in.

API

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.

Returned object from .render*

{body: String, dependencies: Array.<String>}
  • body represents the result as a string
  • dependencies is an array of files that were read in as part of the render process (or an empty array if there were no dependencies)

.render

transformer.render(str, options, locals);
=> {body: String, dependencies: Array.<String>}

requires the underlying transform to implement .render or .compile

Transform a string and return an object.

.renderAsync

transformer.renderAsync(str[, options], locals, callback);
transformer.renderAsync(str[, options], locals);
=> Promise({body: String, dependencies: Array.<String>})

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.

.renderFile

transformer.renderFile(filename, options, locals)
=> {body: String, dependencies: Array.<String>}

requires the underlying transform to implement .renderFile, .render, .compileFile, or .compile

Transform a file and return an object.

.renderFileAsync

transformer.renderFileAsync(filename[, options], locals, callback);
transformer.renderFileAsync(filename[, options], locals);
=> Promise({body: String, dependencies: Array.<String>})

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.

.inputFormats

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.

.outputFormat

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

License

MIT

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

1.0.0 - 2016-06-06

Changed

  • Browser support is fixed
  • Marked as stable

0.0.4 - 2015-11-23

Changed

  • Switched to Keep a Changelog spec for CHANGELOG.md
  • Creates an options.filename for *File() functions, if one is not provided

0.0.3 - 2015-07-13

Added

  • Added .render() fallbacks for .compile()

Changed

  • Prefers locals over options when passing a single argument to .render()
  • Updated dependencies

0.0.2 - 2015-04-11

Added

  • Now have a logo
  • Added tests

Changed

  • Updated documentation

0.0.1 - 2015-02-09

Added

  • Initial release