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

blimpy

v0.0.6

Published

Easily set the class of an object.

Downloads

21

Readme

Why?

Most databases don't store an object's prototype. This means if you're doing something like

firebaseRef.set(someFoodObject);

and then retrieving it later, it won't have the methods from FoodClass.

What should you do?

  • Using Object.setPrototypeOf is terrible for performance.
  • A combination of Object.assign and Object.create is ugly if you're doing it over and over again.
  • Object.create and Object.getOwnPropertyDescriptors is even worse.

Using blimpy makes it easy to add a prototype to an object.

  • blimpy is small (blimpy.min.js is less than 400 bytes).
  • blimpy is simple (blimpy only uses 2 built-in JS functions).
  • blimpy is well-tested (blimpy has 16 tests using MochaJS)

Sample Usage

  1. Get some object. It doesn't matter where from.

    • …from a database…

      let foodObject = getFoodObjectFromDatabase('apple');
    • …or with an object literal…

      let foodObject = { name: 'apple', price: 5 };
  2. Use blimpy.

    let food = blimpy.withClass(FoodClass, foodObject);
  3. Profit. (Use the class's methods.)

    food.eat();
    console.log(food.getPriceStr());

Install

npm install --save blimpy

Full Docs

withClass

Adds a class's prototype to an object (without mutating it).

blimpy.withClass(someClass, someObject)

  • someClass: The class to add.
  • someObject: The object to add it to.
  • Returns: The new object with the class's prototype.

withProto

Adds a prototype to an object (without mutating it).

blimpy.withProto(someProto, someObject)

  • someClass: The prototype to add.
  • someObject: The object to add it to.
  • Returns: The new object with the prototype.

withNoClass

Removes an object's prototype (without mutating it). Actually, this sets the object's prototype to Object.prototype (the default object prototype).

blimpy.withNoClass(someObject)

  • someObject: The object to remove the class from.
  • Returns: The new object without a prototype.

withNoProto

Removes an object's prototype (without mutating it). Unlike withNoClass, this sets the prototype of the object to null, not Object.prototype. For example, this means that blimpy.withNoClass(someObject).toString() works but blimpy.withNoProto(someObject).toString() does not.

blimpy.withNoClass(someObject)

  • someObject: The object to remove the class from.
  • Returns: The new object without a prototype.

Full Example File

// Require blimpy.
let blimpy = require('blimpy');

// Some arbitrary class.
class FoodClass {
    constructor(name) {
        this.name = name;
        this.price = name.length;
    }

    getPriceStr() {
        return '$' + this.price.toString();
    }
}

// Some food object without the `FoodClass` prototype, in this case
// an object literal.
let foodObject = {
    name: 'apple',
    price: 5,
}

// Add the prototype with blimpy.
let food = blimpy.withClass(FoodClass, foodObject);

// Logs `$5`.
console.log(food.getPriceStr());