jstransformer

WebJar for jstransformer

License

License

MIT
Categories

Categories

ORM Data
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

jstransformer
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

jstransformer
WebJar for jstransformer
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/jstransformers/jstransformer

Download jstransformer

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/jstransformer/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>jstransformer</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/jstransformer/
implementation 'org.webjars.npm:jstransformer:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/jstransformer/
implementation ("org.webjars.npm:jstransformer:1.0.0")
'org.webjars.npm:jstransformer:jar:1.0.0'
<dependency org="org.webjars.npm" name="jstransformer" rev="1.0.0">
  <artifact name="jstransformer" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='jstransformer', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "jstransformer" % "1.0.0"
[org.webjars.npm/jstransformer "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : is-promise jar [2.0.0,3)
org.webjars.npm : promise jar [7.0.1,8)

Project Modules

There are no modules declared in this project.

JSTransformer

Normalize the API of any jstransformer

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

There are many good template engines and compilers written for Node.js. But there is a problem: all of them have slightly different APIs, requiring slightly different usage. JSTransformer unifies them into one standardized API. Code written for one transformer will work with any other transformer. There are over 100 transformers, ranging from Markdown parsers to template engines to code compilers.

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.

.render*

Returned object from .render*

{body: String, dependencies: Array.<String>}
  • body represents the result as a string
  • dependencies is an array of file names 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, .render, .compile, or .compileAsync

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

Transform a file asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.

.compile*

Returned object from .compile*

{fn: Function, dependencies: Array.<String>}
  • fn is a function that takes a locals object and returns the rendered template as a string.
  • dependencies is an array of file names that were read in as part of the compilation process (or an empty array if there were no dependencies)

.compile

transformer.compile(str[, options]);
=> {fn: Function, dependencies: Array.<String>}

requires the underlying transform to implement .compile or .render

Compile a string and return an object.

.compileAsync

transformer.compileAsync(str[, options], callback);
transformer.compileAsync(str[, options]);
=> Promise({fn: Function, dependencies: Array.<String>})

requires the underlying transform to implement .compileAsync, .compile or .render

Compile a string asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.

.compileFile

transformer.compileFile(filename[, options])
=> {fn: Function, dependencies: Array.<String>}

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

Compile a file and return an object.

.compileFileAsync

transformer.compileFileAsync(filename[, options], callback);
transformer.compileFileAsync(filename[, options]);
=> Promise({fn: Function, dependencies: Array.<String>})

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

Compile a file asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.

.compileClient*

Returned object from .compileClient*

{body: String, dependencies: Array.<String>}
  • body is a .toStringed function that can be used on the client side.
  • dependencies is an array of file names that were read in as part of the compilation process (or an empty array if there were no dependencies)

.compileClient

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

requires the underlying transform to implement .compileClient

Compile a string for client-side use and return an object.

.compileClientAsync

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

requires the underlying transform to implement .compileClientAsync or .compileClient

Compile a string for client-side use asynchronously. If a callback is provided, it is called as callback(err, data), otherwise a Promise is returned.

.compileFileClient

transformer.compileFileClient(filename[, options])
=> {body: String, dependencies: Array.<String>}

requires the underlying transform to implement .compileFileClient or .compileClient

Compile a file for client-side use and return an object.

.compileFileClientAsync

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

requires the underlying transform to implement .compileFileClientAsync, .compileFileClient, .compileClientAsync, or .compileClient

Compile a file for client-side use 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().

.can

var md = require('jstransformer')(require('jstransformer-markdown'))
md.can('render');
=> true

Takes a method name as a string and returns a boolean value indicating whether the normalised transform implements this method.

License

MIT

org.webjars.npm

JSTransformers

Versions

Version
1.0.0
0.0.2