JavaScript collection classes.
An ObjectSet instance can hold objects (not primitives as a performance tradeoff.)
var alpha = {length: 5};
var beta = {length: 4};
var gamma = {length: 5};
var set = new hormigas.ObjectSet(alpha, beta, alpha);
set.size; // 2
set.has(alpha); // true
set['delete'](beta);
set.add(gamma);
set.toArray(); // [alpha, gamma] or [gamma, alpha]
set.forEach(function(element) {
console.log(element.length);
});
set.every(function(element) {
return element.length > 0;
}); // true
set.some(function(element) {
return element.length > 0;
}); // true
set.reduce(function(accumulator, element) {
return {value: accumulator.length + element.length};
}); // 10
set.map(function(element) {
return element.length;
}); // [5, 5]
set.filter(function(element) {
return element.length > 4;
}); // [alpha, gamma] or [gamma, alpha]
set.empty();
You can also mixin ObjectSet functionality into other constructors
app.MyModel = function() {
hormigas.ObjectSet.call(this);
};
hormigas.ObjectSet.mixin(app.MyModel.prototype);
or mixin to just a single object.
var obj = {};
hormigas.ObjectSet.mixin(obj);
See http://peter.michaux.ca/downloads/hormigas/ for production ready builds.
Stable.
Tested working in IE6 and newer browsers by a variety of manufacturers.
None.
GitHub: https://github.com/petermichaux/hormigas
To build the production ready files, you need JSMin or any other tool with the same command line interface. Then just type "make" at the command line and look in the build directory for the results.
For the record, this is how I installed JSMin. Note that I have /Users/peter/bin in my PATH.
$ cd ~/tmp
$ curl -O https://raw.github.com/douglascrockford/JSMin/master/jsmin.c
$ gcc -o jsmin jsmin.c
$ mv jsmin ~/bin
$ rm jsmin.c
$ which jsmin
/Users/peter/bin/jsmin
To run the automated tests, open tst/runner.html in a web browser.
Peter Michaux
petermichaux@gmail.com
http://peter.michaux.ca/
@petermichaux
Simplified BSD License. See the included LICENSE file for details.