Permalink
Browse files

added client function oui.util.canonicalizeModuleName used to canonic…

…alize module names and paths
  • Loading branch information...
rsms committed Apr 20, 2010
1 parent 6f56659 commit c324c90a84e40fd42ad86c72a25ef67ff41c18f6
Showing with 15 additions and 0 deletions.
  1. +15 −0 client/lib/oui/util.js
View
@@ -0,0 +1,15 @@
+
+/**
+ * Takes a module name or path and returns its canonical representation.
+ */
+exports.canonicalizeModuleName = function(path) {
+ return path
+ .replace(/(?:\.min|)\.[^\.]+$/g, '') // foo/bar-baz-.min.js => foo/bar-baz-
+ .replace(/\/+/g,'.') // foo/bar-baz- => foo.bar-baz-
+ .replace(/-+/g,'_') // foo.bar-baz- => foo.bar_baz_
+ .replace(/\.index$/, '') // * removes ".index"
+ .replace(/^[_\.\-]|[_\.\-]$/g,'') // foo.bar_baz_ => foo.bar_baz
+ .replace(/_+(\w)/g, function(str, m1){ // foo.bar_baz => foo.barBaz
+ return m1.toUpperCase();
+ });
+};

0 comments on commit c324c90

Please sign in to comment.