[Pkg-javascript-commits] [node-umd] 01/07: Uses the module name as namespace spec (Fixes #8)

Bastien Roucariès rouca at moszumanska.debian.org
Mon Apr 17 07:38:09 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to annotated tag 2.0.0
in repository node-umd.

commit 83569fbf203b1a2a3124be23046bd9ab4eed357f
Author: Quildreen "Sorella" Motta <quildreen at gmail.com>
Date:   Wed Nov 27 13:13:07 2013 -0200

    Uses the module name as namespace spec (Fixes #8)
    
    There were three operations that were unused in this module: replacing {{name}} and {{pascalCase}}, so I've removed them.
---
 index.js    | 12 ++----------
 template.js | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/index.js b/index.js
index 3badff0..9ae97a4 100644
--- a/index.js
+++ b/index.js
@@ -4,10 +4,7 @@ var templateSTR = rfile('./template.js');
 var uglify = require('uglify-js');
 function template(moduleName, cjs) {
   var str = uglify.minify(
-    templateSTR
-      .replace(/\{\{name\}\}/g, moduleName.toLowerCase())
-      .replace(/\{\{pascalcase\}\}/g, pascalCase(moduleName))
-      .replace(/\{\{camelcase\}\}/g, camelCase(moduleName)),
+    templateSTR.replace(/\{\{name\}\}/g, camelCase(moduleName)),
     {fromString: true}).code
     .split('source()')
   str[0] = str[0].trim();
@@ -53,11 +50,6 @@ exports.postlude = function (moduleName, cjs) {
 };
 
 
-
-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-z])/g, function (_, char) { return char.toUpperCase(); });
 }
diff --git a/template.js b/template.js
index f040973..b554ee4 100644
--- a/template.js
+++ b/template.js
@@ -10,11 +10,20 @@
   // <script>
   } else {
     if (typeof window !== "undefined") {
-      window.{{camelcase}} = f();
+      setup(window, {{name}}, f())
     } else if (typeof global !== "undefined") {
-      global.{{camelcase}} = f();
+      setup(global, {{name}}, f())
     } else if (typeof self !== "undefined") {
-      self.{{camelcase}} = f();
+      setup(self, {{name}}, f())
+    }
+  }
+
+  function setup(object, name, value) {
+    var key
+    var names = name.split('.')
+    while (key = names.shift()) {
+      object[key] = object[key] || (names.length? {} : value)
+      object = object[key]
     }
   }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-umd.git



More information about the Pkg-javascript-commits mailing list