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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mash-js

v1.0.1

Published

Functional prototype mixins

Readme

mash.js

I think I have some AOP in my OOP

install: npm install mash-js

size: < 1 kB

What it does

Mash uses mixin functions to modify objects and prototypes.

When you mash(object, mixin) mash will attempt to apply the mixin to the object's prototype. Mash will revert to plain objects if no prototype or object was found.

Then, two methods will be added to the mashed object:

mashed.create( arg1, arg2, ... argN )

Create an instance of your mashed object. This will auto-invoke any init method found on the instance, passing along the arguments.

Returns: the new instance.

mashed.mixin( object, options )

Run the same mixin on another object. See class mixins.

Returns: a reference to the mashed object's prototype.

Performance

Measuring raw prototype access..
[mash.js mixins] x 6,404,834 ops/sec ±0.41% (100 runs sampled)
[native prototypes] x 6,248,419 ops/sec ±0.32% (94 runs sampled)
Fastest is [mash.js mixins]

Measuring constructor abstractions..
[mash.js create] x 4,838,249 ops/sec ±0.33% (100 runs sampled)
[coffee class] x 5,568,587 ops/sec ±0.35% (99 runs sampled)
[p.js init] x 4,353,508 ops/sec ±0.50% (100 runs sampled)
Fastest is [coffee class]

(very fast)

Basic objects

demo: http://jsbin.com/xipat/8/edit?js,console

var greeting = mash(function () {
  this.init = function (prefix) {
    console.log(prefix + ' mash');
  };
});

var yo = greeting.create('yo');
// 'yo mash'

Object.getPrototypeOf(yo) === greeting;
// true

Class mixins

demo: http://jsbin.com/micil/8/edit?js,console

function Animal() {}
mash(Animal, function() {
  this.init = function(name) {
    this.name = name;
  };

  this.move = function(meters) {
    console.log(this.name + ' moved ' + meters + 'm.');
  };
});

function Snake() {}
mash(Snake, function () {
  var supr = Animal.mixin(this);

  this.move = function() {
    console.log('Slithering...');
    supr.move.call(this, 5);
  };
});

function Horse() {}
mash(Horse, function () {
  var supr = Animal.mixin(this);

  this.move = function() {
    console.log('Galloping...');
    supr.move.call(this, 45);
  };
});

var sam = Snake.create('Sammy the Python');
var tom = Horse.create('Tommy the Palomino');
sam.move();
tom.move();

// Slithering...
// Sammy the Python moved 5m.
// Galloping...
// Tommy the Palomino moved 45m.

Functional mixins

demo: http://jsbin.com/borat/8/edit?js,console

var withSword = function () {
  this.slash = function (dmg) {
    console.log('Sword slash for ' + dmg + ' damage!');
  };
};

var withMagic = function () {
  this.fireball = function (dmg) {
    console.log('Cast fireball for ' + dmg + ' damage!');
  };
};

function Hero() {}
mash(Hero, function () {
  withSword.call(this);
  withMagic.call(this);

  this.attack = function (enemy) {
    console.log('Hero attacks the ' + enemy);
    this.slash(25);
    this.fireball(80);
  };
});

var hero = new Hero();
hero.attack('Orc');

// Hero attacks the Orc
// Sword slash for 25 damage!
// Cast fireball for 80 damage!

Contributing

npm install to install testing libs.

npm test to make sure tests pass :)

npm run bench for a good time

MIT License

This code may be freely distributed under the MIT license.

--

https://www.youtube.com/watch?v=OH0n_Ew2YDM