npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

register-js

v1.2.2

Published

A compatible layer for node projects to support require feature on both browser and node. Also, provide complex file loading features for browser. And it also support to load JSON files.

Downloads

18

Readme

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.