Comparing version 2.0.0 to 2.0.1
@@ -29,3 +29,5 @@ // Copyright (c) 2013 Daniel Ennis <aikar@aikar.co> | ||
indexMap.push(obj); | ||
obj.__proto__ = forwarder(obj.__proto__, loadModule); | ||
obj.__proto__ = proxy(obj.__proto__, loadModule); | ||
dirMap[index] = []; | ||
@@ -35,3 +37,3 @@ } | ||
function loadModule(obj, key) { | ||
function loadModule(key) { | ||
var file = key.replace(/_/,"/"); | ||
@@ -57,3 +59,3 @@ var dirs = dirMap[index]; | ||
function forwarder(target, cb){ | ||
function proxy(target, cb){ | ||
var traps = { | ||
@@ -73,21 +75,19 @@ getOwnPropertyDescriptor: Object.getOwnPropertyDescriptor.bind(null, target), | ||
return Proxy.create(Proxy.create({ | ||
get: function(r, trap){ | ||
return function(a, b){ | ||
if (trap === 'get' && b != 'v8debug' && !target[b]) { | ||
var result = cb(a, b); | ||
if (typeof result == 'undefined') { | ||
throw new ReferenceError(b + ' is not defined'); | ||
} else { | ||
return result; | ||
} | ||
return Proxy.create({ | ||
get: function(r, key){ | ||
if (key != 'v8debug' && target[key] == undefined) { | ||
var result = cb(key); | ||
if (typeof result == 'undefined') { | ||
throw new ReferenceError(key + ' is not defined'); | ||
} else { | ||
return result; | ||
} | ||
} | ||
if (trap in traps) { | ||
return traps[trap].apply(target, arguments); | ||
} | ||
if (key in traps) { | ||
return traps[key].apply(target, arguments); | ||
} | ||
} | ||
}), Object.getPrototypeOf(target)); | ||
}, Object.getPrototypeOf(target)); | ||
} | ||
@@ -5,3 +5,3 @@ { | ||
"description": "Autoloads JS Files", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"homepage": "http://aikar.co", | ||
@@ -8,0 +8,0 @@ "main": "autoloader.js", |
## About | ||
Autoloads JS files based on name when the class is needed. | ||
This is designed to be used with Joose classes in the "Foo.Bar.Baz" format | ||
@@ -8,3 +7,3 @@ This module removes the needs of using require() all over your files. Simply | ||
ie lib/Foo/Bar/Baz.js when you load 'lib/' makes Foo.Bar.Baz | ||
ie lib/Foo/Bar/Baz.js when you load 'lib/' makes Foo_Bar_Baz | ||
require('./lib/Foo/Bar/Baz.js') automatically and return the value. | ||
@@ -64,2 +63,8 @@ | ||
You may optionally pass an object as the 2nd parameter and the autoloader will bind to that object instead of global. | ||
So consider: | ||
global.App = require('autoloader')(__dirname + '/lib', require('./myapp')); | ||
new App.Foo_Bar(); | ||
## Custom Loaders | ||
@@ -66,0 +71,0 @@ If you pass a function as the 1st argument, autoloader will execute that instead of |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7768
100
0
91