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

norb

v1.0.2

Published

node or browser: detect if the script is running on node or in a browser

Downloads

2

Readme

Norb

License Email Donate Donate

Node OR Browser

detect if the script is running on node or in a browser

Getting Started

Installing

This library is easy to install by cloning the repo or installing it through npm too:

Local installation

npm install norb

Global installation

npm install -g norb

Usage

  • Require Node
const norb = require('norb')(module);
//{
//  isNode:boolean (true),
//  isBrowser:boolean (false),
//  export:[Function],
//  import:[Function],
//  require:[Function]
//  }
  • Require Browser
<script src="norb.js"></script>
  • isNode [Boolean]: true if running in node

  • isBrowser [Boolean]: true if running in browser

  • export export(Object, name?, mode?) This method allow to export an object in the correct way, independant if the code is in a Node or a Browser environment. (?) In the Browser context you have to assign a name? that will point to window[name] object; the mode? help to decide in which way the object will be overwritten can be 0: ( conserve ) that preserve the original window[name] if present, 1: ( overwrite ) that overwrite anyway, 2: ( merge ) that merge both object.

  • NB Browser doesn't support system API and Node doesn't support some of the Broswer API

  • import import(path) Enclose and import a Browser module, like it would be a Node module.

  • NB Browser doesn't support system API and Node doesn't support some of the Broswer API

  • require require(path, [name?, mode?,] callback) Require a Node module, like it would be a Browser module. In Browser the method is async so you must define a callback for take the module result; with name parameter you can autoassign the module to the window[name]. (?) In the Browser context you have to assign a name? that will point to window[name] object; the mode? help to decide in which way the object will be overwritten can be 0: ( conserve ) that preserve the original window[name] if present, 1: ( overwrite ) that overwrite anyway, 2: ( merge ) that merge both object.

  • NB Browser doesn't support system API and Node doesn't support some of the Broswer API

Example

File mymodule.js

//Module to be exported
const norb = require('norb')(module);

var export = {};
export.test = function(){console.log('sample function for testing')};

norb.export(export,'myModule');

File index.html (Browser)

...
<script src="./norb.js"></script>
<script>
  norb.require('./mymodule.js',(module)=>module.test());   // "sample function for testing"
</script>
...

File node.js (Node)

const norb = require('norb')(module);
const myModule = norb.require('./mymodule');

myModule.test();  // "sample function for testing"

Contacts

If you like the project feel free to contact me on my Email.

Something gone wrong? Feel free to rise an issue!

Did you like this project and it was usefull? Help me improve my work:

Donate Donate