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

modelized

v0.3.6

Published

Having fun with models & aspects!

Downloads

10

Readme

Modelized

Example

function Person(values) {
	Model.initialize(this, values);
}

Model.define(Person, {
	firstName: {type: String, required: true},
	lastName: String,
	birthDate: Date
});

Under the hood, Model is based on Aspect so models could also be initialized with the following, especially if they're given more aspects than only Model:

function Person(values) {
	Aspect.initialize(this, values);
}

Aspect

Basics

Using Aspect is pretty simple: you just have to call Aspect#initialize within constructors, like:

function Thing() {
	Aspect.initialize(this);
}

Observable.enhance(Thing);
Capable.enhance(Thing);

You can also provide arguments for initialization, to every aspects:

function Thing(capacity) {
	Aspect.initialize(this, capacity);
}

If you need to initialize aspects in particular order feel free to do so but as a counterpart you'll become responsible for initializing each of them properly. You could do so as well if you need to provide different parameters to respective initialize functions:

function Thing(capacity) {
	Capable.initialize(this, capacity);
	Observable.initialize(this, 15);
}

Defining Aspects

Aspects can be forged from any function, in that way:

function Whatever(target) {
    // Well, up to you there...
}

Aspect.define(Whatever);

Basically, the aspect function is responsible for enhancing whatever it aims to apply to (usually a prototype or some instance of a constructor). Syntax is quite free here and you could write something like:

function Capable(constructor) {
    // `Capable` aspect only aims to give final objects the `getCapacity` method:
	constructor.prototype.getCapacity = function getCapacity() {
	    return this.capacity;
	};
}

Also, Aspect#define allows you to specify the function responsible for initializing objects - if necessary:

Aspect.define(Capable, function initialize(capacity) { // hopefully it can be anonymous
    this.capacity = capacity;
});

Once again, syntax is quite free here also. It's really up to developer's intention.

Own Scopes

In order to prevent collisions with other aspects or objects' direct properties you could enclose any aspect's stuff into its own scope. By default, aspects' own scopes are provided at objects' level as pre-defined variables based on aspects' names and could be retrieved with the following:

Aspect.define(Capable, function(capacity) {
	var self = this, own = Capable.getOwnScope(self);
	
	own.capacity = capacity;
}

Things could be even more tricky if getOwnScope is customized, like:

Capable.getOwnScope = function(object) {
    var key = "THERE";
	return (object[key] = object[key] || {});
};