
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
If you need to quickly assign a prototype to an object,
such as one from a database, blimpy is the best way to do it.
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?
Object.setPrototypeOf
is terrible for performance.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.min.js
is less than 400 bytes
).2
built-in JS functions).16
tests using MochaJS)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 };
Use blimpy.
let food = blimpy.withClass(FoodClass, foodObject);
Profit. (Use the class's methods.)
food.eat();
console.log(food.getPriceStr());
npm install --save blimpy
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.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.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.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.// 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());
FAQs
Easily set the class of an object.
The npm package blimpy receives a total of 1 weekly downloads. As such, blimpy popularity was classified as not popular.
We found that blimpy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.