ampersand-collection-underscore-mixin
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -16,5 +16,5 @@ var _ = require('underscore'); | ||
// Mix in each Underscore method as a proxy to `Collection#models`. | ||
_.each(methods, function(method) { | ||
_.each(methods, function (method) { | ||
if (!_[method]) return; | ||
mixins[method] = function() { | ||
mixins[method] = function () { | ||
var args = slice.call(arguments); | ||
@@ -30,6 +30,6 @@ args.unshift(this.models); | ||
// Use attributes instead of properties. | ||
_.each(attributeMethods, function(method) { | ||
_.each(attributeMethods, function (method) { | ||
if (!_[method]) return; | ||
mixins[method] = function(value, context) { | ||
var iterator = _.isFunction(value) ? value : function(model) { | ||
mixins[method] = function (value, context) { | ||
var iterator = _.isFunction(value) ? value : function (model) { | ||
return model.get ? model.get(value) : model[value]; | ||
@@ -43,5 +43,5 @@ }; | ||
// `filter`. | ||
mixins.where = function(attrs, first) { | ||
mixins.where = function (attrs, first) { | ||
if (_.isEmpty(attrs)) return first ? void 0 : []; | ||
return this[first ? 'find' : 'filter'](function(model) { | ||
return this[first ? 'find' : 'filter'](function (model) { | ||
var value; | ||
@@ -58,3 +58,3 @@ for (var key in attrs) { | ||
// of `find`. | ||
mixins.findWhere = function(attrs) { | ||
mixins.findWhere = function (attrs) { | ||
return this.where(attrs, true); | ||
@@ -64,3 +64,3 @@ }; | ||
// Plucks an attribute from each model in the collection. | ||
mixins.pluck = function(attr) { | ||
mixins.pluck = function (attr) { | ||
return _.invoke(this.models, 'get', attr); | ||
@@ -67,0 +67,0 @@ }; |
{ | ||
"name": "ampersand-collection-underscore-mixin", | ||
"description": "A mixin for extending ampersand-collection with underscore methods.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -13,3 +13,7 @@ "bugs": { | ||
"devDependencies": { | ||
"ampersand-collection": "^1.0.0" | ||
"ampersand-collection": "^1.0.0", | ||
"ampersand-state": "^4.3.2", | ||
"precommit-hook": "~0.3.10", | ||
"run-browser": "~1.2.0", | ||
"tape": "~2.12.1" | ||
}, | ||
@@ -27,3 +31,24 @@ "homepage": "https://github.com/ampersandjs/ampersand-collection-underscore-mixin", | ||
"url": "git://github.com/ampersandjs/ampersand-collection-underscore-mixin" | ||
}, | ||
"scripts": { | ||
"test": "node test/index.js", | ||
"validate": "jshint .", | ||
"start": "run-browser test/index.js" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/9..latest", | ||
"firefox/17..latest", | ||
"firefox/nightly", | ||
"chrome/22..latest", | ||
"chrome/canary", | ||
"opera/12..latest", | ||
"opera/next", | ||
"safari/5.1..latest", | ||
"ipad/6.0..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2..latest" | ||
] | ||
} | ||
} |
@@ -5,2 +5,6 @@ # ampersand-collection-underscore-mixin | ||
If you're using an [ampersand-rest-collection](http://ampersandjs.com/docs/#ampersand-rest-collection) this is already mixed in for you. | ||
Out of the box, ampersand-collections proxy the [ES5 iteration methods already](http://ampersandjs.com/docs/#ampersand-collection-proxied-es5-array-methods-9) so you don't _have_ to use this mixin, but if you want all the underscore methods, or better browser support, you can use this. | ||
## install | ||
@@ -7,0 +11,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8515
8
140
44
5
1