From 57a7a20af7dea26913f2bbf75ee5c9dd7dd1fbe6 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 6 Apr 2016 13:45:33 -0400 Subject: [PATCH] feat(odd): added even and odd methods, closes #66 --- README.md | 11 +++++++++++ dist/check-more-types.js | 34 +++++++++++++++++++++++++++------- dist/check-more-types.min.js | 2 +- docs/use.md | 10 ++++++++++ src/mid-level-spec.js | 28 ++++++++++++++++++++++++++++ src/mid-level.js | 34 +++++++++++++++++++++++++++------- 6 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 src/mid-level-spec.js diff --git a/README.md b/README.md index a1f8b2a..1142c82 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ for advice and examples. * **API** * [check.email](#checkemail) + * [check.odd and check.even](#checkodd-and-checkeven) * [check.port](#checkport) * [check.systemPort](#checksystemport) * [check.userPort](#checkuserport) @@ -137,6 +138,16 @@ check.email('me@foo.bar') // true check.email('me.foo.bar') // false ``` +#### check.odd and check.even + +Check if a number odd or even + +```js +check.odd(2) // false +check.odd(3) // true +check.even(2) // true +``` + #### check.port Returns true if passed argument is positive number less or equal to largest diff --git a/dist/check-more-types.js b/dist/check-more-types.js index b5bd149..d1dc4af 100644 --- a/dist/check-more-types.js +++ b/dist/check-more-types.js @@ -535,6 +535,24 @@ return /******/ (function(modules) { // webpackBootstrap x.indexOf(prefix) === 0 } + /** + Checks if given number is even + + @method even + */ + function even (n) { + return n % 2 === 0 + } + + /** + Checks if given number is odd + + @method odd + */ + function odd (n) { + return n % 2 === 1 + } + /** Checks if the given item is the given {arrya, string} @@ -656,17 +674,19 @@ return /******/ (function(modules) { // webpackBootstrap } module.exports = { - found: found, - startsWith: startsWith, + allSame: allSame, contains: contains, - type: curry2(type), + even: even, + found: found, + hexRgb: hexRgb, index: index, + odd: odd, oneOf: curry2(oneOf, true), + raises: raises, sameLength: sameLength, - allSame: allSame, - unit: unit, - hexRgb: hexRgb, - raises: raises + startsWith: startsWith, + type: curry2(type), + unit: unit } diff --git a/dist/check-more-types.min.js b/dist/check-more-types.min.js index bb8f36a..d72b5a3 100644 --- a/dist/check-more-types.min.js +++ b/dist/check-more-types.min.js @@ -2,4 +2,4 @@ homepage: https://github.com/kensho/check-more-types Copyright @ 2014 Kensho license: MIT */ -!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.check=b():a.check=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){"use strict";function d(a){return m.object(a)&&p(a)}function e(a){Object.keys(a).forEach(function(b){m.mixin(a[b],b)})}if("function"!=typeof Function.prototype.bind)throw new Error("Missing Function.prototype.bind, please load es5-shim first");var f=c(1),g=c(3),h=c(5),i=c(6),j=c(7),k=c(8),l=c(9),m={maybe:{},verify:{},not:{},every:i.every,map:i.map};if(!m.defend){var n=function(a,b,c){m.verify.fn(a,"expected a function"),m.verify.array(b,"expected list of predicates"),m.verify.defined(c,"missing args");var d=0,e=0,g=b.length;for(d=0;g>d;d+=1){var h=b[d];if(m.fn(h)){if(!h(c[e])){var i="Argument "+(e+1)+": "+c[e]+" does not pass predicate";throw f.unemptyString(b[d+1])&&(i+=": "+b[d+1]),new Error(i)}e+=1}}return a.apply(null,c)};m.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return n(a,b,arguments)}}}m.mixin||(m.mixin=function(a,b){function d(a,b,c){if(!f.object(a))throw new Error("missing object "+a);if(!f.unemptyString(b))throw new Error("missing name");if(!f.fn(c))throw new Error("missing function");a[b]||(a[b]=c)}function e(a){return function(){return!m.defined(arguments[0])||m.nulled(arguments[0])?!0:a.apply(null,arguments)}}if(f.string(a)&&f.fn(b)){var g=a;a=b,b=g}if(!f.fn(a))throw new Error("expected predicate function for name "+b);if(f.unemptyString(b)||(b=a.name),!f.unemptyString(b))throw new Error("predicate function missing name\n"+a.toString());var h=c(4);d(m,b,a),d(m.maybe,b,e(a)),d(m.not,b,i.notModifier(a)),d(m.verify,b,h(a,b+" failed"))}),m.then||(m.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 o={then:f.fn};o["catch"]=f.fn;var p=l.schema.bind(null,o),q={array:Array.isArray,promise:d};[f,g,q,j,k,h,i,l].forEach(e),m.VERSION="{{ packageVersion }}",a.exports=m},function(a,b,c){"use strict";function d(a){return"function"==typeof a}function e(a){return"string"==typeof a}function f(a){return e(a)&&Boolean(a)}function g(a){return"object"==typeof a&&!H(a)&&!l(a)&&!o(a)}function h(a){return g(a)&&0===Object.keys(a).length}function i(a){return"number"==typeof a&&!isNaN(a)&&a!==1/0&&a!==-(1/0)}function j(a){return i(a)&&a%1===0}function k(a){return i(a)&&a%1!==0}function l(a){return null===a}function m(a){return i(a)&&a>0}function n(a){return i(a)&&0>a}function o(a){return a instanceof Date}function p(a){return a instanceof RegExp}function q(a){return a instanceof Error}function r(a,b){return a instanceof b}function s(a,b){return"number"==typeof a&&"number"!=typeof b?s(b,a):(H(a)||e(a))&&a.length===b}function t(a){return"undefined"!=typeof a}function u(a){return o(a)&&i(Number(a))}function v(a){var b=typeof a;return"number"===b||"boolean"===b||"string"===b||"symbol"===b}function w(a){return"number"==typeof a&&0===a}function x(a,b){return a===b}function y(a){return 0===a||1===a}function z(a){return"boolean"==typeof a}function A(a){return e(a)&&a.toLowerCase()===a}function B(a,b){if(2!==arguments.length)throw new Error("Expected two arguments to check.has, got only "+arguments.length);return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function C(a){return""===a}function D(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function E(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function F(a,b){return a===b}var G=c(2).curry2,H=Array.isArray;a.exports={bit:y,bool:z,date:o,defined:t,empty:D,emptyObject:h,emptyString:C,equal:G(F),error:q,floatNumber:k,fn:d,has:B,instance:r,intNumber:j,isArray:H,length:G(s),lowerCase:A,negative:n,negativeNumber:n,nulled:l,number:i,object:g,positive:m,positiveNumber:m,primitive:v,regexp:p,same:x,string:e,unempty:E,unemptyString:f,validDate:u,zero:w}},function(a,b){"use strict";function c(a,b){return function(c){if(b&&arguments.length>2)throw new Error("Curry2 function "+a.name+" called with too many arguments "+arguments.length);return 2===arguments.length?a(arguments[0],arguments[1]):function(b){return a(c,b)}}}a.exports={curry2:c}},function(a,b,c){"use strict";function d(a){return a>=0}function e(a,b){return o.string(a)&&o.string(b)&&0===b.indexOf(a)}function f(a,b){if(Array.isArray(a))return-1!==a.indexOf(b);if("string"==typeof a){if("string"!=typeof b)throw new Error("Contains in string should search for string also "+b);return-1!==a.indexOf(b)}return!1}function g(a,b){return typeof b===a}function h(a,b){return o.defined(a)&&o.has(a,"length")&&b>=0&&b=0&&1>=a}function m(a){return o.string(a)&&r.test(a)}function n(a,b){p(o.fn(a),"expected function that raises");try{a()}catch(c){return"undefined"==typeof b?!0:"function"==typeof b?b(c):!1}return!1}var o=c(1),p=c(4),q=c(2).curry2,r=/^#(?:[0-9a-fA-F]{3}){1,2}$/;a.exports={found:d,startsWith:e,contains:f,type:q(g),index:h,oneOf:q(k,!0),sameLength:i,allSame:j,unit:l,hexRgb:m,raises:n}},function(a,b,c){"use strict";function d(a,b){return function(){var c;if(a.apply(null,arguments)===!1)throw c=arguments[arguments.length-1],new Error(e.unemptyString(c)?c:b)}}var e=c(1);a.exports=d},function(a,b,c){"use strict";function d(a){return i.isArray(a)&&a.length>0}function e(a,b){return i.isArray(b)&&b.every(a)}function f(a,b){if(!i.isArray(b))throw new Error("expected array to find bad items");return b.filter(j.notModifier(a))}function g(a,b){var c=i.isArray(a)&&a.every(i.string);return c&&i.bool(b)&&b?a.every(i.lowerCase):c}function h(a,b){return i.isArray(a)&&a.every(function(a){return g(a,b)})}var i=c(1),j=c(6),k=c(4);k(i.fn(i.isArray),"missing low level isArray"),a.exports={arrayOf:e,arrayOfArraysOfStrings:h,arrayOfStrings:g,badItems:f,unemptyArray:d}},function(a,b,c){"use strict";function d(){var a=Array.prototype.slice.call(arguments,0);if(!a.length)throw new Error("empty list of arguments to or");return function(){var b=Array.prototype.slice.call(arguments,0);return a.some(function(a){try{return i.fn(a)?a.apply(null,b):Boolean(a)}catch(c){return!1}})}}function e(){var a=Array.prototype.slice.call(arguments,0);if(!a.length)throw new Error("empty list of arguments to or");return function(){var b=Array.prototype.slice.call(arguments,0);return a.every(function(a){return i.fn(a)?a.apply(null,b):Boolean(a)})}}function f(a){return function(){return!a.apply(null,arguments)}}function g(a){var b,c;for(b in a)if(a.hasOwnProperty(b)){if(c=a[b],i.object(c)&&g(c)===!1)return!1;if(c===!1)return!1}return!0}function h(a,b){var c,d,e={};for(c in b)b.hasOwnProperty(c)&&(d=b[c],i.fn(d)?e[c]=d(a[c]):i.object(d)&&(e[c]=h(a[c],d)));return e}var i=c(1);a.exports={or:d,and:e,notModifier:f,every:g,map:h}},function(a,b,c){"use strict";function d(a){return h.unemptyString(a)&&/^\d+\.\d+\.\d+$/.test(a)}function e(a){return h.unemptyString(a)&&/^git@/.test(a)}function f(a){return h.string(a)&&40===a.length&&i.test(a)}function g(a){return h.string(a)&&7===a.length&&j.test(a)}var h=c(1),i=/^[0-9a-f]{40}$/,j=/^[0-9a-f]{7}$/;a.exports={semver:d,git:e,commitId:f,shortCommitId:g}},function(a,b,c){"use strict";function d(a){return k.string(a)&&m(a)}function e(a){return k.string(a)&&n(a)}function f(a){return k.string(a)&&(m(a)||n(a))}function g(a){return k.positiveNumber(a)&&65535>=a}function h(a){return k.positiveNumber(a)&&1024>=a}function i(a){return g(a)&&a>1024}function j(a){return k.string(a)&&/^.+@.+\..+$/.test(a)}var k=c(1),l=c(3),m=l.startsWith.bind(null,"http://"),n=l.startsWith.bind(null,"https://");a.exports={email:j,http:d,https:e,port:g,secure:e,systemPort:h,url:f,userPort:i,webUrl:f}},function(a,b,c){"use strict";function d(a,b){return h(g.object(a),"missing object to check"),h(g.object(b),"missing predicates object"),Object.keys(b).forEach(function(a){if(!g.fn(b[a]))throw new Error("not a predicate function for "+a+" but "+b[a])}),i(j(a,b))}function e(a,b){return d(b,a)}var f=c(2).curry2,g=c(1),h=c(4),i=c(6).every,j=c(6).map;h(g.fn(i),"missing check.every method"),h(g.fn(j),"missing check.map method"),a.exports={all:d,schema:f(e)}}])}); \ No newline at end of file +!function(a,b){"object"==typeof exports&&"object"==typeof module?module.exports=b():"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?exports.check=b():a.check=b()}(this,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={exports:{},id:d,loaded:!1};return a[d].call(e.exports,e,e.exports,b),e.loaded=!0,e.exports}var c={};return b.m=a,b.c=c,b.p="",b(0)}([function(a,b,c){"use strict";function d(a){return m.object(a)&&p(a)}function e(a){Object.keys(a).forEach(function(b){m.mixin(a[b],b)})}if("function"!=typeof Function.prototype.bind)throw new Error("Missing Function.prototype.bind, please load es5-shim first");var f=c(1),g=c(3),h=c(5),i=c(6),j=c(7),k=c(8),l=c(9),m={maybe:{},verify:{},not:{},every:i.every,map:i.map};if(!m.defend){var n=function(a,b,c){m.verify.fn(a,"expected a function"),m.verify.array(b,"expected list of predicates"),m.verify.defined(c,"missing args");var d=0,e=0,g=b.length;for(d=0;g>d;d+=1){var h=b[d];if(m.fn(h)){if(!h(c[e])){var i="Argument "+(e+1)+": "+c[e]+" does not pass predicate";throw f.unemptyString(b[d+1])&&(i+=": "+b[d+1]),new Error(i)}e+=1}}return a.apply(null,c)};m.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return n(a,b,arguments)}}}m.mixin||(m.mixin=function(a,b){function d(a,b,c){if(!f.object(a))throw new Error("missing object "+a);if(!f.unemptyString(b))throw new Error("missing name");if(!f.fn(c))throw new Error("missing function");a[b]||(a[b]=c)}function e(a){return function(){return!m.defined(arguments[0])||m.nulled(arguments[0])?!0:a.apply(null,arguments)}}if(f.string(a)&&f.fn(b)){var g=a;a=b,b=g}if(!f.fn(a))throw new Error("expected predicate function for name "+b);if(f.unemptyString(b)||(b=a.name),!f.unemptyString(b))throw new Error("predicate function missing name\n"+a.toString());var h=c(4);d(m,b,a),d(m.maybe,b,e(a)),d(m.not,b,i.notModifier(a)),d(m.verify,b,h(a,b+" failed"))}),m.then||(m.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 o={then:f.fn};o["catch"]=f.fn;var p=l.schema.bind(null,o),q={array:Array.isArray,promise:d};[f,g,q,j,k,h,i,l].forEach(e),m.VERSION="{{ packageVersion }}",a.exports=m},function(a,b,c){"use strict";function d(a){return"function"==typeof a}function e(a){return"string"==typeof a}function f(a){return e(a)&&Boolean(a)}function g(a){return"object"==typeof a&&!H(a)&&!l(a)&&!o(a)}function h(a){return g(a)&&0===Object.keys(a).length}function i(a){return"number"==typeof a&&!isNaN(a)&&a!==1/0&&a!==-(1/0)}function j(a){return i(a)&&a%1===0}function k(a){return i(a)&&a%1!==0}function l(a){return null===a}function m(a){return i(a)&&a>0}function n(a){return i(a)&&0>a}function o(a){return a instanceof Date}function p(a){return a instanceof RegExp}function q(a){return a instanceof Error}function r(a,b){return a instanceof b}function s(a,b){return"number"==typeof a&&"number"!=typeof b?s(b,a):(H(a)||e(a))&&a.length===b}function t(a){return"undefined"!=typeof a}function u(a){return o(a)&&i(Number(a))}function v(a){var b=typeof a;return"number"===b||"boolean"===b||"string"===b||"symbol"===b}function w(a){return"number"==typeof a&&0===a}function x(a,b){return a===b}function y(a){return 0===a||1===a}function z(a){return"boolean"==typeof a}function A(a){return e(a)&&a.toLowerCase()===a}function B(a,b){if(2!==arguments.length)throw new Error("Expected two arguments to check.has, got only "+arguments.length);return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function C(a){return""===a}function D(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function E(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function F(a,b){return a===b}var G=c(2).curry2,H=Array.isArray;a.exports={bit:y,bool:z,date:o,defined:t,empty:D,emptyObject:h,emptyString:C,equal:G(F),error:q,floatNumber:k,fn:d,has:B,instance:r,intNumber:j,isArray:H,length:G(s),lowerCase:A,negative:n,negativeNumber:n,nulled:l,number:i,object:g,positive:m,positiveNumber:m,primitive:v,regexp:p,same:x,string:e,unempty:E,unemptyString:f,validDate:u,zero:w}},function(a,b){"use strict";function c(a,b){return function(c){if(b&&arguments.length>2)throw new Error("Curry2 function "+a.name+" called with too many arguments "+arguments.length);return 2===arguments.length?a(arguments[0],arguments[1]):function(b){return a(c,b)}}}a.exports={curry2:c}},function(a,b,c){"use strict";function d(a){return a>=0}function e(a,b){return q.string(a)&&q.string(b)&&0===b.indexOf(a)}function f(a){return a%2===0}function g(a){return a%2===1}function h(a,b){if(Array.isArray(a))return-1!==a.indexOf(b);if("string"==typeof a){if("string"!=typeof b)throw new Error("Contains in string should search for string also "+b);return-1!==a.indexOf(b)}return!1}function i(a,b){return typeof b===a}function j(a,b){return q.defined(a)&&q.has(a,"length")&&b>=0&&b=0&&1>=a}function o(a){return q.string(a)&&t.test(a)}function p(a,b){r(q.fn(a),"expected function that raises");try{a()}catch(c){return"undefined"==typeof b?!0:"function"==typeof b?b(c):!1}return!1}var q=c(1),r=c(4),s=c(2).curry2,t=/^#(?:[0-9a-fA-F]{3}){1,2}$/;a.exports={allSame:l,contains:h,even:f,found:d,hexRgb:o,index:j,odd:g,oneOf:s(m,!0),raises:p,sameLength:k,startsWith:e,type:s(i),unit:n}},function(a,b,c){"use strict";function d(a,b){return function(){var c;if(a.apply(null,arguments)===!1)throw c=arguments[arguments.length-1],new Error(e.unemptyString(c)?c:b)}}var e=c(1);a.exports=d},function(a,b,c){"use strict";function d(a){return i.isArray(a)&&a.length>0}function e(a,b){return i.isArray(b)&&b.every(a)}function f(a,b){if(!i.isArray(b))throw new Error("expected array to find bad items");return b.filter(j.notModifier(a))}function g(a,b){var c=i.isArray(a)&&a.every(i.string);return c&&i.bool(b)&&b?a.every(i.lowerCase):c}function h(a,b){return i.isArray(a)&&a.every(function(a){return g(a,b)})}var i=c(1),j=c(6),k=c(4);k(i.fn(i.isArray),"missing low level isArray"),a.exports={arrayOf:e,arrayOfArraysOfStrings:h,arrayOfStrings:g,badItems:f,unemptyArray:d}},function(a,b,c){"use strict";function d(){var a=Array.prototype.slice.call(arguments,0);if(!a.length)throw new Error("empty list of arguments to or");return function(){var b=Array.prototype.slice.call(arguments,0);return a.some(function(a){try{return i.fn(a)?a.apply(null,b):Boolean(a)}catch(c){return!1}})}}function e(){var a=Array.prototype.slice.call(arguments,0);if(!a.length)throw new Error("empty list of arguments to or");return function(){var b=Array.prototype.slice.call(arguments,0);return a.every(function(a){return i.fn(a)?a.apply(null,b):Boolean(a)})}}function f(a){return function(){return!a.apply(null,arguments)}}function g(a){var b,c;for(b in a)if(a.hasOwnProperty(b)){if(c=a[b],i.object(c)&&g(c)===!1)return!1;if(c===!1)return!1}return!0}function h(a,b){var c,d,e={};for(c in b)b.hasOwnProperty(c)&&(d=b[c],i.fn(d)?e[c]=d(a[c]):i.object(d)&&(e[c]=h(a[c],d)));return e}var i=c(1);a.exports={or:d,and:e,notModifier:f,every:g,map:h}},function(a,b,c){"use strict";function d(a){return h.unemptyString(a)&&/^\d+\.\d+\.\d+$/.test(a)}function e(a){return h.unemptyString(a)&&/^git@/.test(a)}function f(a){return h.string(a)&&40===a.length&&i.test(a)}function g(a){return h.string(a)&&7===a.length&&j.test(a)}var h=c(1),i=/^[0-9a-f]{40}$/,j=/^[0-9a-f]{7}$/;a.exports={semver:d,git:e,commitId:f,shortCommitId:g}},function(a,b,c){"use strict";function d(a){return k.string(a)&&m(a)}function e(a){return k.string(a)&&n(a)}function f(a){return k.string(a)&&(m(a)||n(a))}function g(a){return k.positiveNumber(a)&&65535>=a}function h(a){return k.positiveNumber(a)&&1024>=a}function i(a){return g(a)&&a>1024}function j(a){return k.string(a)&&/^.+@.+\..+$/.test(a)}var k=c(1),l=c(3),m=l.startsWith.bind(null,"http://"),n=l.startsWith.bind(null,"https://");a.exports={email:j,http:d,https:e,port:g,secure:e,systemPort:h,url:f,userPort:i,webUrl:f}},function(a,b,c){"use strict";function d(a,b){return h(g.object(a),"missing object to check"),h(g.object(b),"missing predicates object"),Object.keys(b).forEach(function(a){if(!g.fn(b[a]))throw new Error("not a predicate function for "+a+" but "+b[a])}),i(j(a,b))}function e(a,b){return d(b,a)}var f=c(2).curry2,g=c(1),h=c(4),i=c(6).every,j=c(6).map;h(g.fn(i),"missing check.every method"),h(g.fn(j),"missing check.map method"),a.exports={all:d,schema:f(e)}}])}); \ No newline at end of file diff --git a/docs/use.md b/docs/use.md index 6bfcc58..9656a85 100644 --- a/docs/use.md +++ b/docs/use.md @@ -18,6 +18,16 @@ check.email('me@foo.bar') // true check.email('me.foo.bar') // false ``` +### check.odd and check.even + +Check if a number odd or even + +```js +check.odd(2) // false +check.odd(3) // true +check.even(2) // true +``` + ### check.port Returns true if passed argument is positive number less or equal to largest diff --git a/src/mid-level-spec.js b/src/mid-level-spec.js new file mode 100644 index 0000000..f216552 --- /dev/null +++ b/src/mid-level-spec.js @@ -0,0 +1,28 @@ +'use strict' + +/* global describe, it */ +describe('check-more-types mid-level predicates', function () { + const la = require('lazy-ass') + const mid = require('./mid-level') + const check = require('..') + + it('is an object', function () { + la(check.object(mid)) + }) + + it('check/even', function () { + la(mid.even(2), '2 is even') + la(mid.even(4), '4 is even') + la(mid.even(0), '0 is even') + la(!mid.even(1), '1 is not even') + la(!mid.even(11), '11 is not even') + }) + + it('check/odd', function () { + la(!mid.odd(2), '2 is not odd') + la(!mid.odd(4), '4 is not odd') + la(!mid.odd(0), '0 is not odd') + la(mid.odd(1), '1 is odd') + la(mid.odd(11), '11 is odd') + }) +}) diff --git a/src/mid-level.js b/src/mid-level.js index 758dea7..5661002 100644 --- a/src/mid-level.js +++ b/src/mid-level.js @@ -19,6 +19,24 @@ function startsWith (prefix, x) { x.indexOf(prefix) === 0 } +/** + Checks if given number is even + + @method even +*/ +function even (n) { + return n % 2 === 0 +} + +/** + Checks if given number is odd + + @method odd +*/ +function odd (n) { + return n % 2 === 1 +} + /** Checks if the given item is the given {arrya, string} @@ -140,15 +158,17 @@ function raises (fn, errorValidator) { } module.exports = { - found: found, - startsWith: startsWith, + allSame: allSame, contains: contains, - type: curry2(type), + even: even, + found: found, + hexRgb: hexRgb, index: index, + odd: odd, oneOf: curry2(oneOf, true), + raises: raises, sameLength: sameLength, - allSame: allSame, - unit: unit, - hexRgb: hexRgb, - raises: raises + startsWith: startsWith, + type: curry2(type), + unit: unit }