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

beerjs

v3.7.1

Published

Javascript framework

Downloads

7

Readme

README

Beerjs is an event driven module architecture, and inspired by Nicholas C. Zakas "Creating A Scalable JavaScript Application Architecture".

To start:


var options = {
  storage:[{
      name:'nameOfStorage',
      type:'localStorage'
  }]
};

BEER.CORE.start(options).run();

Modules:

Create folder 'modules' and and then create ie 'init.js'

init.js


(function(e){
    'use strict';
    e.CORE.subscribe('init', (function( sandbox ){

        var requestResponse = function(response){
            sandbox.notify('eventName', response);
        };

        return {
            init:function(){
                //this.container: the element who has the 'data-module' attribute
                //Rest call:
                sandbox.request().get('/api/v1/', requestResponse.bind(self), {});
            },
            destroy:function(){}
        };

    }));
}( BEER ));

another.js


(function(e){
    'use strict';
    e.CORE.subscribe('another', (function( sandbox ){

        var eventResponse = function(data){
            console.log(data);//from init.js
        };

        return {
            init:function(){
                //this.container: the element who has the 'data-module' attribute
                sandbox.listen('eventName', eventResponse.bind(self));
            },
            destroy:function(){}
        };

    }));
}( BEER ));

In dom, add data-module="init"


<div data-module="init"></div>

<div data-module="another"></div>

Working with dom objects:


<div data-module="another">
  <button class="js-button">Button</button>
</div>

(function(e){
    'use strict';
    e.CORE.subscribe('another', (function( sandbox ){
        //another.js
        var eventResponse = function(data){
            console.log(data);//from init.js
            this.container.child('js-button').on('click', function(event){
                /*
                For all options on dom element, check dom.js in dist/core/lib/dom.js
                */
            });
        };

        return {
            init:function(){
                //this.container: the element who has the 'data-module' attribute
                sandbox.listen('eventName', eventResponse.bind(self));
            },
            destroy:function(){}
        };

    }));
}( BEER ));

Storage


var storage = sandbox.storage();
storage.set('key', 'value');
storage.get('key');

Extend

If you need to share same code base between modules:

  1. create folder extends next to modules folder.

  2. create extension:


(function(e){
    'use strict';
    e.CORE.extension('extendMe', (function( ){

        return {
            createExtend:function(){
                console.log('I am extended!');
            }
        };
    }));
}( BEER ));

In module:


(function(e){
    'use strict';
    e.CORE.subscribe('init', (function( sandbox ){

        return {
            init:function(){
                this.extendMe.createExtend();
            },
            destroy:function(){}
        };
    }), 'extendMe');// if wanted, you can include more by comma seperation: 'one, two, .....'
}( BEER ));

Create own services:

  1. create folder services next to modules

  2. create service:


//If you need to add custom services to project. Services specific for this project
(function( e ){
    'use strict';
    e.CORE.define('serviceExample', (function(){
        return {
            init:function(){
                console.log('Service extension has been called');
            }
        }
    }));
}( BEER ));

In module:


(function(e){
    'use strict';
    e.CORE.subscribe('init', (function( sandbox ){

        return {
            init:function(){
                sandbox.service('serviceExample').init();
            },
            destroy:function(){}
        };
    }));
}( BEER ));

Validate form (min, max, email, equal, time(12:00) and date)


(function(e){
    'use strict';
    e.CORE.subscribe('another', (function( sandbox ){

        return {
            init:function(){
                var validate = element.attr('data-validate');
                var element  = this.container('elementToValidate');
                if( validate ){
                    var conditions  = validate.split(',');
                    if(conditions.length > 0) {
                        var hasErrors = sandbox.validate().check( conditions, element.value(), []);
                        // Will return if input field in this case only contains of 2 letters:
                        // Object { func: "min", hasError: true }
                    }
                }
            },
            destroy:function(){}
        };
    }));
}( BEER ));

<div data-module="another">
    <input type="text" data-validate="min:5, max:20" />//only 2 letters
</div>