Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blimpy

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blimpy - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

.babelrc

2

license.txt
MIT License
Copyright (c) [year] [fullname]
Copyright (c) 2017 Marco Burstein

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "blimpy",
"version": "0.0.3",
"version": "0.0.4",
"description": "Easily set the class of an object.",
"main": "blimpy.js",
"main": "dist/blimpy.min.js",
"scripts": {
"build": "babel src/blimpy.js -o dist/blimpy.min.js",
"test": "mocha tests"

@@ -13,4 +14,7 @@ },

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-minify": "^0.2.0",
"mocha": "^5.0.0"
}
}

@@ -11,5 +11,11 @@ <div align="center">

<p>
<img src="https://img.shields.io/npm/v/blimpy.svg" />
<img src="https://img.shields.io/travis/skunkmb/blimpy.svg" />
<img src="https://img.shields.io/github/license/skunkmb/blimpy.svg" />
<a href="https://www.npmjs.com/package/blimpy">
<img src="https://img.shields.io/npm/v/blimpy.svg" />
</a>
<a href="https://www.travis-ci.org/skunkmb/blimpy">
<img src="https://img.shields.io/travis/skunkmb/blimpy.svg" />
</a>
<a href="https://github.com/skunkmb/blimpy/blob/master/license.txt">
<img src="https://img.shields.io/github/license/skunkmb/blimpy.svg" />
</a>
</p>

@@ -27,7 +33,13 @@ </div>

