Socket
Socket
Sign inDemoInstall

jstransformer

Package Overview
Dependencies
3
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

jstransformer

Normalize the API of any jstransformer


Version published
Maintainers
5
Weekly downloads
1,705,934
increased by0.57%
Bundle size
4.1 kB
Minified + gzipped

Weekly downloads

Package description

What is jstransformer?

The jstransformer npm package provides a standardized interface for handling different kinds of transformations on strings, such as compiling template languages, processing markdown, or minifying code. It allows developers to use a consistent API across various transformers.

What are jstransformer's main functionalities?

Template Compilation

Compile templates from languages like Jade/Pug to HTML.

const jstransformer = require('jstransformer');
const jade = require('jstransformer-jade');

const input = 'h1 Jade - node template engine';
const result = jstransformer(jade).render(input).body;
console.log(result);

Markdown Processing

Convert markdown syntax to HTML.

const jstransformer = require('jstransformer');
const markdown = require('jstransformer-markdown');

const input = '# Markdown Example\n\nSome *emphasis* and **strong** text.';
const result = jstransformer(markdown).render(input).body;
console.log(result);

Code Minification

Minify JavaScript code using UglifyJS.

const jstransformer = require('jstransformer');
const uglify = require('jstransformer-uglify-js');

const input = 'function add(x, y) {\n  return x + y;\n}';
const result = jstransformer(uglify).render(input).body;
console.log(result);

Other packages similar to jstransformer

Readme

Source

JSTransformer

Normalize the API of any jstransformer

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

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.

Returned object from .render*

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

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

Transform a file 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().

License

MIT

Keywords

FAQs

Last updated on 06 Jun 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc