check-more-types
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "check-more-types", | ||
"main": "check-more-types.js", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"homepage": "https://github.com/kensho/check-more-types", | ||
@@ -18,3 +18,2 @@ "license": "MIT", | ||
], | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
"keywords": [ | ||
@@ -26,3 +25,7 @@ "types", | ||
"check-types" | ||
], | ||
"description": "Additional type checks for https://github.com/philbooth/check-types.js", | ||
"authors": [ | ||
"Gleb Bahmutov <gleb.bahmutov@gmail.com>" | ||
] | ||
} |
@@ -136,2 +136,12 @@ (function checkMoreTypes(check) { | ||
/** | ||
Returns true if each item in the array passes predicate | ||
@method arrayOf | ||
@param rule Predicate function | ||
@param a Array to check | ||
*/ | ||
function arrayOf(rule, a) { | ||
return check.array(a) && a.every(rule); | ||
} | ||
/** | ||
Returns true if given array only has strings | ||
@@ -452,3 +462,4 @@ @method arrayOfStrings | ||
index: index, | ||
git: git | ||
git: git, | ||
arrayOf: arrayOf | ||
}; | ||
@@ -455,0 +466,0 @@ |
@@ -1,5 +0,5 @@ | ||
/*! check-more-types - v1.1.1 | ||
/*! check-more-types - v1.2.0 | ||
homepage: https://github.com/kensho/check-more-types | ||
Copyright @ 2014 Kensho license: MIT */ | ||
!function(a){"use strict";function b(a){return"undefined"!=typeof a}function c(a,b){return a===b}function d(a,c){return b(a)&&j(a,"length")&&c>=0&&c<a.length}function e(a,b){return typeof a==typeof b&&a&&b&&a.length===b.length}function f(b){if(!a.array(b))return!1;if(!b.length)return!0;var c=b[0];return b.every(function(a){return a===c})}function g(b){return a.unemptyString(b)&&/^git@/.test(b)}function h(a){return 0===a||1===a}function i(a){return"boolean"==typeof a}function j(a,b){return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function k(b){return a.string(b)&&b.toLowerCase()===b}function l(b){return a.array(b)&&b.length>0}function m(b,c){var d=a.array(b)&&b.every(a.string);return d&&a.bool(c)&&c?b.every(a.lowerCase):d}function n(b,c){return a.array(b)&&b.every(function(b){return a.arrayOfStrings(b,c)})}function o(b,c){return a.verify.object(b,"missing object to check"),a.verify.object(c,"missing predicates object"),Object.keys(c).forEach(function(b){a.verify.fn(c[b],"not a predicate function for "+b)}),a.every(a.map(b,c))}function p(a,b){return o(b,a)}function q(b,c){a.verify.fn(b,"expected function that raises");try{b()}catch(d){return"undefined"==typeof c?!0:"function"==typeof c?c(d):!1}return!1}function r(a){return""===a}function s(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function t(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function u(b){return a.number(b)&&b>=0&&1>=b}function v(b){return a.string(b)&&y.test(b)}function w(b){return a.string(b)&&40===b.length&&z.test(b)}function x(b){return a.string(b)&&7===b.length&&A.test(b)}if(!a){if("undefined"==typeof require)throw new Error("Cannot find check-types library, has it been loaded?");a=require("check-types")}var y=/^#(?:[0-9a-fA-F]{3}){1,2}$/,z=/^[0-9a-f]{40}$/,A=/^[0-9a-f]{7}$/;if(!a.defend){var B=function(b,c,d){a.verify.fn(b,"expected a function"),a.verify.array(c,"expected list of predicates"),a.verify.defined(d,"missing args");var e=0,f=0,g=c.length;for(e=0;g>e;e+=1){var h=c[e];if(a.fn(h)){if(!h.call(null,d[f])){var i="Argument "+(f+1)+": "+d[f]+" does not pass predicate";throw a.unemptyString(c[e+1])&&(i+=": "+c[e+1]),new Error(i)}f+=1}}return b.apply(null,d)};a.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return B(a,b,arguments)}}}a.mixin||(a.mixin=function(b,c){function d(b,c,d){a.verify.object(b,"missing object"),a.verify.unemptyString(c,"missing name"),a.verify.fn(d,"missing function"),b[c]||(b[c]=d)}function e(b){return function(){return!a.defined(arguments[0])||a.nulled(arguments[0])?!0:b.apply(null,arguments)}}function f(a){return function(){return!a.apply(null,arguments)}}function g(b,c){return function(){var d;if(b.apply(null,arguments)===!1)throw d=arguments[arguments.length-1],new Error(a.unemptyString(d)?d:c)}}a.verify.fn(b,"expected predicate function"),a.unemptyString(c)||(c=b.name),a.verify.unemptyString(c,"predicate function missing name\n"+b.toString()),d(a,c,b),d(a.maybe,c,e(b)),d(a.not,c,f(b)),d(a.verify,c,g(b,c+" failed"))}),a.then||(a.then=function(a,b){return function(){var c="function"==typeof a?a.apply(null,arguments):a;return c?b.apply(null,arguments):void 0}});var C={defined:b,same:c,allSame:f,bit:h,bool:i,has:j,lowerCase:k,unemptyArray:l,arrayOfStrings:m,arrayOfArraysOfStrings:n,all:o,schema:p,raises:q,empty:s,emptyString:r,unempty:t,unit:u,hexRgb:v,sameLength:e,commitId:w,shortCommitId:x,index:d,git:g};Object.keys(C).forEach(function(b){a.mixin(C[b],b)}),"object"==typeof module&&(module.exports=a)}("object"==typeof window?window.check:global.check); | ||
!function(a){"use strict";function b(a){return"undefined"!=typeof a}function c(a,b){return a===b}function d(a,c){return b(a)&&j(a,"length")&&c>=0&&c<a.length}function e(a,b){return typeof a==typeof b&&a&&b&&a.length===b.length}function f(b){if(!a.array(b))return!1;if(!b.length)return!0;var c=b[0];return b.every(function(a){return a===c})}function g(b){return a.unemptyString(b)&&/^git@/.test(b)}function h(a){return 0===a||1===a}function i(a){return"boolean"==typeof a}function j(a,b){return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function k(b){return a.string(b)&&b.toLowerCase()===b}function l(b){return a.array(b)&&b.length>0}function m(b,c){return a.array(c)&&c.every(b)}function n(b,c){var d=a.array(b)&&b.every(a.string);return d&&a.bool(c)&&c?b.every(a.lowerCase):d}function o(b,c){return a.array(b)&&b.every(function(b){return a.arrayOfStrings(b,c)})}function p(b,c){return a.verify.object(b,"missing object to check"),a.verify.object(c,"missing predicates object"),Object.keys(c).forEach(function(b){a.verify.fn(c[b],"not a predicate function for "+b)}),a.every(a.map(b,c))}function q(a,b){return p(b,a)}function r(b,c){a.verify.fn(b,"expected function that raises");try{b()}catch(d){return"undefined"==typeof c?!0:"function"==typeof c?c(d):!1}return!1}function s(a){return""===a}function t(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function u(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function v(b){return a.number(b)&&b>=0&&1>=b}function w(b){return a.string(b)&&z.test(b)}function x(b){return a.string(b)&&40===b.length&&A.test(b)}function y(b){return a.string(b)&&7===b.length&&B.test(b)}if(!a){if("undefined"==typeof require)throw new Error("Cannot find check-types library, has it been loaded?");a=require("check-types")}var z=/^#(?:[0-9a-fA-F]{3}){1,2}$/,A=/^[0-9a-f]{40}$/,B=/^[0-9a-f]{7}$/;if(!a.defend){var C=function(b,c,d){a.verify.fn(b,"expected a function"),a.verify.array(c,"expected list of predicates"),a.verify.defined(d,"missing args");var e=0,f=0,g=c.length;for(e=0;g>e;e+=1){var h=c[e];if(a.fn(h)){if(!h.call(null,d[f])){var i="Argument "+(f+1)+": "+d[f]+" does not pass predicate";throw a.unemptyString(c[e+1])&&(i+=": "+c[e+1]),new Error(i)}f+=1}}return b.apply(null,d)};a.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return C(a,b,arguments)}}}a.mixin||(a.mixin=function(b,c){function d(b,c,d){a.verify.object(b,"missing object"),a.verify.unemptyString(c,"missing name"),a.verify.fn(d,"missing function"),b[c]||(b[c]=d)}function e(b){return function(){return!a.defined(arguments[0])||a.nulled(arguments[0])?!0:b.apply(null,arguments)}}function f(a){return function(){return!a.apply(null,arguments)}}function g(b,c){return function(){var d;if(b.apply(null,arguments)===!1)throw d=arguments[arguments.length-1],new Error(a.unemptyString(d)?d:c)}}a.verify.fn(b,"expected predicate function"),a.unemptyString(c)||(c=b.name),a.verify.unemptyString(c,"predicate function missing name\n"+b.toString()),d(a,c,b),d(a.maybe,c,e(b)),d(a.not,c,f(b)),d(a.verify,c,g(b,c+" failed"))}),a.then||(a.then=function(a,b){return function(){var c="function"==typeof a?a.apply(null,arguments):a;return c?b.apply(null,arguments):void 0}});var D={defined:b,same:c,allSame:f,bit:h,bool:i,has:j,lowerCase:k,unemptyArray:l,arrayOfStrings:n,arrayOfArraysOfStrings:o,all:p,schema:q,raises:r,empty:t,emptyString:s,unempty:u,unit:v,hexRgb:w,sameLength:e,commitId:x,shortCommitId:y,index:d,git:g,arrayOf:m};Object.keys(D).forEach(function(b){a.mixin(D[b],b)}),"object"==typeof module&&(module.exports=a)}("object"==typeof window?window.check:global.check); |
@@ -162,2 +162,22 @@ ### check.defined | ||
### check.arrayOf | ||
```js | ||
check.arrayOf(check.unemptyString, ['foo', '']); // false | ||
check.arrayOf(check.unemptyString, ['foo', 'bar']); // true | ||
// can be partially applied and combined with check.schema | ||
var person = { | ||
first: check.unemptyString, | ||
last: check.unemptyString | ||
}; | ||
var isPerson = check.schema.bind(null, person); | ||
var arePeople = check.arrayOf.bind(null, isPerson); | ||
var people = [{ | ||
first: 'foo', | ||
last: 'bar' | ||
}]; | ||
arePeople(people); // true | ||
``` | ||
--- | ||
### check.arrayOfArraysOfStrings | ||
@@ -164,0 +184,0 @@ |
{ | ||
"name": "check-more-types", | ||
"description": "Additional type checks for https://github.com/philbooth/check-types.js", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>", | ||
@@ -12,11 +12,11 @@ "bugs": { | ||
"coveralls": "2.11.2", | ||
"grunt-contrib-jshint": "0.10.0", | ||
"grunt-contrib-uglify": "0.6.0", | ||
"grunt-contrib-jshint": "0.11.0", | ||
"grunt-contrib-uglify": "0.7.0", | ||
"grunt-contrib-watch": "0.6.1", | ||
"grunt-deps-ok": "0.5.1", | ||
"grunt-deps-ok": "0.5.2", | ||
"grunt-gt": "0.1.4", | ||
"grunt-jshint-solid": "0.1.0", | ||
"grunt-mocha-test": "0.12.4", | ||
"grunt-mocha-test": "0.12.7", | ||
"grunt-nice-package": "0.9.2", | ||
"grunt-npm2bower-sync": "0.4.0", | ||
"grunt-npm2bower-sync": "0.8.1", | ||
"grunt-readme": "0.4.5", | ||
@@ -26,5 +26,5 @@ "grunt-toc": "0.1.0", | ||
"lazy-ass": "0.5.3", | ||
"lazy-ass-helpful": "0.6.0", | ||
"lazy-ass-helpful": "0.6.1", | ||
"lcov-filter": "0.0.1", | ||
"lodash": "2.4.1", | ||
"lodash": "3.1.0", | ||
"matchdep": "0.3.0", | ||
@@ -46,3 +46,6 @@ "pre-git": "0.1.1" | ||
"main": "check-more-types.js", | ||
"pre-commit": "npm test", | ||
"pre-commit": [ | ||
"npm test", | ||
"npm version" | ||
], | ||
"repository": { | ||
@@ -49,0 +52,0 @@ "type": "git", |
@@ -1,2 +0,2 @@ | ||
# check-more-types v1.1.1 | ||
# check-more-types v1.2.0 | ||
@@ -68,2 +68,3 @@ > Additional type checks for [check-types.js](https://github.com/philbooth/check-types.js) | ||
* [check.arrayOfStrings](#checkarrayofstrings) | ||
* [check.arrayOf](#checkarrayof) | ||
* [check.arrayOfArraysOfStrings](#checkarrayofarraysofstrings) | ||
@@ -254,2 +255,22 @@ * [check.lowerCase](#checklowercase) | ||
#### check.arrayOf | ||
```js | ||
check.arrayOf(check.unemptyString, ['foo', '']); // false | ||
check.arrayOf(check.unemptyString, ['foo', 'bar']); // true | ||
// can be partially applied and combined with check.schema | ||
var person = { | ||
first: check.unemptyString, | ||
last: check.unemptyString | ||
}; | ||
var isPerson = check.schema.bind(null, person); | ||
var arePeople = check.arrayOf.bind(null, isPerson); | ||
var people = [{ | ||
first: 'foo', | ||
last: 'bar' | ||
}]; | ||
arePeople(people); // true | ||
``` | ||
--- | ||
#### check.arrayOfArraysOfStrings | ||
@@ -256,0 +277,0 @@ |
@@ -16,2 +16,31 @@ /* global describe, la, check, it, beforeEach */ | ||
describe('check/arrayOf', function () { | ||
it('validates array of strings', function () { | ||
la(check.arrayOf(check.string, ['foo', ''])); | ||
}); | ||
it('validates array of empty strings', function () { | ||
la(!check.arrayOf(check.unemptyString, ['foo', ''])); | ||
la(check.arrayOf(check.unemptyString, ['foo', 'bar'])); | ||
}); | ||
it('validates array of positive numbers', function () { | ||
la(check.arrayOf(check.positiveNumber, [10, 20, 30])); | ||
}); | ||
it('validates schema for objects', function () { | ||
var person = { | ||
first: check.unemptyString, | ||
last: check.unemptyString | ||
}; | ||
var isPerson = check.schema.bind(null, person); | ||
var arePeople = check.arrayOf.bind(null, isPerson); | ||
var people = [{ | ||
first: 'foo', | ||
last: 'bar' | ||
}]; | ||
la(arePeople(people), 'checked people'); | ||
}); | ||
}); | ||
describe('check/shortCommitId', function () { | ||
@@ -18,0 +47,0 @@ /** @sample check/shortCommitId */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332435
1571
629