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 🙏

© 2025 – Pkg Stats / Ryan Hefner

classified-magic

v0.1.5

Published

OOP for NodeJS with magic

Downloads

55

Readme

#Classified Magic

OOP for NodeJS with magic. Inspired by Classified

Build Status

NPM

Installation

$ npm install classified-magic

Quick Start

var classified = require('classified-magic');

//root definition
var RootClass = classified(function() {
	//sample constants
	this.SOME_CONSTANT = 'foo';
	
	//sample public properties
	this.data = {};
	
	this.sampleProperty = 4.5;
	
	this.sampleDeepProperty = {
		sample1: 'Hello',
		sample2: [4, 5, 6, 7],
		sample3: {
			bool	: true,
			regex	: /^abc/,
			date	: new Date(),
			string	: String
		}
	};
	
	//sample protected properties
	this._sampleProperty = 5.5;
	
	this._sampleDeepProperty = {
		sample1: '_Hello',
		sample2: [8, 9, 0, 1]
	};
	
	//sample private properties
	this.__sampleProperty = 6.5;
	
	this.__sampleDeepProperty = {
		sample1: '__Hello',
		sample2: [12, 13, 14, 15]
	};
	
	//sample constructor
	this.___construct = function() {
		this.constructCalled = true;
	};
	
	//sample public method
	this.sampleMethod = function() {
		return this._sampleMethod();
	};
	
	//sample protected method
	this._sampleMethod = function() {
		return this.__sampleMethod();
	};
	
	//sample private method
	this.__sampleMethod = function() {
		return this.SOME_CONSTANT + this._sampleProperty;
	};
	
	this.sampleAccessMethod = function() {
		return this.sampleMethod()
		+ this._sampleMethod()
		+ this.__sampleMethod();
	};
	
	//sample magic methods
	this.___get = function(name) {
		return this.data[name];
	};
	
	this.___set = function(name, value) {
		this.data[name] = value;
	};
	
	this.___enum = function() {
		return Object.keys(this.data);
	};
	
	this.___has = function(name, value) {
		return this.data.hasOwnProperty(name);
	};
	
	this.___delete = function(name) {
		delete this.data[name];
	};
});

//sample child definition
//you can use object or function as the definition
var ChildClass = RootClass.extend(function() {
	//sample constants
	this.SOME_CONSTANT_2 = 'bar';
	
	//sample protected properties
	this._sampleProperty = 7.5;
	
	//sample public methods
	this.sampleMethod = function() {
		return this._sampleMethod();
	};
	
	//sample protected methods
	this._sampleMethod = function() {
		return this.___parent._sampleMethod();
	};
});

//instantiate child
var child = ChildClass.load();

//test it
console.log(child.sampleMethod()); //--> foo7.5

try {
	child._sampleMethod();
} catch(e) {
	console.log('Protected call did not work');
}

//test magic
child.foo = 4;

console.log(child.data.foo);

Features

  • Public, Private, Protected
  • Constants
  • Inheritance
  • Works on server or client
  • Magic methods - get, set and iterators

Methods

  • define(object|function) - Defines the class
  • extend(object|function) - Adds a parent to be combined with the definition
  • definition() - Returns the entire definition including the protected and private properties
  • parents() - Returns direct parents of this definition
  • get() - Returns the publically accessable class definition function
  • load() - Returns class defined instantiation
  • register(string) - saves a state of the definition which can be recalled in trait
  • trait(string|function|object) - will setup the provided as a parent, if string will recall from registry

What's up with the underscores?

  • _ - protected properties and methods
  • __ - private properties and methods
  • ___ - Magic placeholder