Socket
Book a DemoInstallSign in
Socket

dustc-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dustc-commonjs

Dust compiler that produces a CommonJS module as output

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

dustc-commonjs

Transforms a compiled Dust template into a CommonJS module.

Installation

npm install dustc-commonjs --save

Why?

Standard Dust modules compile down to JavaScript code that registers a compiled template function using a given template name and the compiled output assumes that there is a global dust variable (globals are evil). By producing a CommonJS module as output the template can be loaded using the standard Node.js module loading system based on require.

Usage

Given the following sample template:

Hello {name}!

And the following sample program:

var templatePath = require('path').join(__dirname, 'hello.dust');
require('dustc-commonjs').compileFile(templatePath, function(err, src) {
    if (err) {
        // Handle the error
        return;
    }

    // src will be the compiled JavaScript code for the Dust template as a CommonJS module
})

The output compiled template will be similar to the following:

(function(){module.exports=body_0;function body_0(chk,ctx){return chk.write("Hello ").reference(ctx.get(["name"], false),ctx,"h").write("!");}return body_0;})();

Notice the usage of module.exports.

In comparison, the standard compiled output (that is _not) a CommonJS module) will be similar to the following:

(function(){module.exports=body_0;function body_0(chk,ctx){return chk.write("Hello ").reference(ctx.get(["name"], false),ctx,"h").write("!");}return body_0;})();

Keywords

dust

FAQs

Package last updated on 11 Mar 2015

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