**What should you do?**
- Using `Object.setPrototypeOf` [is terrible for performance](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf).
- 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.js` is less than `1000 bytes`).
- 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 `8` tests using MochaJS)
- blimpy is **well-tested** (blimpy has `16` tests using MochaJS)

@@ -83,2 +95,12 @@ ## Sample Usage

#### 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

@@ -93,8 +115,18 @@

#### 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
```js
// Require blimpy.
let blimpy = require('blimpy');
// Arbitrary class.
// Some arbitrary class.
class FoodClass {

@@ -111,3 +143,3 @@ constructor(name) {

// Some food object without the `Food` class prototype, in this case
// Some food object without the `FoodClass` prototype, in this case
// an object literal.

@@ -114,0 +146,0 @@ let foodObject = {

let assert = require('assert');
let blimpy = require('../blimpy.js');

@@ -48,88 +47,172 @@ /**

describe('blimpy', () => {
describe('"positives"', () => {
let foodObject;
let blimpys = ['src/blimpy', 'dist/blimpy.min'];
beforeEach(() => {
foodObject = {
name: 'apple',
price: 50,
};
assert.equal(foodObject.__proto__, Object.prototype);
});
for (let i = 0; i < blimpys.length; i++) {
let currentBlimpy = blimpys[i]
let blimpy = require('../' + currentBlimpy + '.js');
describe('.withClass', () => {
let foodObjectWithProto;
describe(currentBlimpy, () => {
describe('"positives"', () => {
let foodObject;
beforeEach(() => {
foodObjectWithProto = blimpy.withClass(Food, foodObject);
});
it('should not mutate the original object', () => {
foodObject = {
name: 'apple',
price: 50,
};
assert.equal(foodObject.__proto__, Object.prototype);
});
it('should return the object with the new prototype', () => {
assert.equal(foodObjectWithProto.__proto__, Food.prototype);
});
describe('.withClass', () => {
let foodObjectWithProto;
it('should add working methods', () => {
assert.equal(foodObjectWithProto.getPriceStr(), '$50');
});
beforeEach(() => {
foodObjectWithProto = blimpy.withClass(Food, foodObject);
});
it('should work on objects with a prototype', () => {
let drinkObject = new Drink('water');
assert.equal(drinkObject.__proto__, Drink.prototype);
it('should not mutate the original object', () => {
assert.equal(foodObject.__proto__, Object.prototype);
});
foodObjectWithProto = blimpy.withClass(Food, drinkObject);
assert.equal(foodObjectWithProto.__proto__, Food.prototype);
it('should return the object with the new prototype', () => {
assert.equal(
foodObjectWithProto.__proto__,
Food.prototype
);
});
it('should add working methods', () => {
assert.equal(foodObjectWithProto.getPriceStr(), '$50');
});
it('should work on objects with a prototype', () => {
let drinkObject = new Drink('water');
assert.equal(drinkObject.__proto__, Drink.prototype);
foodObjectWithProto = blimpy.withClass(Food, drinkObject);
assert.equal(
foodObjectWithProto.__proto__,
Food.prototype
);
});
});
});
});
describe('"negatives"', () => {
let foodObject;
describe('.withProto', () => {
let foodObjectWithProto;
beforeEach(() => {
foodObject = new Food('apple');
assert.equal(foodObject.__proto__, Food.prototype);
beforeEach(() => {
foodObjectWithProto = blimpy.withProto(
Food.prototype,
foodObject
);
});
it('should not mutate the original object', () => {
assert.equal(foodObject.__proto__, Object.prototype);
});
it('should return the object with the new prototype', () => {
assert.equal(
foodObjectWithProto.__proto__,
Food.prototype
);
});
it('should add working methods', () => {
assert.equal(foodObjectWithProto.getPriceStr(), '$50');
});
it('should work on objects with a prototype', () => {
let drinkObject = new Drink('water');
assert.equal(drinkObject.__proto__, Drink.prototype);
foodObjectWithProto = blimpy.withClass(Food, drinkObject);
assert.equal(
foodObjectWithProto.__proto__,
Food.prototype
);
});
});
});
describe('.withNoClass', () => {
let foodObjectWithNoProto;
describe('"negatives"', () => {
let foodObject;
beforeEach(() => {
foodObjectWithNoProto = blimpy.withNoClass(foodObject);
});
it('should not mutate the original object', () => {
foodObject = new Food('apple');
assert.equal(foodObject.__proto__, Food.prototype);
});
it('should return the object with the new prototype', () => {
assert.equal(
foodObjectWithNoProto.__proto__,
Object.prototype,
);
});
describe('.withNoClass', () => {
let foodObjectWithNoProto;
it('should remove working methods', () => {
assert.equal(foodObjectWithNoProto.getPriceStr, undefined);
beforeEach(() => {
foodObjectWithNoProto = blimpy.withNoClass(foodObject);
});
it('should not mutate the original object', () => {
assert.equal(foodObject.__proto__, Food.prototype);
});
it('should return the object with the new prototype', () => {
assert.equal(
foodObjectWithNoProto.__proto__,
Object.prototype,
);
});
it('should remove working methods', () => {
assert.equal(foodObjectWithNoProto.getPriceStr, undefined);
});
it('should work on objects with no prototype', () => {
foodObject = {
name: 'apple',
price: 50,
};
assert.equal(foodObject.__proto__, Object.prototype);
foodObjectWithNoProto = blimpy.withNoClass(foodObject);
assert.equal(
foodObjectWithNoProto.__proto__,
Object.prototype,
);
});
});
it('should work on objects with no prototype', () => {
foodObject = {
name: 'apple',
price: 50,
};
assert.equal(foodObject.__proto__, Object.prototype);
describe('.withNoProto', () => {
let foodObjectWithNoProto;
foodObjectWithNoProto = blimpy.withNoClass(foodObject);
assert.equal(
foodObjectWithNoProto.__proto__,
Object.prototype,
);
beforeEach(() => {
foodObjectWithNoProto = blimpy.withNoProto(foodObject);
});
it('should not mutate the original object', () => {
assert.equal(foodObject.__proto__, Food.prototype);
});
it('should return the object with the new prototype', () => {
assert.equal(foodObjectWithNoProto.__proto__, null);
});
it('should remove working methods', () => {
assert.equal(foodObjectWithNoProto.getPriceStr, undefined);
});
it('should work on objects with no prototype', () => {
foodObject = {
name: 'apple',
price: 50,
};
assert.equal(foodObject.__proto__, Object.prototype);
foodObjectWithNoProto = blimpy.withNoClass(foodObject);
assert.equal(
foodObjectWithNoProto.__proto__,
Object.prototype,
);
});
});
});
});
});
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc