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 1.3.1 to 2.0.0

39

index.js

@@ -7,6 +7,3 @@ var through = require('through');

var str = uglify.minify(
templateSTR
.replace(/\{\{name\}\}/g, moduleName.toLowerCase())
.replace(/\{\{pascalcase\}\}/g, pascalCase(moduleName))
.replace(/\{\{camelcase\}\}/g, camelCase(moduleName)),
templateSTR.replace(/\{\{defineNamespace\}\}/g, compileNamespace(moduleName)),
{fromString: true}).code

@@ -57,9 +54,33 @@ .split('source()')

function pascalCase(name) {
return camelCase(name).replace(/^[a-z]/, function (char) { return char.toUpperCase(); });
}
function camelCase(name) {
name = name.replace(/\-([a-z])/g, function (_, char) { return char.toUpperCase(); });
return name.replace(/[^a-zA-Z0-9]+/g, '');
return name.replace(/[^a-zA-Z0-9]+/g, '')
}
function compileNamespace(name) {
var names = name.split('.')
// No namespaces, yield the best case 'global.NAME = VALUE'
if (names.length === 1) {
return 'g.' + camelCase(name) + ' = f()';
// Acceptable case, with reasonable compilation
} else if (names.length === 2) {
names = names.map(camelCase);
return '(g.' + names[0] + ' || (g.' + names[0] + ' = {})).' + names[1] + ' = f()';
// Worst case, too many namespaces to care about
} else {
var valueContainer = names.pop()
return names.reduce(compileNamespaceStep, ['var ref$ = g'])
.concat(['ref$.' + camelCase(valueContainer) + ' = f()'])
.join(';\n ');
}
}
function compileNamespaceStep(code, name, i, names) {
name = camelCase(name);
code.push('ref$ = (ref$.' + name + ' || (ref$.' + name + ' = {}))')
return code
}
{
"name": "umd",
"version": "1.3.1",
"version": "2.0.0",
"description": "Universal Module Definition for use in automated build systems",

@@ -5,0 +5,0 @@ "bin": "./bin/cli.js",

@@ -0,0 +0,0 @@ # umd

@@ -12,9 +12,11 @@ ;(function (f) {

} else {
var g
if (typeof window !== "undefined") {
window.{{camelcase}} = f();
g = window;
} else if (typeof global !== "undefined") {
global.{{camelcase}} = f();
g = global;
} else if (typeof self !== "undefined") {
self.{{camelcase}} = f();
g = self;
}
{{defineNamespace}};
}

@@ -21,0 +23,0 @@

var assert = require('assert')
var umd = require('../')
var src = umd('sentinel-prime', 'return "sentinel"')
var namespacedSrc = umd('sentinel.prime', 'return "sentinel"')
var multiNamespaces = umd('a.b.c.d.e', 'return "sentinel"')

@@ -39,2 +41,13 @@ describe('with CommonJS', function () {

})
})
it('creates the proper namespaces', function() {
var glob = {}
Function('window', namespacedSrc)(glob)
assert(glob.sentinel.prime === 'sentinel')
})
it('creates proper multiple namespaces', function() {
var glob = {}
Function('window', multiNamespaces)(glob)
assert(glob.a.b.c.d.e === 'sentinel')
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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