npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

transpile

v2.8.0

Published

Transpiles JavaScript modules from one format to another.

Downloads

7,028

Readme

Transpiles JavaScript modules from one format to another.

It supports from:

  • es6,
  • cjs,
  • amd,
  • steal

to

  • amd,
  • steal,
  • cjs.

Currently, it can not transpile to ES6 module syntax.

Install

> npm install transpile --save-dev

Use

transpile.to transpiles from one format to another format. transpile.able lets you know if a transpile is possible.

Formats

Formats are specified by strings like:

  • "es6" - ES6 Module syntax like import Point from "math";
  • "cjs" - CommonJS syntax like var _ = require('underscore');
  • "amd" - Asynchronous Module Definition syntax like define(['jquery'],function($){});
  • "steal" - steal syntax like steal('jquery', function($){})

transpile.to(load, format, options) -> transpiledResult

Transpiles from the load's format to the specified format. If the load does not specify a format, "es6" modules are assumed. Returns an object containing the transpiled source and sourceMap (if sourceMap option provided).

Example:

var transpile = require('transpile');
var res = transpile.to({
  name: "my/module",
  source: "var foo = require('foo')",
  metadata: {format: "cjs"}
}, "amd")

res.code //-> "define("my/module", function(require, exports, module) { ... "

A load is an object in the shape of an ES6 Load Record like:

{
  name: "moduleName",
  source: "source code",
  metadata: {format: "formatName"}
}

NOTE

Previously transpile.to returned a string containing the transpiled source. To accomodate Source Maps support the API has changed and now returns an object that looks like:

{
  code: "define(...", // The transpiled source,
  map: {}, // A source map, if sourceMaps option is provided.
  ast: {} // A Mozilla Parser API compatible AST, created by Esprima
}

options

  • normalizeMap Object<moduleName,moduleName> - A mapping module names that will be used to replace dependency names in the transpiled result.
  • normalize function(name, currentName, address) -> String - A function that can be used to change moduleNames that are written in the transpiled result.
  • namedDefines Boolean=false - Set to true to insert named defines.
  • transpiler String=traceur - Set which ES6 transpiler to use. Valid options are traceur or 6to5 with traceur being the default.
  • transpile function(source, compileOptions, options) -> Object - If you want to handle tranpiling yourself and not use the built-in options, this is a function that will be given the source and is expected to return an object containing a code string.
  • sourceMaps Boolean=false - Set to true to return a map and ast object along with the result.
  • sourceMapsContent Boolean=false - If sourceMaps is set to true, this option will include the original source contents with the source maps.

transpile.able(fromFormat, toFormat) -> transpiledPath

Returns the path used to transpile from fromFormat to toFormat. If transpiling is not possible, null will be returned.

Example:

var res = transpile.able("steal","cjs");
res //-> ["steal","amd"];

This means that a module will be converted from "steal" to "amd" and then to "cjs".

Test

> npm test