3 * Require the given path.
6 * @return {Object} exports
10 function require(path, parent, orig) {
11 var resolved = require.resolve(path);
14 if (null == resolved) {
16 parent = parent || 'root';
17 var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
24 var module = require.modules[resolved];
26 // perform real require()
27 // by invoking the module's
28 // registered function
29 if (!module.exports) {
31 module.client = module.component = true;
32 module.call(this, module.exports, require.relative(resolved), module);
35 return module.exports;
59 * @param {String} path
60 * @return {String} path or null
64 require.resolve = function(path) {
65 if (path.charAt(0) === '/') path = path.slice(1);
66 var index = path + '/index.js';
76 for (var i = 0; i < paths.length; i++) {
78 if (require.modules.hasOwnProperty(path)) return path;
81 if (require.aliases.hasOwnProperty(index)) {
82 return require.aliases[index];
87 * Normalize `path` relative to the current path.
89 * @param {String} curr
90 * @param {String} path
95 require.normalize = function(curr, path) {
98 if ('.' != path.charAt(0)) return path;
100 curr = curr.split('/');
101 path = path.split('/');
103 for (var i = 0; i < path.length; ++i) {
104 if ('..' == path[i]) {
106 } else if ('.' != path[i] && '' != path[i]) {
111 return curr.concat(segs).join('/');
115 * Register module at `path` with callback `definition`.
117 * @param {String} path
118 * @param {Function} definition
122 require.register = function(path, definition) {
123 require.modules[path] = definition;
127 * Alias a module definition.
129 * @param {String} from
134 require.alias = function(from, to) {
135 if (!require.modules.hasOwnProperty(from)) {
136 throw new Error('Failed to alias "' + from + '", it does not exist');
138 require.aliases[to] = from;
142 * Return a require function relative to the `parent` path.
144 * @param {String} parent
149 require.relative = function(parent) {
150 var p = require.normalize(parent, '..');
153 * lastIndexOf helper.
156 function lastIndexOf(arr, obj) {
159 if (arr[i] === obj) return i;
165 * The relative require() itself.
168 function localRequire(path) {
169 var resolved = localRequire.resolve(path);
170 return require(resolved, parent, path);
174 * Resolve relative to the parent.
177 localRequire.resolve = function(path) {
178 var c = path.charAt(0);
179 if ('/' == c) return path.slice(1);
180 if ('.' == c) return require.normalize(p, path);
182 // resolve deps by returning
183 // the dep in the nearest "deps"
185 var segs = parent.split('/');
186 var i = lastIndexOf(segs, 'deps') + 1;
188 path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
193 * Check if module is defined at `path`.
196 localRequire.exists = function(path) {
197 return require.modules.hasOwnProperty(localRequire.resolve(path));
202 require.register("isarray/index.js", function(exports, require, module){
203 module.exports = Array.isArray || function (arr) {
204 return Object.prototype.toString.call(arr) == '[object Array]';
208 require.alias("isarray/index.js", "isarray/index.js");