ampersand-collection
Advanced tools
Comparing version 1.3.3 to 1.3.4
{ | ||
"name": "ampersand-collection", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -13,2 +13,3 @@ # ampersand-collection | ||
<!-- starthide --> | ||
## browser support | ||
@@ -18,4 +19,5 @@ | ||
](https://ci.testling.com/ampersandjs/ampersand-collection) | ||
<!-- endhide --> | ||
## install | ||
## Installation | ||
@@ -26,2 +28,3 @@ ``` | ||
<!-- starthide --> | ||
## massive flexibility | ||
@@ -75,4 +78,72 @@ | ||
In order to deal with this (because sometimes this is a legitimate scenario), `collection` simply creates a read-only `isCollection` property on all collection objects that can be used to check whether or a not a given object is in fact a collection object no matter what its constructor was. | ||
<!-- endhide --> | ||
## API Reference | ||
### extend `AmpersandCollection.extend([attributes])` | ||
### constructor/initialize `new AmpersandCollection([modelsArray], [options])` | ||
### model `collection.model` | ||
### mainIndex `collection.mainIndex | ||
### indexes `collections.indexes` | ||
### isModel `collection.isModel(model)` | ||
### length `collection.length` | ||
### isCollection `collection.isCollection` | ||
### add `collection.add(modelOrObject)` | ||
### serialize `collection.serialize()` | ||
### toJSON `collection.toJSON()` | ||
### set `collection.set(models, [options])` | ||
### get `collection.get(query, [indexName])` | ||
### at `collection.at(index)` | ||
### remove `collection.remove(models, [options])` | ||
### reset `collection.reset(models, [options])` | ||
### sort `collection.sort([options])` | ||
### **proxied ES5 array methods (9)** | ||
The base AmpersandCollection proxies some basic ES5 methods to the underlying model array: | ||
* indexOf | ||
* lastIndexOf | ||
* every | ||
* some | ||
* forEach | ||
* each (alias for forEach) | ||
* map | ||
* filter | ||
* reduce | ||
* reduceRight | ||
Unlike a backbone collection it doesn not include underscore and all the array methods from underscore, though if you wish more functions than those built into modern browsers, you can mixin [ampersand-collection-underscore-mixin](#ampersand-collection-underscore-mixin) to get them. | ||
```javascript | ||
var people = People([ | ||
{ name: 'Phil', hatColor: 'red' }, | ||
{ name: 'Jenn', hatColor: 'green' }, | ||
{ name: 'Henrik', hatColor: 'blue' }, | ||
{ name: 'Julie', hatColor: 'yellow' } | ||
]); | ||
people.map(function (person) { return person.name; }) //=> ['Phil', 'Jenn', 'Henrik', 'Julie'] | ||
people.filter(function (person) { | ||
return person.name[0] === 'J'; | ||
}) //=> ['Jenn', 'Julie'] | ||
``` | ||
<!-- starthide --> | ||
@@ -79,0 +150,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
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
25779
157
0