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

igneousjs

v0.2.6

Published

A fully featured ES5 implementation for OOP in javascript for the browser or NodeJS!

Downloads

3

Readme

IgneousJS

A fully featured ES5 implementation for OOP in javascript for the browser or NodeJS!

NPM info

Build Status

The main goal of this library is to provide a small but powerful implementation of Object Oriented constructs in JavaScript (ES5). With ES6 on the way, this library is meant to bridge the gap by using as close to the correct syntax as possible.

Installation:

Node.js:

npm install --save igneousjs

You can then access it like so:


var ig = require('igneousjs'),
  Enum = ig.Enum,
  Class = ig.Class;

// OR...

var Enum = require('igneousjs/enum');
var Class = require('igneousjs/class');

Browser:

Using Bower:

bower install igneousjs --save

Traditional:

The distributable files are located here.

Once it is loaded into the webpage, Class and Enum are available in the global scope!

Using AMD or CommonJS? No problem, it supports all types by default! (thanks to UMD)

Usage:

Enums:


var LightSwitch = Enum.extend('Off', 'On');

var kitchenLight = LightSwitch.On;

console.log(kitchenLight === LightSwitch.On);    // => true
console.log(kitchenLight);                       // => 1
console.log(LightSwitch[kitchenLight]);          // => 'On';
console.log(LightSwitch.toString(kitchenLight)); // => 'On';

for(var state in LightSwitch){
  if(kitchenLight == state) {
    console.log('The light is ' + LightSwitch[state]);
  }
}

var Direction = Enum.extend({
  'North': 1,
  'South': 2,
  'East':  4,
  'West':  8
});

var myHeading = Direction.North | Direction.East;

console.log(myHeading);            // => 5
console.log(Direction[myHeading]); // => undefined

console.log(Enum.hasFlag(myHeading, Direction.North)); // => true
console.log(Enum.hasFlag(myHeading, Direction.West));  // => false

Classes:


var Polygon = Class.extend({

  // Class constructor, ran during instantiation.
  constructor: function (height, width) { 
    this.name = 'Polygon';
    this.height = height;
    this.width = width;
  },

  // Class method, `this` being the class instance.
  sayName: function () {
    console.log('Hi, I am a', this.name + '.');
  }
});

var Rectangle = Polygon.extend({
  constructor: function (height, width) {
    this.super(height, width); // Call the parent method with `this.super`.
    this.name = 'Rectangle';
  },

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

var Square = Rectangle.extend({
  constructor: function (length) {
    this.super(length, length);
    this.name = 'Square';
  },

  area: function () {
    return this.super();
  },

  sayName: function () {
    this.super(); // This super call overrides Polygon's.
    console.log('And I\'m way better than a Rectangle!');
  }
});

var p = new Polygon(4, 3);
var r = new Rectangle(2, 5);
var s = new Square(5);

p.sayName(); // => Hi, I am a Polygon.
r.sayName(); // => Hi, I am a Rectangle.
s.sayName(); // => Hi, I am a Square.
             //    And I'm way better than a Rectangle!

console.log(r.area())  // => 10			 
console.log(s.area()); // => 25

console.log(s instanceof Rectangle); // => true
console.log(r instanceof Square); // => false

API

Enum

Enum.extend(obj)

  • Returns: Enum,
  • Accepts:
  • obj: Object

Creates a new enum from an object hash.

Enum.extend(arr)

  • Returns: Enum,
  • Accepts:
  • arr: Array

Creates a new enum from an array of strings.

Enum.extend(str1, str2, ...)

  • Returns: Enum,
  • Accepts:
  • str: String (one or many)

Creates a new enum from a set of strings.

<enum>.toString(val)

  • Returns: String,
  • Accepts:
  • val: Integer (Enum value)

Returns the string value (key) based on the enum value (integer).

Enum.hasFlag(enumValue, flagValue)

  • Returns: Boolean,
  • Accepts:
  • enumValue: Integer (Enum Value, your variable)
  • flagValue: Integer (Enum Value, the flag to check for)

Runs a bitwise comparison to see if the enum has a specified flag.

Class

Class.extend(obj)

  • Returns: Class,
  • Accepts:
  • obj: Object

Creates a new Class type. obj accepts a constructor function to act as the constructor. Each method will be run in the context of the class instance, exposing a super method that calls the parent instance of the current function.

See John Resig's original blog post for more information.

<class>.extend(obj)

  • Returns: Class,
  • Accepts:
  • obj: Object

This is the same as Class.extend, but may be called on any class implementation created using igneous.

Inspired By:

Simple JavaScript Inheritance

By John Resig

MIT Licensed.

(Inspired by base2 and Prototype)

Blog Post

TypeScript Enums

By Microsoft (et al.)

GitHub Project

TypeScriptLang.org

License:

See LICENSE for more information.