Code Monkey home page Code Monkey logo

umdify's Introduction

umdify

umdify is a small JavaScript library for converting modules authored in AMD format to UMD format. It's useful for distributing libraries with wide compatibility in mind. Output UMD is compatible with AMD loaders, CommonJS loaders (like node.js), and (optionally) browser globals.

Based on and shares the same "modify as little as possible" philosophy with nodefy.

Installation

Using npm:

npm install umdify

Usage

String umdify( String contents, Object [options] )

contents

Converts it (a valid AMD JavaScript module) to UMD format.

options

options.namespace : String. Only required if you want to support browser globals, and will be the name of the exported window property.

options.template : String. Specifies the path to a file containing a lodash template. Only required if you want to use custom output format.

options.templateSource : String. Specifies the lodash template source. If specified, overrides template. Only required if you want to use custom output format.

Example (node.js):

var fs = require('fs');
var umdify = require('umdify');

var contents = fs.readFileSync('src/myModule.js', 'utf8');
contents = umdify(contents, {
    namespace: 'myModule'
});
fs.writeFileSync('dist/myModule.js', contents);

Want to do a bulk convert? I won't stand in your way. How about node-glob?

var fs = require('fs');
var path = require('path');
var glob = require('glob');
var umdify = require('umdify');

var files = glob.sync('src/**/*.js');
files.forEach(function(file) {
	var contents = fs.readFileSync(file, 'utf8');
	contents = umdify(contents);
	var dest = path.join('dist', file.replace(/^src\//, ''));
	fs.writeFileSync(dest, contents);
});

License

Released under the MIT License.

umdify's People

Contributors

hmhao avatar zship avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.