lfr-amd-loader
Version:
AMD Loader with support for combo URL and conditional loading
110 lines (80 loc) • 3.14 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: path-resolver.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: path-resolver.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>'use strict';
/**
* Creates an instance of PathResolver class.
*
* @constructor
*/
function PathResolver() {}
PathResolver.prototype = {
constructor: PathResolver,
/**
* Resolves the path of module.
*
* @param {string} module Module path which will be used as reference to resolve the path of the dependency.
* @param {string} dependency The dependency path, which have to be resolved.
* @return {string} The resolved dependency path.
*/
resolvePath: function(module, dependency) {
if (dependency === 'exports') {
return dependency;
}
// Split module directories
var moduleParts = module.split('/');
// Remove module name
moduleParts.splice(-1);
// Split dependency directories
var dependencyParts = dependency.split('/');
// Extract dependecy name
var dependencyName = dependencyParts.splice(-1);
for (var i = 0; i < dependencyParts.length; i++) {
var dependencyPart = dependencyParts[i];
if (dependencyPart === '.') {
continue;
} else if (dependencyPart === '..') {
if (moduleParts.length) {
moduleParts.splice(-1, 1);
}
else {
moduleParts = moduleParts.concat(dependencyParts.slice(i));
break;
}
} else {
moduleParts.push(dependencyPart);
}
}
moduleParts.push(dependencyName);
return moduleParts.join('/');
}
};</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="ConfigParser.html">ConfigParser</a></li><li><a href="DependencyBuilder.html">DependencyBuilder</a></li><li><a href="EventEmitter.html">EventEmitter</a></li><li><a href="Loader.html">Loader</a></li><li><a href="PathResolver.html">PathResolver</a></li><li><a href="URLBuilder.html">URLBuilder</a></li></ul><h3>Events</h3><ul><li><a href="Loader.html#event:moduleRegister">moduleRegister</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Thu Dec 18 2014 12:11:03 GMT-0800 (PST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>