Comparing version 1.6.0 to 1.6.1
{ | ||
"name": "valentine" | ||
, "description": "JavaScripts Functional Sister. Utilitiy, Iterators, type checking" | ||
, "version": "1.6.0" | ||
, "version": "1.6.1" | ||
, "homepage": "https://github.com/ded/valentine" | ||
@@ -6,0 +6,0 @@ , "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)" |
@@ -89,2 +89,14 @@ \ / _. | _ ._ _|_ o ._ _ | ||
* v.inArray(array, needle) => boolean | ||
* v.memo(fn, hasher) => function | ||
``` js | ||
// use memo to cache expensive methods | ||
var getAllTheDom = v.memo(function () { | ||
return v(document.getElementsByTagName('*')).toArray() | ||
}) | ||
getAllTheDom().each(modifier) | ||
``` | ||
### parallel api | ||
* v.parallel([fn args]) => void | ||
@@ -112,3 +124,6 @@ | ||
### waterfall api | ||
* v.waterfall([fn args]) | ||
* v.waterfall([fn1, fn2<, fn3>], callback) | ||
@@ -136,3 +151,2 @@ ``` js | ||
* v.waterfall([fn1, fn2<, fn3>], callback) | ||
* v.queue([fn args]) | ||
@@ -160,6 +174,6 @@ | ||
* v.is.fun(o) | ||
* v.is.str(o) | ||
* v.is.ele(o) | ||
* v.is.arr(o) | ||
* v.is.func(o) | ||
* v.is.string(o) | ||
* v.is.element(o) | ||
* v.is.array(o) | ||
* v.is.arrLike(o) | ||
@@ -169,7 +183,8 @@ * v.is.num(o) | ||
* v.is.args(o) | ||
* v.is.emp(o) | ||
* v.is.dat(o) | ||
* v.is.empty(o) | ||
* v.is.date(o) | ||
* v.is.nan(o) | ||
* v.is.nil(o) | ||
* v.is.und(o) | ||
* v.is.undef(o) | ||
* is.regexp(o) | ||
* v.is.obj(o) | ||
@@ -176,0 +191,0 @@ |
@@ -322,2 +322,12 @@ (function (name, context, definition) { | ||
// nicer looking aliases | ||
is.empty = is.emp | ||
is.date = is.dat | ||
is.regexp = is.reg | ||
is.element = is.ele | ||
is.array = is.arr | ||
is.string = is.str | ||
is.undef = is.und | ||
is.func = is.fun | ||
var o = { | ||
@@ -324,0 +334,0 @@ each: function (a, fn, scope) { |
@@ -527,21 +527,21 @@ if (typeof module !== 'undefined' && module.exports) { | ||
test('String', 3, function () { | ||
ok(v.is.str('hello'), 'v.is.str("hello")') | ||
ok(v.is.str(''), 'v.is.str("")') | ||
ok(!v.is.str(null), '!v.is.str(null)') | ||
ok(v.is.string('hello'), 'v.is.str("hello")') | ||
ok(v.is.string(''), 'v.is.str("")') | ||
ok(!v.is.string(null), '!v.is.str(null)') | ||
}) | ||
test('Function', 6, function () { | ||
ok(v.is.fun(function () {}), 'function () {}') | ||
ok(v.is.fun(Function), 'Function') | ||
ok(v.is.fun(new Function), 'new Function') | ||
ok(!v.is.fun({}), 'not {}') | ||
ok(!v.is.fun([]), 'not []') | ||
ok(!v.is.fun(''), 'not ""') | ||
ok(v.is.func(function () {}), 'function () {}') | ||
ok(v.is.func(Function), 'Function') | ||
ok(v.is.func(new Function), 'new Function') | ||
ok(!v.is.func({}), 'not {}') | ||
ok(!v.is.func([]), 'not []') | ||
ok(!v.is.func(''), 'not ""') | ||
}) | ||
test('Array', 4, function () { | ||
ok(v.is.arr([]), '[]') | ||
ok(v.is.arr(Array(1)), 'Array(1)') | ||
ok(v.is.arr(new Array), 'new Array') | ||
ok(!v.is.arr(Object), 'not Object') | ||
ok(v.is.array([]), '[]') | ||
ok(v.is.array(Array(1)), 'Array(1)') | ||
ok(v.is.array(new Array), 'new Array') | ||
ok(!v.is.array(Object), 'not Object') | ||
}) | ||
@@ -571,17 +571,17 @@ | ||
test('Empty', 6, function () { | ||
ok(v.is.emp({}), '{}') | ||
ok(v.is.emp([]), '[]') | ||
ok(v.is.emp(''), '""') | ||
ok(!v.is.emp({foo:'bar'}), '{foo:bar}') | ||
ok(!v.is.emp([1]), '[1]') | ||
ok(!v.is.emp('i'), '"i"') | ||
ok(v.is.empty({}), '{}') | ||
ok(v.is.empty([]), '[]') | ||
ok(v.is.empty(''), '""') | ||
ok(!v.is.empty({foo:'bar'}), '{foo:bar}') | ||
ok(!v.is.empty([1]), '[1]') | ||
ok(!v.is.empty('i'), '"i"') | ||
}) | ||
test('Date', 1, function () { | ||
ok(v.is.dat(new Date), 'new Date') | ||
ok(v.is.date(new Date), 'new Date') | ||
}) | ||
test('RegExp', 2, function () { | ||
ok(v.is.reg(/i/), '/i/') | ||
ok(v.is.reg(new RegExp("i")), 'new RegExp("i")') | ||
ok(v.is.regexp(/i/), '/i/') | ||
ok(v.is.regexp(new RegExp("i")), 'new RegExp("i")') | ||
}) | ||
@@ -596,5 +596,5 @@ | ||
test('Undefined', 3, function () { | ||
ok(v.is.und(), 'no args') | ||
ok(v.is.und(undefined), 'undefined') | ||
ok(!v.is.und(null), 'undefined') | ||
ok(v.is.undef(), 'no args') | ||
ok(v.is.undef(undefined), 'undefined') | ||
ok(!v.is.undef(null), 'undefined') | ||
}) | ||
@@ -611,7 +611,7 @@ | ||
test('Element', 5, function () { | ||
ok(v.is.ele(document.body), 'document.body') | ||
ok(v.is.ele(document.createElement('div')), 'createElement("div")') | ||
ok(!v.is.ele({}), 'not {}') | ||
ok(!v.is.ele([]), 'not []') | ||
ok(!v.is.ele(document.getElementsByTagName('body')), 'not getElementsByTagName()') | ||
ok(v.is.element(document.body), 'document.body') | ||
ok(v.is.element(document.createElement('div')), 'createElement("div")') | ||
ok(!v.is.element({}), 'not {}') | ||
ok(!v.is.element([]), 'not []') | ||
ok(!v.is.element(document.getElementsByTagName('body')), 'not getElementsByTagName()') | ||
}) | ||
@@ -618,0 +618,0 @@ } |
@@ -329,2 +329,12 @@ /*! | ||
// nicer looking aliases | ||
is.empty = is.emp | ||
is.date = is.dat | ||
is.regexp = is.reg | ||
is.element = is.ele | ||
is.array = is.arr | ||
is.string = is.str | ||
is.undef = is.und | ||
is.func = is.fun | ||
var o = { | ||
@@ -331,0 +341,0 @@ each: function (a, fn, scope) { |
@@ -7,2 +7,2 @@ /*! | ||
*/ | ||
(function(e,t,n){typeof module!="undefined"?module.exports=n():typeof define=="function"?define(n):t[e]=t.v=n()})("valentine",this,function(){function p(e){this.values=e,this.index=0}function d(e,t){return new m(e,t)}function v(e,t){for(var n in t)e[n]=t[n]}function m(e,t){this.val=e,this._scope=t||i,this._chained=0}var e=this,t=e.v,n=[],r=Object.prototype.hasOwnProperty,i=null,s=n.slice,o="map"in n,u="reduce"in n,a=/(^\s*|\s*$)/g,f={each:o?function(e,t,r){n.forEach.call(e,t,r)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)r in e&&t.call(n,e[r],r,e)},map:o?function(e,t,r){return n.map.call(e,t,r)}:function(e,t,n){var r=[],i;for(i=0,l=e.length;i<l;i++)i in e&&(r[i]=t.call(n,e[i],i,e));return r},some:o?function(e,t,n){return e.some(t,n)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r,e))return!0;return!1},every:o?function(e,t,n){return e.every(t,n)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)if(r in e&&!t.call(n,e[r],r,e))return!1;return!0},filter:o?function(e,t,n){return e.filter(t,n)}:function(e,t,n){for(var r=[],i=0,s=0,o=e.length;i<o;i++)if(i in e){if(!t.call(n,e[i],i,e))continue;r[s++]=e[i]}return r},indexOf:o?function(e,t,n){return e.indexOf(t,isFinite(n)?n:0)}:function(e,t,n){n=n||0,n=n<0?0:n,n=n>e.length?e.length:n;for(var r=n;r<e.length;r++)if(r in e&&e[r]===t)return r;return-1},lastIndexOf:o?function(e,t,n){return e.lastIndexOf(t,isFinite(n)?n:e.length)}:function(e,t,n){n=n||e.length,n=n>=e.length?e.length:n<0?e.length+n:n;for(var r=n;r>=0;--r)if(r in e&&e[r]===t)return r;return-1},reduce:u?function(e,t,r,i){return n.reduce.call(e,t,r,i)}:function(e,t,n,r){e||(e=[]);var i=0,s=e.length;if(arguments.length<3)do{if(i in e){n=e[i++];break}if(++i>=s)throw new TypeError("Empty array")}while(1);for(;i<s;i++)i in e&&(n=t.call(r,n,e[i],i,e));return n},reduceRight:u?function(e,t,r,i){return n.reduceRight.call(e,t,r,i)}:function(e,t,n,r){!e&&(e=[]);var i=e.length,s=i-1;if(arguments.length<3)do{if(s in e){n=e[s--];break}if(--s<0)throw new TypeError("Empty array")}while(1);for(;s>=0;s--)s in e&&(n=t.call(r,n,e[s],s,e));return n},find:function(e,t,n){var r;return f.some(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},reject:function(e,t,n){var r=[];for(var i=0,s=0,o=e.length;i<o;i++)if(i in e){if(t.call(n,e[i],i,e))continue;r[s++]=e[i]}return r},size:function(e){return h.toArray(e).length},compact:function(e){return f.filter(e,function(e){return!!e})},flatten:function(e){return f.reduce(e,function(e,t){return c.arr(t)?e.concat(f.flatten(t)):(e[e.length]=t,e)},[])},uniq:function(e,t){var n=[],r,i;e=t?f.map(e,t):e;e:for(r=0;r<e.length;r++){for(i=0;i<n.length;i++)if(n[i]===e[r])continue e;n[n.length]=e[r]}return n},merge:function(e,t){var n=e.length,r=0,i;if(isFinite(t.length))for(i=t.length;r<i;r++)e[n++]=t[r];else while(t[r]!==undefined)first[n++]=second[r++];return e.length=n,e},inArray:function(e,t){return!!~f.indexOf(e,t)},memo:function(e,t){var n={};return t||(t=function(e){return e}),function(){var i=t.apply(this,arguments);return r.call(n,i)?n[i]:n[i]=e.apply(this,arguments)}}},c={fun:function(e){return typeof e=="function"},str:function(e){return typeof e=="string"},ele:function(e){return!!e&&!!e.nodeType&&e.nodeType==1},arr:function(e){return e instanceof Array},arrLike:function(e){return e&&e.length&&isFinite(e.length)},num:function(e){return typeof e=="number"},bool:function(e){return e===!0||e===!1},args:function(e){return!!e&&!!r.call(e,"callee")},emp:function(e){var t=0;return c.arr(e)?e.length===0:c.obj(e)?function(){for(var n in e){t++;break}return t===0}():e===""},dat:function(e){return!!(e&&e.getTimezoneOffset&&e.setUTCFullYear)},reg:function(e){return!(!(e&&e.test&&e.exec)||!e.ignoreCase&&e.ignoreCase!==!1)},nan:function(e){return e!==e},nil:function(e){return e===i},und:function(e){return typeof e=="undefined"},def:function(e){return typeof e!="undefined"},obj:function(e){return e instanceof Object&&!c.fun(e)&&!c.arr(e)}},h={each:function(e,t,n){c.arrLike(e)?f.each(e,t,n):function(){for(var i in e)r.call(e,i)&&t.call(n,i,e[i],e)}()},map:function(e,t,n){var i=[],s=0;return c.arrLike(e)?f.map(e,t,n):!function(){for(var o in e)r.call(e,o)&&(i[s++]=t.call(n,o,e[o],e))}()&&i},pluck:function(e,t){return c.arrLike(e)?f.map(e,function(e){return e[t]}):h.map(e,function(e,n){return n[t]})},toArray:function(e){return e?c.arr(e)?e:e.toArray?e.toArray():c.args(e)?s.call(e):f.map(e,function(e){return e}):[]},first:function(e){return e[0]},last:function(e){return e[e.length-1]},keys:Object.keys?function(e){return Object.keys(e)}:function(e){var t=[],n;for(n in e)r.call(e,n)&&(t[t.length]=n);return t},values:function(e){return h.map(e,function(e,t){return t})},extend:function(){var e,t,n,r,s,o=arguments[0],u=1,a=arguments.length;for(;u<a;u++)if((e=arguments[u])!==i)for(t in e){n=o[t],r=e[t];if(o===r)continue;r&&c.obj(r)?(s=n&&c.obj(n)?n:{},o[t]=h.extend(s,r)):r!==undefined&&(o[t]=r)}return o},trim:String.prototype.trim?function(e){return e.trim()}:function(e){return e.replace(a,"")},bind:function(e,t){var n=arguments.length>2?s.call(arguments,2):null;return function(){return t.apply(e,n?n.concat(s.call(arguments)):arguments)}},curry:function(e){if(arguments.length==1)return e;var t=s.call(arguments,1);return function(){return e.apply(null,t.concat(s.call(arguments)))}},parallel:function(e,t){var n=h.toArray(arguments),r=0,s=[],o=[];if(c.arr(e)&&e.length===0||c.fun(e)&&n.length===1)throw new TypeError("Empty parallel array");c.arr(e)||(t=n.pop(),e=n),f.each(e,function(n,u){n(function(){var n=h.toArray(arguments),a=n.shift();if(a)return t(a);s[u]=n,e.length==++r&&(s.unshift(i),f.each(s,function(e){o=o.concat(e)}),t.apply(i,o))})})},waterfall:function(e,t){var n=h.toArray(arguments),r=0;if(c.arr(e)&&e.length===0||c.fun(e)&&n.length===1)throw new TypeError("Empty waterfall array");c.arr(e)||(t=n.pop(),e=n),function s(){var n=h.toArray(arguments);n.push(s);var r=n.shift();!r&&e.length?e.shift().apply(i,n):(n.pop(),n.unshift(r),t.apply(i,n))}(i)},queue:function(e){return new p(c.arrLike(e)?e:h.toArray(arguments))}};return p.prototype.next=function(){return this.index<this.values.length&&this.values[this.index++](),this},v(d,f),v(d,h),d.is=c,d.v=d,d.each(d.extend({},f,h),function(e,t){m.prototype[e]=function(){var e=d.toArray(arguments);e.unshift(this.val);var n=t.apply(this._scope,e);return this.val=n,this._chained?this:n}}),v(m.prototype,{chain:function(){return this._chained=1,this},value:function(){return this.val}}),d.noConflict=function(){return e.v=t,this},d}) | ||
(function(e,t,n){typeof module!="undefined"?module.exports=n():typeof define=="function"?define(n):t[e]=t.v=n()})("valentine",this,function(){function p(e){this.values=e,this.index=0}function d(e,t){return new m(e,t)}function v(e,t){for(var n in t)e[n]=t[n]}function m(e,t){this.val=e,this._scope=t||i,this._chained=0}var e=this,t=e.v,n=[],r=Object.prototype.hasOwnProperty,i=null,s=n.slice,o="map"in n,u="reduce"in n,a=/(^\s*|\s*$)/g,f={each:o?function(e,t,r){n.forEach.call(e,t,r)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)r in e&&t.call(n,e[r],r,e)},map:o?function(e,t,r){return n.map.call(e,t,r)}:function(e,t,n){var r=[],i;for(i=0,l=e.length;i<l;i++)i in e&&(r[i]=t.call(n,e[i],i,e));return r},some:o?function(e,t,n){return e.some(t,n)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)if(r in e&&t.call(n,e[r],r,e))return!0;return!1},every:o?function(e,t,n){return e.every(t,n)}:function(e,t,n){for(var r=0,i=e.length;r<i;r++)if(r in e&&!t.call(n,e[r],r,e))return!1;return!0},filter:o?function(e,t,n){return e.filter(t,n)}:function(e,t,n){for(var r=[],i=0,s=0,o=e.length;i<o;i++)if(i in e){if(!t.call(n,e[i],i,e))continue;r[s++]=e[i]}return r},indexOf:o?function(e,t,n){return e.indexOf(t,isFinite(n)?n:0)}:function(e,t,n){n=n||0,n=n<0?0:n,n=n>e.length?e.length:n;for(var r=n;r<e.length;r++)if(r in e&&e[r]===t)return r;return-1},lastIndexOf:o?function(e,t,n){return e.lastIndexOf(t,isFinite(n)?n:e.length)}:function(e,t,n){n=n||e.length,n=n>=e.length?e.length:n<0?e.length+n:n;for(var r=n;r>=0;--r)if(r in e&&e[r]===t)return r;return-1},reduce:u?function(e,t,r,i){return n.reduce.call(e,t,r,i)}:function(e,t,n,r){e||(e=[]);var i=0,s=e.length;if(arguments.length<3)do{if(i in e){n=e[i++];break}if(++i>=s)throw new TypeError("Empty array")}while(1);for(;i<s;i++)i in e&&(n=t.call(r,n,e[i],i,e));return n},reduceRight:u?function(e,t,r,i){return n.reduceRight.call(e,t,r,i)}:function(e,t,n,r){!e&&(e=[]);var i=e.length,s=i-1;if(arguments.length<3)do{if(s in e){n=e[s--];break}if(--s<0)throw new TypeError("Empty array")}while(1);for(;s>=0;s--)s in e&&(n=t.call(r,n,e[s],s,e));return n},find:function(e,t,n){var r;return f.some(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},reject:function(e,t,n){var r=[];for(var i=0,s=0,o=e.length;i<o;i++)if(i in e){if(t.call(n,e[i],i,e))continue;r[s++]=e[i]}return r},size:function(e){return h.toArray(e).length},compact:function(e){return f.filter(e,function(e){return!!e})},flatten:function(e){return f.reduce(e,function(e,t){return c.arr(t)?e.concat(f.flatten(t)):(e[e.length]=t,e)},[])},uniq:function(e,t){var n=[],r,i;e=t?f.map(e,t):e;e:for(r=0;r<e.length;r++){for(i=0;i<n.length;i++)if(n[i]===e[r])continue e;n[n.length]=e[r]}return n},merge:function(e,t){var n=e.length,r=0,i;if(isFinite(t.length))for(i=t.length;r<i;r++)e[n++]=t[r];else while(t[r]!==undefined)first[n++]=second[r++];return e.length=n,e},inArray:function(e,t){return!!~f.indexOf(e,t)},memo:function(e,t){var n={};return t||(t=function(e){return e}),function(){var i=t.apply(this,arguments);return r.call(n,i)?n[i]:n[i]=e.apply(this,arguments)}}},c={fun:function(e){return typeof e=="function"},str:function(e){return typeof e=="string"},ele:function(e){return!!e&&!!e.nodeType&&e.nodeType==1},arr:function(e){return e instanceof Array},arrLike:function(e){return e&&e.length&&isFinite(e.length)},num:function(e){return typeof e=="number"},bool:function(e){return e===!0||e===!1},args:function(e){return!!e&&!!r.call(e,"callee")},emp:function(e){var t=0;return c.arr(e)?e.length===0:c.obj(e)?function(){for(var n in e){t++;break}return t===0}():e===""},dat:function(e){return!!(e&&e.getTimezoneOffset&&e.setUTCFullYear)},reg:function(e){return!(!(e&&e.test&&e.exec)||!e.ignoreCase&&e.ignoreCase!==!1)},nan:function(e){return e!==e},nil:function(e){return e===i},und:function(e){return typeof e=="undefined"},def:function(e){return typeof e!="undefined"},obj:function(e){return e instanceof Object&&!c.fun(e)&&!c.arr(e)}};c.empty=c.emp,c.date=c.dat,c.regexp=c.reg,c.element=c.ele,c.array=c.arr,c.string=c.str,c.undef=c.und,c.func=c.fun;var h={each:function(e,t,n){c.arrLike(e)?f.each(e,t,n):function(){for(var i in e)r.call(e,i)&&t.call(n,i,e[i],e)}()},map:function(e,t,n){var i=[],s=0;return c.arrLike(e)?f.map(e,t,n):!function(){for(var o in e)r.call(e,o)&&(i[s++]=t.call(n,o,e[o],e))}()&&i},pluck:function(e,t){return c.arrLike(e)?f.map(e,function(e){return e[t]}):h.map(e,function(e,n){return n[t]})},toArray:function(e){return e?c.arr(e)?e:e.toArray?e.toArray():c.args(e)?s.call(e):f.map(e,function(e){return e}):[]},first:function(e){return e[0]},last:function(e){return e[e.length-1]},keys:Object.keys?function(e){return Object.keys(e)}:function(e){var t=[],n;for(n in e)r.call(e,n)&&(t[t.length]=n);return t},values:function(e){return h.map(e,function(e,t){return t})},extend:function(){var e,t,n,r,s,o=arguments[0],u=1,a=arguments.length;for(;u<a;u++)if((e=arguments[u])!==i)for(t in e){n=o[t],r=e[t];if(o===r)continue;r&&c.obj(r)?(s=n&&c.obj(n)?n:{},o[t]=h.extend(s,r)):r!==undefined&&(o[t]=r)}return o},trim:String.prototype.trim?function(e){return e.trim()}:function(e){return e.replace(a,"")},bind:function(e,t){var n=arguments.length>2?s.call(arguments,2):null;return function(){return t.apply(e,n?n.concat(s.call(arguments)):arguments)}},curry:function(e){if(arguments.length==1)return e;var t=s.call(arguments,1);return function(){return e.apply(null,t.concat(s.call(arguments)))}},parallel:function(e,t){var n=h.toArray(arguments),r=0,s=[],o=[];if(c.arr(e)&&e.length===0||c.fun(e)&&n.length===1)throw new TypeError("Empty parallel array");c.arr(e)||(t=n.pop(),e=n),f.each(e,function(n,u){n(function(){var n=h.toArray(arguments),a=n.shift();if(a)return t(a);s[u]=n,e.length==++r&&(s.unshift(i),f.each(s,function(e){o=o.concat(e)}),t.apply(i,o))})})},waterfall:function(e,t){var n=h.toArray(arguments),r=0;if(c.arr(e)&&e.length===0||c.fun(e)&&n.length===1)throw new TypeError("Empty waterfall array");c.arr(e)||(t=n.pop(),e=n),function s(){var n=h.toArray(arguments);n.push(s);var r=n.shift();!r&&e.length?e.shift().apply(i,n):(n.pop(),n.unshift(r),t.apply(i,n))}(i)},queue:function(e){return new p(c.arrLike(e)?e:h.toArray(arguments))}};return p.prototype.next=function(){return this.index<this.values.length&&this.values[this.index++](),this},v(d,f),v(d,h),d.is=c,d.v=d,d.each(d.extend({},f,h),function(e,t){m.prototype[e]=function(){var e=d.toArray(arguments);e.unshift(this.val);var n=t.apply(this._scope,e);return this.val=n,this._chained?this:n}}),v(m.prototype,{chain:function(){return this._chained=1,this},value:function(){return this.val}}),d.noConflict=function(){return e.v=t,this},d}) |
58483
1603
265