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

neuronjs

v10.0.3

Published

Neuron is A Full Feature CommonJS Module Manager, Dependency Graph Handler and Loader for Browsers

Downloads

25

Readme

NPM version Build Status

Neuron

First of all, neuron is not designed for human developers to use directly. Most usually, it works together with cortex.

Neuron is a full feature CommonJS module loader which makes your node-style modules run in browsers.

  • Implements commonjs Module/1.0 standard.
  • Fully supports SemVer and SemVer ranges: '^a.b.c', '~a.b.c', '>=a.b.c', etc.
  • Implements File Modules of node.js (Maybe the only module loader which could do that.)
  • Supports cyclic dependencies.
  • Implements require.resolve() for browsers which is similar to node.js.
  • Completely isolated sandboxes.

Neurons are the core components of the nervous system. They processes and transmits chemical signals to others as well as javascript modules work with others by passing runtime objects.

With Cortex and Neuron, we write web modules exactly the same as we work with node.js, with no Module/Wrappings, no *MD, etc.

You could remove all those annoying and noisy things out of your mind, and, just focus on the origin and code your web modules like node.js.

Neuron is designed to run in the background without your concern, UNLIKE RequireJS and many other loaders.

We're trying to return to the origin of commonjs. There should be only ONE standard, that is, Module/1.0.


Build dist

$ node node/build

With ecma5 compatibility

$ node node/build ecma5

NPM module: neuronjs

A package to get the JavaScript file of neuron.

var neuron = require('neuronjs');
neuron.version(); // 6.0.0
neuron.content(function(err, content){
  content; // The file content of neuron.js
});

neuron.version();

Returns String the version of neuron for browsers, not the version of npm module neuronjs

neuron.write(dest, callback)

  • dest path
  • callback function(err)

Writes the content of neuron.js to the dest

neuron.content(callback)

  • callback function(err, content)
  • content Buffer the buffer of the content of neuron.js

Gets the content of neuron.js


Neuron Loader for Browsers

Getting Started

Installation

npm install
grunt

Usage

Frequent configurations, for more, just see Configuration Hierarchies section.

<script src="/dist/neuron.js"></script>
<script>
neuron.config({
	path: 'http://localhost/mod'
});
</script>

For the example above:

module '[email protected]' will be located at 'http://localhost/mod/abc/0.1.1/abc.js'

Methods

require(id)

  • id String module identifier.

To require modules. See CommonJS Module/1.0

require.async(id, callback)

  • id String module identifier.
  • callback function(exports) callback must be passed, or require.async will do nothing.

Asynchronously loads a module by id, and then passes the module exports to callback.

You should always pass the callback parameter because neuron can not make sure the exact time when a module is loaded asynchronously.

It is NOT a good practice if the logic of your code relies on the result of the require.async()d module without a callback.

require.resolve(path)

  • path String the relative path to be resolved according to the current module.

Returns the resolved absolute path of the resource.

Returns undefined if path is not a relative path.

Returns undefined if path is even outside the current package.

facade()

facade(identifier);

facade(identifier, data);

Method facade loads a module. If the module.exports has a method named init, facade method will run the init method.

We call this kind of modules as facade modules

identifier String

module name with version, seperated with '@'. For example: '[email protected]'

data Object

If data is defined, data will be passed as the parameter of the init method.


Developer Guide

Neuron CORE supplies no high-level APIs, which means that neuron core only cares about module dependencies and module wrapping while will do nothing about things such as fetching modules from remote server and injecting them into the current document, and never cares about where a specific module should come from.

You could do all these things in your will (by write your own lib/load.js and adjust Gruntfile.js). Nevertheless, neuron have a basic configuration file which located at lib/load.js.

Configuration

neuron.config(settings);

settings.path String

CommonJS module path, like NODE_PATH, default to 'the root directory of neuronjs'.

Pay attension that path will not be resolved to absolute url. So if you don't want a relative path, don't forget 'http://'.

settings.loaded String|Array.<id>

To tell neuron loader that those modules are already loaded, and prevent duplicate loading.

If String, we can separate different ids with '|' (comma).

neuron.config({
	loaded: ['[email protected]', '[email protected]']
});

settings.graph Object

The directed graph of all dependencies, which could be parsed by neuron-graph.

The arithmetics to generate the graph is complicated and hard to describe, see https://github.com/kaelzhang/neuron/blob/master/doc/graph.md for details (Too Long; Don't Read)

define()

With cortex, you might NEVER use this method.

ALWAYS use builders to generate this method.

define(identifier, dependencies, factory, options);

id (full module id)

Format: <package-name>@<version>/<path-with-extension>

Type: string

The real pathname relative to the root directory of the package.

dependencies

Array.<id>

factory

function(require, exports, module, __filename, __dirname){}

options

options.main

Type Boolean

whether the module is the main entry, i.e. the package.main field in package.json

options.map

Type Object

<id>:<full-module-id>.

require('./a')
require('./lib')
// ->
// map: {
//   './a': '[email protected]/a.js'
//   // require a directory
//   './lib': '[email protected]/lib/index.js'
// }

Events

Event | Emitted ------------ | ------------ beforeready | when the module is needed by others beforeload | before being downloaded load | when the module is downloaded ready | when the module is ready to be require()d

neuron.on('ready', function(id){
  console.log('module "' + id + '" is ready to be `require()`d');
});

Related Projects