🚀 DAY 3 OF LAUNCH WEEK:Announcing Bun and vlt Support in Socket.Learn more →
Socket
Book a DemoInstallSign in
Socket

consolidate-jstransformer

Package Overview
Dependencies
Maintainers
6
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolidate-jstransformer

Consolidate-compatible API to use JSTransformers.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
6
Created
Source

consolidate-jstransformer

Consolidate-compatible API to use JSTransformers.

Build Status Coverage Status Dependency Status Greenkeeper badge NPM version

API

Replace the consolidate package with consolidate-jstransformer.

Before

var cons = require('consolidate')

After

var cons = require('consolidate-jstransformer')

Usage

Use consolidate-jstransformer the same way you would use Consolidate:

var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Or without options / local variables:

var cons = require('consolidate-jstransformer');
cons.swig('views/page.html', function(err, html){
  if (err) throw err;
  console.log(html);
});

To dynamically pass the engine, simply use the subscript operator and a variable:

var cons = require('consolidate-jstransformer')
  , name = 'swig';

cons[name]('views/page.html', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Render strings rather than files:

var cons = require('consolidate-jstransformer')
  , name = 'swig';

cons[name].render('Hello {{ user }}', { user: 'tobi' }, function(err, html){
  if (err) throw err;
  console.log(html);
});

Promises

If no callback function is provided, a Promise will be returned.

var cons = require('consolidate-jstransformer');

cons.swig('views/page.html', { user: 'tobi' })
  .then(function (html) {
    console.log(html);
  })
  .catch(function (err) {
    throw err;
  });

License

MIT

Keywords

jstransformer

FAQs

Package last updated on 15 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts