function psr4 () { } psr4.namespaces = []; psr4.add = function (namespace, path) { this.namespaces.push({namespace: namespace, path: path}); } psr4.use = function (module) { var possibles = []; this.namespaces.forEach(function (ns) { if (module.substr(0, ns.namespace.length) == ns.namespace) { possibles.push(ns); } }); if (possibles.length > 0) { possibles.sort(function (a, b) { return b.namespace.length - a.namespace.length; }); var ns = possibles[0]; var newpath = ns.path + module.substr(ns.namespace.length).replace('\\', '/'); return require(newpath); } } module.exports = ps4;