Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

umd

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

umd - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

10

bin/cli.js

@@ -37,4 +37,8 @@ #!/usr/bin/env node

var dest = args[2] ? write(args[2]) : process.stdout
source.pipe(umd(args[0], commonJS)).pipe(dest)
}
var prelude = umd.prelude(args[0], {commonJS: commonJS})
var postlude = umd.postlude(args[0], {commonJS: commonJS})
dest.write(prelude)
source.on('end', function () {
dest.write(postlude + '\n')
}).pipe(dest, {end: false})
}

@@ -0,1 +1,12 @@

3.0.0 / 2015-02-04
==================
- remove dependency on ruglify (thanks to @zertosh)
- add `this` as an additional fallback when looking for a global (thanks to @winterbe)
- use `options` rather than `true` / `false` for whether to use CommonJS (with fallback for backwards compatibility).
- support `$` and `_` in module names (thanks to @fitnr) **(BREAKING CHANGE)**
- uglify as a pre-publish step - removing a dependency
- brfs as a pre-publish step - allowing this module to be used from the browser.
- remove support for streaming **(BREAKING CHANGE)**
2.1.0 / 2014-04-02

@@ -48,2 +59,2 @@ ==================

- Initial Release
- Initial Release
'use strict';
var through = require('through');
var rfile = require('rfile');
var uglify = require('uglify-js');
var templateSTR = rfile('./template.js');
function template(moduleName, cjs) {
var str = uglify.minify(
templateSTR.replace(/\{\{defineNamespace\}\}/g, compileNamespace(moduleName)),
{fromString: true}).code
var templateSTR = "(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}defineNamespace()}})(function(){source()});";
function template(moduleName, options) {
if (typeof options === 'boolean') {
options = {commonJS: options};
} else if (!options) {
options = {};
}
var str = templateSTR.replace(/defineNamespace\(\)/g, compileNamespace(moduleName))
.split('source()')

@@ -16,5 +17,5 @@ str[0] = str[0].trim();

str[0] += 'var define,module,exports;';
if (cjs) str[0] += 'module={exports:(exports={})};';
if (options.commonJS) str[0] += 'module={exports:(exports={})};';
str[0] += '\n';
if (cjs) str[1] = 'return module.exports;' + str[1];
if (options.commonJS) str[1] = 'return module.exports;' + str[1];
str[1] = '\n' + str[1];

@@ -24,31 +25,16 @@ return str;

exports = module.exports = function (name, cjs, src) {
if (typeof cjs === 'string') {
var tmp = cjs;
cjs = src;
exports = module.exports = function (name, src, options) {
if (typeof options === 'string' && typeof src === 'object') {
var tmp = options;
options = src;
src = tmp;
}
if (src) {
return exports.prelude(name, cjs) + src + exports.postlude(name, cjs);
}
var strm = through(write, end);
var first = true;
function write(chunk) {
if (first) strm.queue(exports.prelude(name, cjs));
first = false;
strm.queue(chunk);
}
function end() {
if (first) strm.queue(exports.prelude(name, cjs));
strm.queue(exports.postlude(name, cjs));
strm.queue(null);
}
return strm;
return exports.prelude(name, options) + src + exports.postlude(name, options);
};
exports.prelude = function (moduleName, cjs) {
return template(moduleName, cjs)[0];
exports.prelude = function (moduleName, options) {
return template(moduleName, options)[0];
};
exports.postlude = function (moduleName, cjs) {
return template(moduleName, cjs)[1];
exports.postlude = function (moduleName, options) {
return template(moduleName, options)[1];
};

@@ -59,3 +45,10 @@

name = name.replace(/\-([a-z])/g, function (_, char) { return char.toUpperCase(); });
return name.replace(/[^a-zA-Z0-9]+/g, '')
if (!/^[a-zA-Z_$]$/.test(name[0])) {
name = name.substr(1);
}
var result = name.replace(/[^\w$]+/g, '')
if (!result) {
throw new Error('Invalid JavaScript identifier resulted from camel-casing');
}
return result
}

@@ -79,12 +72,11 @@

var valueContainer = names.pop()
return names.reduce(compileNamespaceStep, ['var ref$ = g'])
.concat(['ref$.' + camelCase(valueContainer) + ' = f()'])
.join(';\n ');
return names.map(compileNamespaceStep)
.concat(['g.' + camelCase(valueContainer) + ' = f()'])
.join(';');
}
}
function compileNamespaceStep(code, name, i, names) {
function compileNamespaceStep(name) {
name = camelCase(name);
code.push('ref$ = (ref$.' + name + ' || (ref$.' + name + ' = {}))')
return code
return 'g=(g.' + name + '||(g.' + name + ' = {}))';
}
{
"name": "umd",
"version": "2.1.0",
"version": "3.0.0",
"description": "Universal Module Definition for use in automated build systems",
"bin": "./bin/cli.js",
"dependencies": {
"rfile": "~1.0.0",
"ruglify": "~1.0.0",
"through": "~2.3.4",
"uglify-js": "~2.4.0"
},
"dependencies": {},
"devDependencies": {
"brfs": "^1.3.0",
"linify": "~1.0.1",
"mocha": "*"
"mocha": "*",
"uglify-js": "~2.4.0"
},
"scripts": {
"test": "mocha -R spec",
"prepublish": "linify transform bin"
"build": "uglifyjs template.js > template.min.js && brfs source.js > index.js",
"test": "npm run build && mocha -R spec",
"prepublish": "npm run build && linify transform bin"
},
"files": [
"index.js",
"bin/cli.js"
],
"repository": {

@@ -21,0 +23,0 @@ "type": "git",

@@ -7,3 +7,2 @@ # umd

- simple synchronous wrapping of a string
- optional wrapping of a "stream" with genuine streaming
- `return` style module support

@@ -13,5 +12,5 @@ - CommonJS support

[![Build Status](https://travis-ci.org/ForbesLindesay/umd.png?branch=master)](https://travis-ci.org/ForbesLindesay/umd)
[![Dependency Status](https://gemnasium.com/ForbesLindesay/umd.png)](https://gemnasium.com/ForbesLindesay/umd)
[![NPM version](https://badge.fury.io/js/umd.png)](http://badge.fury.io/js/umd)
[![Build Status](https://img.shields.io/travis/ForbesLindesay/umd/master.svg)](https://travis-ci.org/ForbesLindesay/umd)
[![Dependency Status](https://img.shields.io/gemnasium/ForbesLindesay/umd.svg)](https://gemnasium.com/ForbesLindesay/umd)
[![NPM version](https://img.shields.io/npm/v/umd.svg)](http://badge.fury.io/js/umd)

@@ -36,17 +35,17 @@ ## Source Format

### umd(name, [commonJS = false], [source])
options:
The `name` should the the name of the module. Use a string like name, all lower case with hyphens instead of spaces.
- `commonJS` (default: `false`) - If commonJS is `true` then it will accept CommonJS source instead of source code which `return`s the module.
If CommonJS is `true` then it will accept CommonJS source instead of source code which `return`s the module.
### umd(name, source, [options])
If `source` is provided and is a string, then it is wrapped in umd and returned as a string. If it is not provided, a duplex stream is returned which wraps the modules (see examples/build.js).
The `name` should the the name of the module. Use a string like name, all lower case with hyphens instead of spaces.
Both commonJS and source are optional and can be provided in either order.
If `source` should be a string, that is wrapped in umd and returned as a string.
### umd.prelude(module, [commonJS = false])
### umd.prelude(module, [options])
return the text which will be inserted before a module.
### umd.postlude(module, [commonJS = false])
### umd.postlude(module, [options])

@@ -68,4 +67,10 @@ return the text which will be inserted after a module.

You can easilly pipe unix commands together like:
```js
cat my-module.js | umd my-module | uglify-js > my-module.umd.min.js
```
## License
MIT
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc