Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

jed/autorequire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

autorequire.js

Copyright (c) 2011 Jed Schmidt

a small module for auto-importing modules in node.js.

usage

require( "./autorequire" )
require.auto( <module-name> )

background

autorequire.js is for the terminally lazy. it turns boilerplate code like this:

http = require( 'http' );
https = require( 'https' );
url = require( 'url' );
path = require( 'path' );
util = require( 'util' );
crypto = require( 'crypto' );

into this:

http, https, url, path, util, crypto;

if you want, you can even abuse otherwise useless javascript labels:

require: http, https, url, path, util, crypto;

it does this by wrapping your module in a closure, like this:

!function( http, https, url, path, util, crypto ) {
  
  // your original code here
  
}.apply( this, [ 'http', 'https', 'url', 'path', 'util', 'crypto' ].map( require ) )

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.

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.

About

small module for autorequiring. warning: MAGIC!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published