node package manager


pico common tools

A Lean Modular System For Browsers and NodeJS

A single file solution to use commonjs/nodejs module definition in your browser or server (node.js), it can also compile javascripts into single file. It has tiny footprint, 188 lines of codes (before uglify and minification)

  • Work on browsers and NodeJS (Universal Javascript)
  • Same syntax on client and server
  • Support circular dependency
  • Small footprint
  • Asyncronous Module Definition
  • Build single file from multiple files
  • Plugin system to extend it capabilities

Download just the pico.js or clone github

git clone pico-common
<script src=PATH/TO/pico.js></script>
var pico=require('PATH/TO/pico.js')

It has similar requirejs config but not compatible. To bootstrap the amd{
            cb(null, pico.require(name))
    var main=require('main')

To compress project into one file{

Script A

var scriptB=require('scriptB')
return function(){
    return 'Script A'

Script B

var scriptA=require('scriptA')
return function(){
    return 'Script B'

to avoid circular dependency, results returned by require() function can't be use in the document scope, they can only be used in function such as this.load


return {
    a:function(){return 'Hello World'}

in runtime

var scriptA=require('ScriptA')
console.log(scriptA.a()) // 'Hello World' 
pico.reload('ScriptA', "return {a:function(){return 'Hot Reload'}}")
console.log(scriptA.a()) // 'Hot Reload' 

The object returns by require() are not the actual object itself but a proxy object. In most cases, you can handle the proxy object just like the actual object except for few cases

// obj.js 
// somewhere.js 
var proxy=require('obj')
proxy[a] // 1 
Object.keys(proxy) // [] 
Object.keys(Object.getPrototypeOf(proxy)) // ['a','b'] 
// arr.js 
module.exports=[ 1, 2 ]
// somewhere.js 
var proxy=require('arr')
proxy[0] // 1 
proxy.length // 0 
Object.getPrototypeOf(proxy).length // 2 
// func.js 
module.exports=function(name){return name}
// somewhere.js 
var proxy=require('func')
proxy('hello pico') // 'hello pico' 
proxy.length // 0 
Object.getPrototypeOf(proxy).length // 1 

![Function diagram]( digraph G { run->js->compile->linker->define; js->placeHolder; linker->loader->linker; loader->getExt; loader->js; loader->define->getMod; getMod->placeHolder; build->replace_define->compile; parse->js; import->nodejs_require; export->getMod; } )