allthethings
Advanced tools
Comparing version 0.0.1-alpha-4 to 0.0.1-alpha-5
@@ -1,2 +0,2 @@ | ||
/*! allthethings v0.0.1-alpha-4 | ||
/*! allthethings v0.0.1-alpha-5 | ||
* https://github.com/markdalgleish/allthethings.js | ||
@@ -10,3 +10,4 @@ * Copyright (c) 2012 Mark Dalgleish; Licensed MIT */ | ||
filter: /^(filter|is)/, | ||
some: /^(some|contains)/ | ||
some: /^(some|contains|has)/, | ||
every: /^(every|all)/ | ||
}, | ||
@@ -13,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! allthethings v0.0.1-alpha-4 | (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)/},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-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={})); |
@@ -6,3 +6,4 @@ (function(exports) { | ||
filter: /^(filter|is)/, | ||
some: /^(some|contains)/ | ||
some: /^(some|contains|has)/, | ||
every: /^(every|all)/ | ||
}, | ||
@@ -9,0 +10,0 @@ |
{ | ||
"name": "allthethings", | ||
"description": "Let your iterations read like actual sentences.", | ||
"version": "0.0.1-alpha-4", | ||
"version": "0.0.1-alpha-5", | ||
"homepage": "https://github.com/markdalgleish/allthethings.js", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -57,9 +57,9 @@ [![Build Status](https://secure.travis-ci.org/markdalgleish/allthethings.js.png)](http://travis-ci.org/markdalgleish/allthethings.js) | ||
```js | ||
var words = ['all', 'the', 'things']; | ||
var things = ['all', 'the', 'things']; | ||
function shout(word) { | ||
return alert(word); | ||
function log(thing) { | ||
console.log(thing); | ||
} | ||
shout.allThe(words); | ||
log.allThe(things); | ||
``` | ||
@@ -81,3 +81,3 @@ | ||
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' is performed. | ||
@@ -108,3 +108,3 @@ When filtering, it's idiomatic to use 'fromThe' instead of 'allThe': | ||
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' is performed. | ||
@@ -147,3 +147,3 @@ When reducing, it's idiomatic to use 'fromThe' instead of 'allThe': | ||
If your named function starts with 'some' or 'contains', then a 'some' is performed. | ||
If your named function starts with 'some', 'contains' or 'has', then a 'some' is performed. | ||
@@ -172,2 +172,38 @@ When using 'some', it's idiomatic to use 'inThe' instead of 'allThe': | ||
```js | ||
var numbers = [-2,-1,0,1,2]; | ||
function hasNegatives(number) { | ||
return number < 0; | ||
} | ||
hasNegatives.inThe(numbers); // true | ||
``` | ||
## every | ||
If your named function starts with 'every' or 'all', then an 'every' is performed. | ||
When using 'every', it's idiomatic to use 'inThe' instead of 'allThe': | ||
```js | ||
var numbers = [1,2,3,4,5]; | ||
function everyNumberIsPositive(number) { | ||
return number > 0; | ||
} | ||
everyNumberIsPositive.inThe(numbers); // true | ||
``` | ||
```js | ||
var numbers = [1,2,3,4,5]; | ||
function allPositive(number) { | ||
return number > 0; | ||
} | ||
allPositive.inThe(numbers); // true | ||
``` | ||
## Elite hacker tips | ||
@@ -174,0 +210,0 @@ |
@@ -79,2 +79,6 @@ /*global require:true */ | ||
function hasNegatives(number) { | ||
return number < 0; | ||
} | ||
test.strictEqual(someNegatives.inThe(numbers), true); | ||
@@ -85,2 +89,26 @@ test.strictEqual(someNegatives.inThe(positiveNumbers), false); | ||
test.strictEqual(containsNegatives.inThe(positiveNumbers), false); | ||
test.strictEqual(hasNegatives.inThe(numbers), true); | ||
test.strictEqual(hasNegatives.inThe(positiveNumbers), false); | ||
test.done(); | ||
}, | ||
'every': function(test) { | ||
var numbers = [-1,0,1], | ||
negativeNumbers = [-1,-2,-3]; | ||
function everyNumberIsNegative(number) { | ||
return number < 0; | ||
} | ||
function allNegatives(number) { | ||
return number < 0; | ||
} | ||
test.strictEqual(everyNumberIsNegative.inThe(negativeNumbers), true); | ||
test.strictEqual(everyNumberIsNegative.inThe(numbers), false); | ||
test.strictEqual(allNegatives.inThe(negativeNumbers), true); | ||
test.strictEqual(allNegatives.inThe(numbers), false); | ||
@@ -87,0 +115,0 @@ test.done(); |
110250
203
257