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

ampersand-collection

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-collection - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

39

ampersand-collection.js

@@ -38,2 +38,20 @@ var BackboneEvents = require('backbone-events-standalone');

// overridable serialize method
serialize: function () {
return this.map(function (model) {
if (model.serialize) {
return model.serialize();
} else {
var out = {};
extend(out, model);
delete out.collection;
return out;
}
});
},
toJSON: function () {
return this.serialize();
},
set: function (models, options) {

@@ -293,4 +311,25 @@ options = extend({add: true, remove: true, merge: true}, options);

var arrayMethods = [
'indexOf',
'lastIndexOf',
'every',
'some',
'forEach',
'map',
'filter',
'reduce',
'reduceRight'
];
arrayMethods.forEach(function (method) {
Collection.prototype[method] = function () {
return this.models[method].apply(this.models, arguments);
};
});
// alias each/forEach for maximum compatibility
Collection.prototype.each = Collection.prototype.forEach;
Collection.extend = classExtend;
module.exports = Collection;

2

package.json
{
"name": "ampersand-collection",
"version": "1.1.2",
"version": "1.2.0",
"author": "Henrik Joreteg <henrik@andyet.net>",

@@ -5,0 +5,0 @@ "bugs": {

@@ -197,1 +197,29 @@ var test = require('tape');

});
test('Proxy `Array.prototype` methods', function (t) {
var c = new Collection();
c.set([{id: 'thing'}, {id: 'other'}]);
var ids = c.map(function (item) {
return item.id;
});
t.deepEqual(ids, ['thing', 'other']);
var count = 0;
c.each(function () {
count++;
});
t.equal(count, 2);
c.forEach(function () {
count++;
});
t.equal(count, 4);
t.end();
});
test('Serialize/toJSON method', function (t) {
var c = new Collection();
c.set([{id: 'thing'}, {id: 'other'}]);
t.deepEqual([{id: 'thing'}, {id: 'other'}], c.serialize());
t.equal(JSON.stringify([{id: 'thing'}, {id: 'other'}]), JSON.stringify(c));
t.end();
});
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