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

fusing

v1.0.0

Published

Prototype fusion

Downloads

118,264

Readme

fusing

From bigpipe.ioVersion npmBuild StatusDependenciesCoverage Status

Fusing is a small library that creates the base class that is used in all of bigpipe's components. It takes care of:

  • Prototypical inheritance.
  • An API for adding readable and writable properties to these classes.
  • Adding default methods which are commonly used.
  • A Backbone.extend based extending of the prototypes.

Installation

The stable versions of this module are released in the npm registry and can be installed using:

npm install --save fusing

The --save tells npm to automatically save this dependency in your package.json.

Getting Started

The module is required just like any other module you use. It exposes a single function that takes care of all the merging.

'use strict';

var fuse = require('fusing');

And that is all we need to start with inheritance. When you want to have a class inherit from the EventEmitter you only need to pass in the class references:

function Example() {

}

fuse(Example, require('events').EventEmitter);

This will tell fuse to use the .prototype of the EventEmitter for your Example class. In addition to that it has added a couple of function to your class which makes it easier to setup the prototypes and extend Example again.

Example.readable

One of the functions that are added to your class is readable this allows you to easily specify which properties or methods on the Example.prototype are read-only and should never be overridden by other code. This is ideal for protecting your private methods.

Example.readable('config', { foo: 'bar' });

The example above added the property config to the prototype with the foo/bar object as value. If you wonder how this magic works, take a look a our predefine project for more details.

Please note that this function is added on the Example function not on the Example.prototype.

Example.writable

This is the writable equivalent of the function above. This allows you to specify properties on the prototype that are writable. The added benefit of this function is that your methods will not be enumerable (which is also true for all properties/methods added using the readable function).

Example.writable('property', 'foo');

Please note that this function is added on the Example function not on the Example.prototype.

Example.get

Add a getter to the prototype.

var foo = 'bar'
Example.get('property', function () {
  return foo;
});

Please note that this function is added on the Example function not on the Example.prototype.

Example.set

Add a getter AND a setter to the prototype.

var foo = 'bar'
Example.set('property', function () {
  return foo;
}, function (value) {
  return foo = value;
});

Please note that this function is added on the Example function not on the Example.prototype.

Example.extend

This allows you to use the same extend functionality that you might be accustomed to with Backbone in your own classes:

var MyExample = Example.extend({
  method: function method() {
    console.log('my custom method');
  },

  prop: 132
});

Please note that this function is added on the Example function not on the Example.prototype.

Example.predefine

As it's sometimes useful to also create readable and writable properties when your class is constructed, we decided to expose the predefine module on your class. Which allows you use the same readable pattern again:

function Example() {
  var writable = Example.predefine(this, Example.predefine.WRITABLE)
    , readable = Example.predefine(this);

  readable('private', 134);
  readable('evn', process.ENV.NODE_ENV || 'development');
  writable('value', 100);
}

fuse(Example, require('eventemitter3'));

Please note that this function is added on the Example function not on the Example.prototype.

License

MIT