1. jstransformer
Normalize the API of any jstransformer
jstransformer
Package: jstransformer
Created by: jstransformers
Last modified: Sun, 19 Jun 2022 07:00:11 GMT
Version: 1.0.0
License: MIT
Downloads: 6,722,692
Repository: https://github.com/jstransformers/jstransformer

Install

npm install jstransformer
yarn add jstransformer

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code