1.2.2 • Published 10 years ago

register-js v1.2.2

Weekly downloads
7
License
MIT
Repository
-
Last release
10 years ago

Register.js

Register js is a compatible level for Node.js programs to run under browser environment. To do this, you should add a single line at the end of your javascript file:

 var register_js = require("regsiter-js") //Call only once for your entire project.
 
 //Then you can use it anywhere.
 register(exportObject, "TestNamespace.TestObject", module);

Or if you're not 100% sure register.js has loaded correctly, the following statement will do 100% correctly under both browser and Node.js:

 var module = require("register-js")(exportObject, "TestNamespace.TestObject", module);

On node.js it will equal to

 module.exports = exportObject;

On browser script, it will equal to

 window.TestNamespace.TestObject = exportObject;

Also, register.js will provide you a require function for browser, which is almost as the same as node.

 var X = require("TestObject", "TestNamespace.TestObject");

And this tool will try to find a resource named as TestNamespace/TestObject.js.

The second parameter will be regarded as the better browser option. However, you can write no 2nd parameter as well:

 var X = require("TestObject");

And this calling will find a javascript file named as TestObject.js.

You can set a configuration object as registerConfig:

 registerConfig.root = "http://example.com/js/"

Then the searching file will be

 http://example.com/js/TestNamespace/TestObject.js

and

 http://example.com/js/TestObject.js

Auto-fetch can be useful only when you're running simple websites with limited visitors or testing. Do not use it for large websites, because performance will be a serious problem. Use grunt to compile your javascript code into a single file to avoid multiply loading.

Browser support:

 IE      6.0 +
 Firefox 1.0 +
 Chrome  1.0 +
 Safari  5.0 +
 Opera   9.0 +

WARNING: Since there has been already a npm package named register, so we used "register-js" instead. For browser, global scope register is also available.

RequireJSON

Since 1.1.0, you can use requireJSON for both node and browser.

requireJSON("test.jsonPackage");

This method will look for test/jsonPackage.json. Also, you can use

requireJSON.fileType = "js";

To make it work with js files.

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.9

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago