Extractor is a tiny JavaScript library for managing variables in the global namespace. Instead of attaching themselves to the global object, libraries may register with Extractor. Developers can then retrieve registered libraries from Extractor and assign them to a variable of their choice. It achieves an effect similar to jQuery's noConflict
function with a syntax more akin to Node's require
. In fact, Extractor's extract
method is aliased to require
for convenience.
For library authors:
// Assuming Extractor.js has been included
(function () {
var MyLibrary = {
foo: "bar"
};
Extractor.register("MyLibrary", MyLibrary);
})();
For developers:
var FooBar = Extractor.extract("MyLibrary");
Or, alternatively:
var FooBar = Extractor.require("MyLibrary");
var barify = Extractor.extract("MyLibrary").fooify;
This allows developers to extract any module (or any property of a module) into a variable with a name of their choosing.
If, for some reason, you need to programmatically reset Extractor's registry, use Extract.reset()
.
To download Extractor, use the Downloads button near the top of the page.
To work on Extractor or to run the included Jasmine specs, you must have Node and NPM installed. Clone the repository and run npm install
inside the directory to install the Node dependencies. You should also install CoffeeScript globally with npm install coffee-script -g
to get command line access to the Cake tasks. Run cake
for a list of available tasks.
Extractor is available under the MIT license. See the included LICENSE
.