From 0acfe32797767966dff349e5b2c1058d4e96af7e Mon Sep 17 00:00:00 2001 From: Dustin Diaz Date: Mon, 10 Jun 2013 16:48:18 -0700 Subject: [PATCH] new (nicer looking) aliases for type checking bump to 1.6.1 --- README.md | 15 ++++++------ package.json | 2 +- src/valentine.js | 10 ++++++++ tests/tests.js | 60 ++++++++++++++++++++++++------------------------ valentine.js | 10 ++++++++ valentine.min.js | 2 +- 6 files changed, 60 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index b37a1f0..00cdfd1 100644 --- a/README.md +++ b/README.md @@ -168,19 +168,20 @@ it.next()

type checking

Each method returns a boolean - * 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) * v.is.num(o) * v.is.bool(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) Object Style diff --git a/package.json b/package.json index 6859fde..49f6b0f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "valentine" , "description": "JavaScripts Functional Sister. Utilitiy, Iterators, type checking" - , "version": "1.6.0" + , "version": "1.6.1" , "homepage": "https://github.com/ded/valentine" , "author": "Dustin Diaz (http://dustindiaz.com)" , "keywords": ["ender", "functional", "iteration", "type checking", "base"] diff --git a/src/valentine.js b/src/valentine.js index 2570b6f..8299edf 100644 --- a/src/valentine.js +++ b/src/valentine.js @@ -319,6 +319,16 @@ } } + // 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 = { each: function (a, fn, scope) { is.arrLike(a) ? diff --git a/tests/tests.js b/tests/tests.js index 39ab892..aef859e 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -524,25 +524,25 @@ sink('Utility', function (test, ok, b, a, assert) { sink('Type Checking', function (test, ok) { 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') }) test('Number', 3, function () { @@ -567,21 +567,21 @@ sink('Type Checking', function (test, ok) { }) 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")') }) test('Null', 3, function () { @@ -591,9 +591,9 @@ sink('Type Checking', function (test, ok) { }) 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') }) test('Object', 4, function () { @@ -605,11 +605,11 @@ sink('Type Checking', function (test, ok) { if (typeof window !== 'undefined' && window.document) { 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()') }) } diff --git a/valentine.js b/valentine.js index 2cafb70..cf01278 100644 --- a/valentine.js +++ b/valentine.js @@ -326,6 +326,16 @@ } } + // 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 = { each: function (a, fn, scope) { is.arrLike(a) ? diff --git a/valentine.min.js b/valentine.min.js index e45c703..9c86b0c 100644 --- a/valentine.min.js +++ b/valentine.min.js @@ -4,4 +4,4 @@ * https://github.com/ded/valentine * License MIT */ -(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;re.length?e.length:n;for(var r=n;r=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=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;i2?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.indexe.length?e.length:n;for(var r=n;r=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=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;i2?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