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

metatype

v0.0.0

Published

a simple bit of code for using objects and prototypes as if you were writing javascript.

Downloads

13

Readme

metatype

metatype is a simple bit of code for using objects and prototypes as if you were writing javascript.

metatype.extend

metatype.extend(prototype1, prototype2, ...)

Creates a new object that inherits from the prototypes given as arguments. Accepts any number of prototypes. Prototypes should be formatted as an Object.create propertiesObject. For more info on propertiesObject and Object.create, see this article on MDN. Keep in mind that order is important, a value on prototype2 will override a value on prototype1 and so on.

IMPORTANT

Remember if you set a .value, the default is that that value is not writable. So if you want to to modify properties on the prototype after creation, you must set propertiesObject.writable: true.

metatype.create

metatype.create(arg1, arg2, ...)

Create a new object from a prototype. If the prototype has a method named init, that method will be called with the arguments passed to this method.

var b = metatype.extend({
        init: {
            value: function (a, b) {
                this.a = a;
                this.b = b.
            }
        }
    }).create("one", "two")

console.log(b.a  === "one"); //true
console.log(b.b  === "two"); //true

metatype.set

metatype.set(keyString, value)

Really more of a bonus method to set properties. Will vivify any undefined properties.

b.set("foo.bar.0.baz", "vivified");
console.log(b.foo.bar[0].baz === "vivified"); // true;

metatype.get

metatype.get(keyString)

Getter using same syntax as above.

console.log(Array.isArray(b.get("foo.bar"))); //true
console.log(b.get("foo.bar.0.baz") === "vivified"); //true

Disclaimer

With great power comes great responsibility. If you don't understand the code in metatype.js, don't use it or you'll just end up shooting yourself in the foot. It's < 40 lines of code, take a few minutes and make sure you understand what's going on.

For example:

var person = metatype.extend({
        knowledge: {
            value: {
                javascript: false,
                html: false,
                css: false
            }
        }
    });

var me = person.create();

me.set("knowledge.javascript", true);

If you don't know why person.knowledge.javascript is true in the above example, you should learn a bit more about prototypes and object in JS!

Enjoy!