funcunit
Version:
<!-- @hide title
57 lines (50 loc) • 1.66 kB
JavaScript
var filename = function(uri){
var lastSlash = uri.lastIndexOf("/");
//if no / slashes, check for \ slashes since it might be a windows path
if(lastSlash === -1)
lastSlash = uri.lastIndexOf("\\");
var matches = ( lastSlash == -1 ? uri : uri.substr(lastSlash+1) ).match(/^[\w-\s\.!]+/);
return matches ? matches[0] : "";
};
var ext = function(uri){
var fn = filename(uri);
var dot = fn.lastIndexOf(".");
if(dot !== -1) {
return fn.substr(dot+1);
} else {
return "";
}
};
var pluginCache = {};
var normalize = function(name, loader){
// Detech if this name contains a plugin part like: app.less!steal/less
// and catch the plugin name so that when it is normalized we do not perform
// Steal's normalization against it.
var pluginIndex = name.lastIndexOf('!');
var pluginPart = "";
if (pluginIndex != -1) {
// argumentName is the part before the !
var argumentName = name.substr(0, pluginIndex);
var pluginName = name.substr(pluginIndex + 1);
pluginPart = "!" + pluginName;
// Set the name to the argument name so that we can normalize it alone.
name = argumentName;
}
var last = filename(name),
extension = ext(name);
// if the name ends with /
if( name[name.length -1] === "/" ) {
return name+filename( name.substr(0, name.length-1) ) + pluginPart;
} else if( !/^(\w+(?:s)?:\/\/|\.|file|\/)/.test(name) &&
// and doesn't end with a dot
last.indexOf(".") === -1
) {
return name+"/"+last + pluginPart;
} else {
if(extension === "js") {
return name.substr(0, name.lastIndexOf(".")) + pluginPart;
} else {
return name + pluginPart;
}
}
};