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

appolo-class

v0.2.15

Published

simple and powerful class system for node js

Downloads

22

Readme

Appolo Class Build Status Dependencies status

Simple and powerful class system for node js

Installation

npm install appolo-class --save

Usage

creating simple class

var Rectangle = Class.define({
    area: function () {
        return 25;
    }
});

 var rectangle = new Rectangle();

creating class with constractor

var Rectangle = Class.define({
    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },

    area: function () {
        return this.width * this.height;
    }
});

var rectangle = new Rectangle(5, 5);

console.log(rectangle.area()) // 25

Inheritance

var Rectangle = Class.define({

    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },
    area: function () {
        return this.width * this.height;
    }
});

var Square = Class.define({

    $config: {
        extends: Rectangle
    },
    
    constructor: function (side) {
        this.callParent(this, side, side);
    }
});

var square = new Square(6);

console.log(square.area()) // 36

you can also use Class.define fucntion

var Rectangle = Class.define({

    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },
    area: function () {
        return this.width * this.height;
    }
});

var Square = Rectangle.define({

    constructor: function (side) {
        this.callParent(side, side);
    }
});

var square = new Square(6);

console.log(square.area()) // 36

Call Parent

use this.callParent function to call the parent method

var Rectangle = Class.define({

    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },

    area: function () {
        return this.width * this.height;
    }
});

var Square = Rectangle.define({

    constructor: function (side) {
        this.callParent(side, side);
    }
});

var Cube = Square.define({

    constructor: function (side) {
        this.callParent(side);

        this.side = side;
    },

    area: function () {
        return 6 * this.callParent()
    },

    volume: function () {
        return Math.pow(this.side,3);
    }
});

var cube = new Cube(5);

console.log(cube.area()) //150;
console.log(cube.volume()) //125;

Statics

var Rectangle = Class.define({
    $config: {
        statics: {
            MIN_SIDE: 1,
            MAX_SIDE: 150
        }
    },

    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },

    area: function () {
        return this.width * this.height;
    }
});


console.log(Rectangle.MIN_SIDE) //1;

var rectangle = new Rectangle(5, 5);
console.log(rectangle.MIN_SIDE.should.equal(1)) //1;

Mixin

used to add protoype functions from other classes

var Events = Class.define({
    bind: function (event, fn) {
        return true;
    },
    unbind: function (event, fn) {
        return true;
    }
});

var Rectangle = Class.define({
    $config: {
        mixins: [Events]
    },

    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },

    area: function () {
        return this.width * this.height;
    }
});

var rectangle = new Rectangle(5, 5);
rectangle.bind('test',function(){})
rectangle.unbind('test',function(){})

Namespace

create class on the global scope

Class.define('Test.Position.Base', {

    constructor: function (symbol, amount, side) {

        this.symbol = symbol;
        this.amount = amount;
        this.side = side;
    }
});

Position.define('Test.Position.Long', {

    constructor: function (symbol, amount) {
        this.callParent( symbol, amount, 2);
    }
});

Position.define("Test.Position.Short", {

    constructor: function (symbol, amount) {

        this.callParent(symbol, amount, 2);
    }
});

var short = new Test.Position.Short();
var long = new Test.Position.Long();

Contractor Name

you can define the class name

var Position = Class.define({

    constructor: function (symbol, amount, side) {

        this.symbol = symbol;
        this.amount = amount;
        this.side = side;

    }
});

var Long = Position.define({
    $config: {
        name: "long"
    },

    constructor: function (symbol, amount) {
        this.callParent( symbol, amount, 2);
    }
});

var Short = Position.define({
    $config: {
        name: "short"
    },
    constructor: function (symbol, amount) {

        this.callParent(symbol, amount, 2);
    }
});


var short = new Short();
var long = new Long();

consloe.log(short.constructor.name) // short
console.log(long.constructor.name) //long;

Members (Properties)

define properties with getter and setter functions. if a property in defined to be a member and a getter or setter is not implemented then erro will be trown

var Rectangle = Class.define({
    $config: {
        members: ['area','name']
    },
    
    constructor: function (width, height) {
        this.height = height;
        this.width = width;
    },

    getArea: function () {
        return this.width * this.height;
    },
    getName:function(){
        return this._name;
    },
     setName:function(value){
        this._name = value;
    }
});

var rectangle = new Rectangle(5, 5);
console.log(rectangle.area) //25;

rectangle.area = 10 // error not implemented

Plugins

you can your custom plugins to the class system by adding callback function the function will be called with 3 arguments

  • config - config object of the class
  • klass - class referance
  • parent - parent class referance
Class.addPlugin(function(config,klass,parent){
    //do something
});

Tests

    grunt test

License

The appolo class library is released under the MIT license. So feel free to modify and distribute it as you wish.