JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 228404
  • Score
    100M100P100Q69439F
  • License MIT

String/Data transformations for use in templating libraries, static site generators and web frameworks

Package Exports

  • transformers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (transformers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

transformers

String/Data transformations for use in templating libraries, static site generators and web frameworks. This gathers the most useful transformations you can apply to text or data into one library with a consistent API. Transformations can be pretty much anything but most are either compilers or templating engines.

API

To apply a transformation called foo-bar to a string str and a file at path pth with options opts:

N.B. note that you will need to also have the foo-bar library installed

var transfomers = require('tramsformers');

var transformer = transformers['foo-bar'];

var rendered = transformer.renderSync(str, opts);

transformer.render(str, opts, function (err, rendered) {
  //Some transformations can only be used asyncronously
});

var rendered = transformer.renderFileSync(pth, opts);

transformer.renderFile(pth, opts, function (err, res) {
  //Some transformations can only be used asyncronously
});

You can also make use of:

transformers['foo-bar'].outputFormat;// => `xml`, `css` or `js`
transformers['foo-bar'].sync;// => `true` if it can be used syncronously
transformers['foo-bar'].sudoSync;// => `true` if not always syncronous (see `Libraries that don't work synchronously`)
transformers['foo-bar'].engines;// => an array of possible npm packages to use as the implementation

Libraries that don't work synchronously

The following transformations will always throw an exception if you attempt to run them synchronously:

  1. dust
  2. qejs

The following transformations sometimes throw an exception if run syncronously, typically they only throw an exception if you are doing something like including another file. If you are not doing the things that cause them to fail then they are consistently safe to use syncronously.

  • jade (only when using then-jade instead of jade)
  • less (when @import is used)
  • stylus (when @import is used)
  • jazz (I don't have an example of where this fails, but I also don't know whether it does or not)

The following libraries look like they might sometimes throw exceptions when used syncronously (if you read the source) but they never actually do so:

  • just
  • ect

Supported transforms

Template engines

Other

  • markdown - You can use marked, supermarked, markdown-js or `markdown
  • coffee - npm install coffee-script
  • cdata - No need to install anything, just wrapps text in <![CDATA[\nYOUR TEXT\n]]>
  • uglify - npm install uglify-js minifies javascript

Pull requests to add more transforms will always be accepted providing they are open-source, come with unit tests, and don't cause any of the tests to fail.