check-more-types
Advanced tools
Comparing version 0.0.0 to 0.1.1
@@ -11,2 +11,8 @@ # {%= name %} v{%= version %} | ||
global.check = requier('check-types'); | ||
require('check-more-types'); | ||
// patches global check object | ||
**browser** include {%= name %} after including *check-types.js* | ||
{%= _.doc("./docs/use.md") %} | ||
@@ -13,0 +19,0 @@ |
@@ -14,2 +14,14 @@ module.exports = function(grunt) { | ||
xplain: { | ||
options: { | ||
framework: 'jasmine' | ||
}, | ||
toMarkdown: { | ||
options: { | ||
output: 'docs/use.md' | ||
}, | ||
src: ['test/*-spec.js'] | ||
} | ||
}, | ||
readme: { | ||
@@ -47,4 +59,5 @@ options: { | ||
grunt.registerTask('test', ['mochaTest']); | ||
grunt.registerTask('doc', ['xplain', 'readme']); | ||
grunt.registerTask('default', | ||
['nice-package', 'deps-ok', 'jshint', 'test', 'readme']); | ||
['nice-package', 'deps-ok', 'jshint', 'test', 'doc']); | ||
}; |
{ | ||
"name": "check-more-types", | ||
"description": "Additional type checks for https://github.com/philbooth/check-types.js", | ||
"version": "0.0.0", | ||
"version": "0.1.1", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -18,2 +18,3 @@ "bugs": { | ||
"grunt-readme": "0.4.5", | ||
"grunt-xplain": "0.2.4", | ||
"lazy-ass": "0.5.1", | ||
@@ -40,3 +41,3 @@ "lazy-ass-helpful": "0.5.0", | ||
"type": "git", | ||
"url": "git@bitbucket.org:gleb_bahmutov/check-more-types.git" | ||
"url": "git@github.com:kensho/check-more-types.git" | ||
}, | ||
@@ -43,0 +44,0 @@ "scripts": { |
100
README.md
@@ -1,2 +0,2 @@ | ||
# check-more-types v0.0.0 | ||
# check-more-types v0.1.1 | ||
@@ -26,5 +26,103 @@ > Additional type checks for [check-types.js](https://github.com/philbooth/check-types.js) | ||
global.check = requier('check-types'); | ||
require('check-more-types'); | ||
// patches global check object | ||
**browser** include check-more-types after including *check-types.js* | ||
## API | ||
#### check.defined | ||
check.defined(0); // true | ||
check.defined(1); // true | ||
check.defined(true); // true | ||
check.defined(false); // true | ||
check.defined(null); // true | ||
check.defined(''); // true | ||
check.defined(); // false | ||
check.defined(root.does_not_exist); // false | ||
check.defined({}.does_not_exist); // false | ||
--- | ||
#### check.bit | ||
check.bit(0); // true | ||
check.bit(1); // true | ||
check.bit('1'); // false | ||
check.bit(2); // false | ||
check.bit(true); // false | ||
--- | ||
#### check.unemptyArray | ||
check.unemptyArray(null); // false | ||
check.unemptyArray(1); // false | ||
check.unemptyArray({}); // false | ||
check.unemptyArray([]); // false | ||
check.unemptyArray(root.does_not_exist); // false | ||
check.unemptyArray([1]); // true | ||
check.unemptyArray(['foo', 'bar']); // true | ||
--- | ||
#### check.arrayOfStrings | ||
// second argument is checkLowerCase | ||
check.arrayOfStrings(['foo', 'Foo']); // true | ||
check.arrayOfStrings(['foo', 'Foo'], true); // false | ||
check.arrayOfStrings(['foo', 'bar'], true); // true | ||
check.arrayOfStrings(['FOO', 'BAR'], true); // false | ||
--- | ||
#### check.arrayOfArraysOfStrings | ||
// second argument is checkLowerCase | ||
check.arrayOfArraysOfStrings([['foo'], ['bar'}}); // true | ||
check.arrayOfArraysOfStrings([['foo'], ['bar'}}, true); // true | ||
check.arrayOfArraysOfStrings([['foo'], ['BAR'}}, true); // false | ||
--- | ||
#### check.lowerCase | ||
check.lowerCase('foo bar'); // true | ||
check.lowerCase('*foo ^bar'); // true | ||
check.lowerCase('fooBar'); // false | ||
--- | ||
#### check.has | ||
var obj = { | ||
foo: 'foo', | ||
bar: 0 | ||
}; | ||
check.has(obj, 'foo'); // true | ||
check.has(obj, 'bar'); // true | ||
check.has(obj, 'baz'); // false | ||
--- | ||
#### check.all | ||
var obj = { | ||
foo: 'foo', | ||
bar: 'bar', | ||
baz: 'baz' | ||
}; | ||
var predicates = { | ||
foo: check.unemptyString, | ||
bar: function(value) { | ||
return value === 'bar'; | ||
} | ||
}; | ||
check.all(obj, predicates); // true | ||
--- | ||
### Small print | ||
@@ -31,0 +129,0 @@ |
@@ -64,2 +64,13 @@ require('lazy-ass'); | ||
it('check.defined', function () { | ||
la(check.defined(0)); | ||
la(check.defined(1)); | ||
la(check.defined(true)); | ||
la(check.defined(false)); | ||
la(check.defined(null)); | ||
la(check.defined('')); | ||
la(!check.defined()); | ||
la(!check.defined(root.does_not_exist)); | ||
la(!check.defined({}.does_not_exist)); | ||
}); | ||
}); | ||
@@ -90,2 +101,10 @@ | ||
}); | ||
it('check.bit', function () { | ||
la(check.bit(0)); | ||
la(check.bit(1)); | ||
la(!check.bit('1')); | ||
la(!check.bit(2)); | ||
la(!check.bit(true)); | ||
}); | ||
}); | ||
@@ -97,3 +116,3 @@ | ||
/** @sample check/defined */ | ||
it('detects unempty array or not', function () { | ||
it('check.unemptyArray', function () { | ||
la(!check.unemptyArray(null)); | ||
@@ -166,2 +185,17 @@ la(!check.unemptyArray(1)); | ||
describe('check.all partial', function () { | ||
it('check.all', function () { | ||
var obj = { | ||
foo: 'foo', | ||
bar: 'bar', | ||
baz: 'baz' | ||
}; | ||
var predicates = { | ||
foo: check.unemptyString, | ||
bar: function (value) { | ||
return value === 'bar'; | ||
} | ||
}; | ||
la(check.all(obj, predicates)); | ||
}); | ||
/** @sample check/all */ | ||
@@ -213,2 +247,10 @@ it('checks an object', function () { | ||
it('check.arrayOfStrings', function () { | ||
// second argument is checkLowerCase | ||
la(check.arrayOfStrings(['foo', 'Foo'])); | ||
la(!check.arrayOfStrings(['foo', 'Foo'], true)); | ||
la(check.arrayOfStrings(['foo', 'bar'], true)); | ||
la(!check.arrayOfStrings(['FOO', 'BAR'], true)); | ||
}); | ||
it('checks if strings are lower case', function () { | ||
@@ -263,2 +305,9 @@ la(check.arrayOfStrings(['foo', 'Foo'])); | ||
it('check.arrayOfArraysOfStrings', function () { | ||
// second argument is checkLowerCase | ||
la(check.arrayOfArraysOfStrings([['foo'], ['bar']])); | ||
la(check.arrayOfArraysOfStrings([['foo'], ['bar']], true)); | ||
la(!check.arrayOfArraysOfStrings([['foo'], ['BAR']], true)); | ||
}); | ||
/** @sample check/arrayOfArraysOfStrings */ | ||
@@ -307,2 +356,8 @@ it('checks if all strings are lower case', function () { | ||
describe('lowerCase', function () { | ||
it('check.lowerCase', function () { | ||
la(check.lowerCase('foo bar')); | ||
la(check.lowerCase('*foo ^bar')); | ||
la(!check.lowerCase('fooBar')); | ||
}); | ||
/** @sample check/lowerCase */ | ||
@@ -352,4 +407,3 @@ it('checks lower case', function () { | ||
describe('has', function () { | ||
/** @sample check/has */ | ||
it('checks property presense', function () { | ||
it('check.has', function () { | ||
var obj = { | ||
@@ -356,0 +410,0 @@ foo: 'foo', |
30867
602
164
13