Skip to content

Commit

Permalink
new (nicer looking) aliases for type checking
Browse files Browse the repository at this point in the history
bump to 1.6.1
  • Loading branch information
ded committed Jun 10, 2013
1 parent 1f6958f commit 0acfe32
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 39 deletions.
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -168,19 +168,20 @@ it.next()
<h3>type checking</h3>
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
Expand Down
2 changes: 1 addition & 1 deletion 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 <dustin@dustindiaz.com> (http://dustindiaz.com)"
, "keywords": ["ender", "functional", "iteration", "type checking", "base"]
Expand Down
10 changes: 10 additions & 0 deletions src/valentine.js
Expand Up @@ -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) ?
Expand Down
60 changes: 30 additions & 30 deletions tests/tests.js
Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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 () {
Expand All @@ -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()')
})
}

Expand Down
10 changes: 10 additions & 0 deletions valentine.js
Expand Up @@ -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) ?
Expand Down
2 changes: 1 addition & 1 deletion valentine.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0acfe32

Please sign in to comment.