All Projects → jstransformers → Jstransformer

jstransformers / Jstransformer

Licence: mit
Normalize the API of any JSTransformer.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Jstransformer

Actuate
One line easy actuation of CSS animation sequences
Stars: ✭ 42 (-69.78%)
Mutual labels:  promise, transform
dry
Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.
Stars: ✭ 66 (-52.52%)
Mutual labels:  engine, templates
unified-args
Create CLIs for unified processors
Stars: ✭ 30 (-78.42%)
Mutual labels:  engine, unified
Preview Email
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
Stars: ✭ 112 (-19.42%)
Mutual labels:  engine, templates
Mdx
Markdown for the component era
Stars: ✭ 11,948 (+8495.68%)
Mutual labels:  unified
Search Engine Optimization
🔍 A helpful checklist/collection of Search Engine Optimization (SEO) tips and techniques.
Stars: ✭ 1,798 (+1193.53%)
Mutual labels:  engine
Node Stratum
Stratum protocol server and client for Node.js
Stars: ✭ 129 (-7.19%)
Mutual labels:  promise
Loaderz
⚡️ A very easy-to-use, blazing fast asset-loader using promises. Support older-browsers and preload images, audios and videos.
Stars: ✭ 130 (-6.47%)
Mutual labels:  promise
Rg3d
3D and 2D game engine written in Rust
Stars: ✭ 2,998 (+2056.83%)
Mutual labels:  engine
Shards Ui
🎨Shards is a beautiful & modern Bootstrap 4 UI kit packed with extra templates and components.
Stars: ✭ 1,718 (+1135.97%)
Mutual labels:  templates
Szl
A lightweight, embeddable scripting language
Stars: ✭ 134 (-3.6%)
Mutual labels:  engine
Rubico
[a]synchronous functional programming
Stars: ✭ 133 (-4.32%)
Mutual labels:  promise
Dashboards
Responsive dashboard templates 📊✨
Stars: ✭ 10,914 (+7751.8%)
Mutual labels:  templates
Pgbouncerhero
A dashboard for your PgBouncers.
Stars: ✭ 129 (-7.19%)
Mutual labels:  engine
Toolkit
Collection of useful patterns
Stars: ✭ 137 (-1.44%)
Mutual labels:  promise
Ferma
An ORM / OGM for the TinkerPop graph stack.
Stars: ✭ 130 (-6.47%)
Mutual labels:  engine
Expr
Expression language for Go
Stars: ✭ 2,123 (+1427.34%)
Mutual labels:  engine
Algorithmic template
🍭lzyrapx 's algorithmic library. Some templates for ACMer, OIer, Algorithm enthusiast.
Stars: ✭ 136 (-2.16%)
Mutual labels:  templates
Fe Interview
😃 每日一道经典前端面试题,一起共同成长。
Stars: ✭ 134 (-3.6%)
Mutual labels:  promise
2moons
Open Source Browsergame Framework
Stars: ✭ 133 (-4.32%)
Mutual labels:  engine

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].