allthethings
Advanced tools
Comparing version 0.0.1-alpha-5 to 0.0.1-alpha-6
@@ -1,2 +0,2 @@ | ||
/*! allthethings v0.0.1-alpha-5 | ||
/*! allthethings v0.0.1-alpha-6 | ||
* https://github.com/markdalgleish/allthethings.js | ||
@@ -8,4 +8,5 @@ * Copyright (c) 2012 Mark Dalgleish; Licensed MIT */ | ||
var rules = { | ||
filter: /^(filter|is)/, | ||
reduce: /^(reduce|add|calculate)/, | ||
filter: /^(filter|is)/, | ||
reduceRight: /^(reduce|add|calculate)Right/, | ||
some: /^(some|contains|has)/, | ||
@@ -12,0 +13,0 @@ every: /^(every|all)/ |
@@ -1,2 +0,2 @@ | ||
/*! allthethings v0.0.1-alpha-5 | (c) 2012 Mark Dalgleish | https://github.com/markdalgleish/allthethings.js | Licensed MIT */ | ||
(function(e){var t={reduce:/^(reduce|add|calculate)/,filter:/^(filter|is)/,some:/^(some|contains|has)/,every:/^(every|all)/},n=function(e,n){var r="_allthethings_func";return e[r]||(e[r]=n[Object.keys(t).reduce(function(n,r){return t[r].test(e.name)?r:n},"map")])},r=function(e){return n(this,e).call(e,this)};["allThe","fromThe","inThe"].forEach(function(e){Function.prototype[e]=r}),e.rules=t})(typeof exports=="object"&&exports||(this.allthethings={})); | ||
/*! allthethings v0.0.1-alpha-6 | (c) 2012 Mark Dalgleish | https://github.com/markdalgleish/allthethings.js | Licensed MIT */ | ||
(function(e){var t={filter:/^(filter|is)/,reduce:/^(reduce|add|calculate)/,reduceRight:/^(reduce|add|calculate)Right/,some:/^(some|contains|has)/,every:/^(every|all)/},n=function(e,n){var r="_allthethings_func";return e[r]||(e[r]=n[Object.keys(t).reduce(function(n,r){return t[r].test(e.name)?r:n},"map")])},r=function(e){return n(this,e).call(e,this)};["allThe","fromThe","inThe"].forEach(function(e){Function.prototype[e]=r}),e.rules=t})(typeof exports=="object"&&exports||(this.allthethings={})); |
(function(exports) { | ||
var rules = { | ||
filter: /^(filter|is)/, | ||
reduce: /^(reduce|add|calculate)/, | ||
filter: /^(filter|is)/, | ||
reduceRight: /^(reduce|add|calculate)Right/, | ||
some: /^(some|contains|has)/, | ||
@@ -7,0 +8,0 @@ every: /^(every|all)/ |
{ | ||
"name": "allthethings", | ||
"description": "Let your iterations read like actual sentences.", | ||
"version": "0.0.1-alpha-5", | ||
"version": "0.0.1-alpha-6", | ||
"homepage": "https://github.com/markdalgleish/allthethings.js", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -7,3 +7,3 @@ [![Build Status](https://secure.travis-ci.org/markdalgleish/allthethings.js.png)](http://travis-ci.org/markdalgleish/allthethings.js) | ||
### Let your iterations read like actual sentences: | ||
### Let your array iterations read like actual sentences: | ||
@@ -34,2 +34,12 @@ ``` js | ||
ALLTHETHINGS.JS allows you to *sentencify* the following array methods: | ||
- [forEach](#foreach--map) | ||
- [map](#foreach--map) | ||
- [filter](#filter) | ||
- [reduce](#reduce--reduceright) | ||
- [reduceRight](#reduce--reduceright) | ||
- [some](#some) | ||
- [every](#every) | ||
### Gimme gimme | ||
@@ -49,8 +59,8 @@ | ||
[min]: https://raw.github.com/markdalgleish/allthethings/master/dist/allthethings.min.js | ||
[max]: https://raw.github.com/markdalgleish/allthethings/master/dist/allthethings.js | ||
[min]: https://raw.github.com/markdalgleish/allthethings.js/master/dist/allthethings.min.js | ||
[max]: https://raw.github.com/markdalgleish/allthethings.js/master/dist/allthethings.js | ||
## forEach / map | ||
By default, 'allThe' performs a 'map' on the array, which doubles as a 'forEach': | ||
By default, 'allThe' performs a [*map*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map) on the array, which doubles as a [*forEach*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach): | ||
@@ -83,3 +93,3 @@ ### forEach | ||
If your named function starts with 'filter' or 'is', then a 'filter' is performed. | ||
If your named function starts with 'filter' or 'is', then a [*filter*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter) is performed. | ||
@@ -108,6 +118,8 @@ When filtering, it's idiomatic to use 'fromThe' instead of 'allThe': | ||
## reduce | ||
## reduce / reduceRight | ||
If your named function starts with 'reduce', 'calculate' or 'add', then a 'reduce' is performed. | ||
If your named function starts with 'reduce', 'calculate' or 'add', then a [*reduce*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/Reduce) is performed. | ||
If you add 'Right' to any of these, then a [*reduceRight*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/ReduceRight) is performed instead. | ||
When reducing, it's idiomatic to use 'fromThe' instead of 'allThe': | ||
@@ -149,3 +161,3 @@ | ||
If your named function starts with 'some', 'contains' or 'has', then a 'some' is performed. | ||
If your named function starts with 'some', 'contains' or 'has', then a [*some*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/some) is performed. | ||
@@ -186,3 +198,3 @@ When using 'some', it's idiomatic to use 'inThe' instead of 'allThe': | ||
If your named function starts with 'every' or 'all', then an 'every' is performed. | ||
If your named function starts with 'every' or 'all', then an [*every*](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every) is performed. | ||
@@ -189,0 +201,0 @@ When using 'every', it's idiomatic to use 'inThe' instead of 'allThe': |
@@ -67,2 +67,23 @@ /*global require:true */ | ||
'reduceRight': function(test) { | ||
var numbers = [1,2,3]; | ||
function reduceRightTest(a, b) { | ||
return b; | ||
} | ||
function calculateRightTest(a, b) { | ||
return b; | ||
} | ||
function addRightTest(a, b) { | ||
return b; | ||
} | ||
test.equal(reduceRightTest.fromThe(numbers), 1); | ||
test.equal(calculateRightTest.fromThe(numbers), 1); | ||
test.equal(addRightTest.fromThe(numbers), 1); | ||
test.done(); | ||
}, | ||
'some': function(test) { | ||
@@ -69,0 +90,0 @@ var numbers = [-1,0,1], |
111793
221
269