Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (24 sloc) 1.287 kB
60a5d73 @jed
authored
1 # autorequire.js
2 Copyright (c) 2011 Jed Schmidt
3
4 a small module for auto-importing modules in node.js.
5
6 ## usage
7
8 require( "./autorequire" )
9 require.auto( <module-name> )
10
11 ## background
12
13 autorequire.js is for the terminally lazy. it turns boilerplate code like this:
14
15 http = require( 'http' );
16 https = require( 'https' );
17 url = require( 'url' );
18 path = require( 'path' );
19 util = require( 'util' );
20 crypto = require( 'crypto' );
21
22 into this:
23
24 http, https, url, path, util, crypto;
a1d952a @jed abusing javascript labels 'cause i can
authored
25
26 if you want, you can even abuse otherwise useless javascript labels:
27
28 require: http, https, url, path, util, crypto;
60a5d73 @jed
authored
29
30 it does this by wrapping your module in a closure, like this:
31
32 !function( http, https, url, path, util, crypto ) {
33
34 // your original code here
35
36 }.apply( this, [ 'http', 'https', 'url', 'path', 'util', 'crypto' ].map( require ) )
37
38
39 basically, it attempts to load your module repeatedly, adding a new argument to the list every time a `not_defined` error is thrown. once all your symbols are there, it compiles and executes the module.
40
41 this module was born from a (fab) brainstorm, and is a prototype not really meant for serious use. that said, if you think it could be useful and would like me to `npm` it, lemme know.
Something went wrong with that request. Please try again.