check-more-types
Advanced tools
Comparing version 2.14.0 to 2.15.0
@@ -104,2 +104,20 @@ (function checkMoreTypes() { | ||
/** | ||
Checks if the given item is the given {arrya, string} | ||
@method contains | ||
*/ | ||
function contains(where, what) { | ||
if (Array.isArray(where)) { | ||
return where.indexOf(what) !== -1; | ||
} | ||
if (typeof where === 'string') { | ||
if (typeof what !== 'string') { | ||
throw new Error('Contains in string should search for string also ' + what); | ||
} | ||
return where.indexOf(what) !== -1; | ||
} | ||
return false; | ||
} | ||
/** | ||
Checks if the type of second argument matches the name in the first | ||
@@ -832,3 +850,4 @@ | ||
systemPort: isSystemPortNumber, | ||
userPort: isUserPortNumber | ||
userPort: isUserPortNumber, | ||
contains: contains | ||
}; | ||
@@ -835,0 +854,0 @@ |
@@ -5,2 +5,2 @@ /*! check-more-types - v0.0.0 | ||
!function(){"use strict";function a(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)}}}function b(a){return"function"==typeof a}function c(a){return"string"==typeof a}function d(a){return c(a)&&Boolean(a)}function e(a){return"object"==typeof a&&!Array.isArray(a)&&!j(a)&&!m(a)}function f(a){return e(a)&&0===Object.keys(a).length}function g(a){return"number"==typeof a&&!isNaN(a)&&a!==1/0&&a!==-(1/0)}function h(a){return g(a)&&a%1===0}function i(a){return g(a)&&a%1!==0}function j(a){return null===a}function k(a){return g(a)&&a>0}function l(a){return g(a)&&0>a}function m(a){return a instanceof Date}function n(a){return a instanceof RegExp}function o(a){return a instanceof Error}function p(a,b){return a instanceof b}function q(a,b){return"number"==typeof a&&"number"!=typeof b?q(b,a):(Array.isArray(a)||c(a))&&a.length===b}function r(a){return a>=0}function s(a,b){return c(a)&&c(b)&&0===b.indexOf(a)}function t(a,b){return typeof b===a}function u(a){return c(a)&&ka(a)}function v(a){return c(a)&&la(a)}function w(a){return c(a)&&(ka(a)||la(a))}function x(a){var b,c;for(b in a)if(a.hasOwnProperty(b)){if(c=a[b],e(c)&&x(c)===!1)return!1;if(c===!1)return!1}return!0}function y(a,c){var d,f,g={};for(d in c)c.hasOwnProperty(d)&&(f=c[d],b(f)?g[d]=f(a[d]):e(f)&&(g[d]=y(a[d],f)));return g}function z(a){return"undefined"!=typeof a}function A(a){return ma.date(a)&&ma.number(Number(a))}function B(a){return ma.unemptyString(a)&&/^\d+\.\d+\.\d+$/.test(a)}function C(a){var b=typeof a;return"number"===b||"boolean"===b||"string"===b||"symbol"===b}function D(a){return"number"==typeof a&&0===a}function E(a,b){return a===b}function F(a,b){return z(a)&&M(a,"length")&&b>=0&&b<a.length}function G(a,b){return typeof a==typeof b&&a&&b&&a.length===b.length}function H(a){if(!ma.array(a))return!1;if(!a.length)return!0;var b=a[0];return a.every(function(a){return a===b})}function I(a,b){return ma.verify.array(a,"expected an array"),-1!==a.indexOf(b)}function J(a){return ma.unemptyString(a)&&/^git@/.test(a)}function K(a){return 0===a||1===a}function L(a){return"boolean"==typeof a}function M(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 N(a){return ma.string(a)&&a.toLowerCase()===a}function O(a){return ma.array(a)&&a.length>0}function P(a,b){return ma.array(b)&&b.every(a)}function Q(a,b){return ma.verify.array(b,"expected array to find bad items"),b.filter(ga(a))}function R(a,b){var c=ma.array(a)&&a.every(ma.string);return c&&ma.bool(b)&&b?a.every(ma.lowerCase):c}function S(a,b){return ma.array(a)&&a.every(function(a){return ma.arrayOfStrings(a,b)})}function T(a,b){return ma.verify.fn(ma.every,"missing check.every method"),ma.verify.fn(ma.map,"missing check.map method"),ma.verify.object(a,"missing object to check"),ma.verify.object(b,"missing predicates object"),Object.keys(b).forEach(function(a){if(!ma.fn(b[a]))throw new Error("not a predicate function for "+a+" but "+b[a])}),ma.every(ma.map(a,b))}function U(a,b){return T(b,a)}function V(a,b){ma.verify.fn(a,"expected function that raises");try{a()}catch(c){return"undefined"==typeof b?!0:"function"==typeof b?b(c):!1}return!1}function W(a){return""===a}function X(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function Y(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function Z(a){return ma.positive(a)&&65535>=a}function $(a){return ma.positive(a)&&1024>=a}function _(a){return Z(a)&&a>1024}function aa(a){return ma.number(a)&&a>=0&&1>=a}function ba(a){return ma.string(a)&&na.test(a)}function ca(a){return ma.string(a)&&40===a.length&&oa.test(a)}function da(a){return ma.string(a)&&7===a.length&&pa.test(a)}function ea(){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 ma.fn(a)?a.apply(null,b):Boolean(a)}catch(c){return!1}})}}function fa(){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 ma.fn(a)?a.apply(null,b):Boolean(a)})}}function ga(a){return function(){return!a.apply(null,arguments)}}function ha(a){return ma.object(a)&&sa(a)}function ia(a,b){return a===b}function ja(a){return c(a)&&/^.+@.+\..+$/.test(a)}if("function"!=typeof Function.prototype.bind)throw new Error("Missing Function.prototype.bind, please load es5-shim first");var ka=s.bind(null,"http://"),la=s.bind(null,"https://"),ma={maybe:{},verify:{},not:{},every:x,map:y},na=/^#(?:[0-9a-fA-F]{3}){1,2}$/,oa=/^[0-9a-f]{40}$/,pa=/^[0-9a-f]{7}$/;if(!ma.defend){var qa=function(a,b,c){ma.verify.fn(a,"expected a function"),ma.verify.array(b,"expected list of predicates"),ma.verify.defined(c,"missing args");var d=0,e=0,f=b.length;for(d=0;f>d;d+=1){var g=b[d];if(ma.fn(g)){if(!g.call(null,c[e])){var h="Argument "+(e+1)+": "+c[e]+" does not pass predicate";throw ma.unemptyString(b[d+1])&&(h+=": "+b[d+1]),new Error(h)}e+=1}}return a.apply(null,c)};ma.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return qa(a,b,arguments)}}}ma.mixin||(ma.mixin=function(a,f){function g(a,c,f){if(!e(a))throw new Error("missing object "+a);if(!d(c))throw new Error("missing name");if(!b(f))throw new Error("missing function");a[c]||(a[c]=f)}function h(a){return function(){return!ma.defined(arguments[0])||ma.nulled(arguments[0])?!0:a.apply(null,arguments)}}function i(a,b){return function(){var c;if(a.apply(null,arguments)===!1)throw c=arguments[arguments.length-1],new Error(ma.unemptyString(c)?c:b)}}if(c(a)&&b(f)){var j=a;a=f,f=j}if(!b(a))throw new Error("expected predicate function");if(d(f)||(f=a.name),!d(f))throw new Error("predicate function missing name\n"+a.toString());g(ma,f,a),g(ma.maybe,f,h(a)),g(ma.not,f,ga(a)),g(ma.verify,f,i(a,f+" failed"))}),ma.then||(ma.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 ra={then:b};ra["catch"]=b;var sa=U.bind(null,ra),ta={email:ja,nulled:j,fn:b,string:c,unemptyString:d,object:e,number:g,array:Array.isArray,positiveNumber:k,negativeNumber:l,positive:k,negative:l,defined:z,same:E,allSame:H,bit:K,bool:L,has:M,lowerCase:N,unemptyArray:O,arrayOfStrings:R,arrayOfArraysOfStrings:S,all:T,schema:a(U),raises:V,empty:X,found:r,emptyString:W,unempty:Y,unit:aa,hexRgb:ba,sameLength:G,commitId:ca,shortCommitId:da,index:F,git:J,arrayOf:P,badItems:Q,oneOf:a(I,!0),promise:ha,validDate:A,equal:a(ia),or:ea,and:fa,primitive:C,zero:D,date:m,regexp:n,instance:p,emptyObject:f,length:a(q),floatNumber:i,intNumber:h,startsWith:s,webUrl:w,url:w,semver:B,type:a(t),http:u,https:v,secure:v,error:o,port:Z,systemPort:$,userPort:_};Object.keys(ta).forEach(function(a){ma.mixin(ta[a],a)}),"object"==typeof module&&(module.exports=ma),"object"==typeof window&&(window.check=ma),"object"==typeof global&&(global.check=ma)}(); | ||
!function(){"use strict";function a(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)}}}function b(a){return"function"==typeof a}function c(a){return"string"==typeof a}function d(a){return c(a)&&Boolean(a)}function e(a){return"object"==typeof a&&!Array.isArray(a)&&!j(a)&&!m(a)}function f(a){return e(a)&&0===Object.keys(a).length}function g(a){return"number"==typeof a&&!isNaN(a)&&a!==1/0&&a!==-(1/0)}function h(a){return g(a)&&a%1===0}function i(a){return g(a)&&a%1!==0}function j(a){return null===a}function k(a){return g(a)&&a>0}function l(a){return g(a)&&0>a}function m(a){return a instanceof Date}function n(a){return a instanceof RegExp}function o(a){return a instanceof Error}function p(a,b){return a instanceof b}function q(a,b){return"number"==typeof a&&"number"!=typeof b?q(b,a):(Array.isArray(a)||c(a))&&a.length===b}function r(a){return a>=0}function s(a,b){return c(a)&&c(b)&&0===b.indexOf(a)}function t(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 u(a,b){return typeof b===a}function v(a){return c(a)&&la(a)}function w(a){return c(a)&&ma(a)}function x(a){return c(a)&&(la(a)||ma(a))}function y(a){var b,c;for(b in a)if(a.hasOwnProperty(b)){if(c=a[b],e(c)&&y(c)===!1)return!1;if(c===!1)return!1}return!0}function z(a,c){var d,f,g={};for(d in c)c.hasOwnProperty(d)&&(f=c[d],b(f)?g[d]=f(a[d]):e(f)&&(g[d]=z(a[d],f)));return g}function A(a){return"undefined"!=typeof a}function B(a){return na.date(a)&&na.number(Number(a))}function C(a){return na.unemptyString(a)&&/^\d+\.\d+\.\d+$/.test(a)}function D(a){var b=typeof a;return"number"===b||"boolean"===b||"string"===b||"symbol"===b}function E(a){return"number"==typeof a&&0===a}function F(a,b){return a===b}function G(a,b){return A(a)&&N(a,"length")&&b>=0&&b<a.length}function H(a,b){return typeof a==typeof b&&a&&b&&a.length===b.length}function I(a){if(!na.array(a))return!1;if(!a.length)return!0;var b=a[0];return a.every(function(a){return a===b})}function J(a,b){return na.verify.array(a,"expected an array"),-1!==a.indexOf(b)}function K(a){return na.unemptyString(a)&&/^git@/.test(a)}function L(a){return 0===a||1===a}function M(a){return"boolean"==typeof a}function N(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 O(a){return na.string(a)&&a.toLowerCase()===a}function P(a){return na.array(a)&&a.length>0}function Q(a,b){return na.array(b)&&b.every(a)}function R(a,b){return na.verify.array(b,"expected array to find bad items"),b.filter(ha(a))}function S(a,b){var c=na.array(a)&&a.every(na.string);return c&&na.bool(b)&&b?a.every(na.lowerCase):c}function T(a,b){return na.array(a)&&a.every(function(a){return na.arrayOfStrings(a,b)})}function U(a,b){return na.verify.fn(na.every,"missing check.every method"),na.verify.fn(na.map,"missing check.map method"),na.verify.object(a,"missing object to check"),na.verify.object(b,"missing predicates object"),Object.keys(b).forEach(function(a){if(!na.fn(b[a]))throw new Error("not a predicate function for "+a+" but "+b[a])}),na.every(na.map(a,b))}function V(a,b){return U(b,a)}function W(a,b){na.verify.fn(a,"expected function that raises");try{a()}catch(c){return"undefined"==typeof b?!0:"function"==typeof b?b(c):!1}return!1}function X(a){return""===a}function Y(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function Z(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function $(a){return na.positive(a)&&65535>=a}function _(a){return na.positive(a)&&1024>=a}function aa(a){return $(a)&&a>1024}function ba(a){return na.number(a)&&a>=0&&1>=a}function ca(a){return na.string(a)&&oa.test(a)}function da(a){return na.string(a)&&40===a.length&&pa.test(a)}function ea(a){return na.string(a)&&7===a.length&&qa.test(a)}function fa(){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 na.fn(a)?a.apply(null,b):Boolean(a)}catch(c){return!1}})}}function ga(){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 na.fn(a)?a.apply(null,b):Boolean(a)})}}function ha(a){return function(){return!a.apply(null,arguments)}}function ia(a){return na.object(a)&&ta(a)}function ja(a,b){return a===b}function ka(a){return c(a)&&/^.+@.+\..+$/.test(a)}if("function"!=typeof Function.prototype.bind)throw new Error("Missing Function.prototype.bind, please load es5-shim first");var la=s.bind(null,"http://"),ma=s.bind(null,"https://"),na={maybe:{},verify:{},not:{},every:y,map:z},oa=/^#(?:[0-9a-fA-F]{3}){1,2}$/,pa=/^[0-9a-f]{40}$/,qa=/^[0-9a-f]{7}$/;if(!na.defend){var ra=function(a,b,c){na.verify.fn(a,"expected a function"),na.verify.array(b,"expected list of predicates"),na.verify.defined(c,"missing args");var d=0,e=0,f=b.length;for(d=0;f>d;d+=1){var g=b[d];if(na.fn(g)){if(!g.call(null,c[e])){var h="Argument "+(e+1)+": "+c[e]+" does not pass predicate";throw na.unemptyString(b[d+1])&&(h+=": "+b[d+1]),new Error(h)}e+=1}}return a.apply(null,c)};na.defend=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){return ra(a,b,arguments)}}}na.mixin||(na.mixin=function(a,f){function g(a,c,f){if(!e(a))throw new Error("missing object "+a);if(!d(c))throw new Error("missing name");if(!b(f))throw new Error("missing function");a[c]||(a[c]=f)}function h(a){return function(){return!na.defined(arguments[0])||na.nulled(arguments[0])?!0:a.apply(null,arguments)}}function i(a,b){return function(){var c;if(a.apply(null,arguments)===!1)throw c=arguments[arguments.length-1],new Error(na.unemptyString(c)?c:b)}}if(c(a)&&b(f)){var j=a;a=f,f=j}if(!b(a))throw new Error("expected predicate function");if(d(f)||(f=a.name),!d(f))throw new Error("predicate function missing name\n"+a.toString());g(na,f,a),g(na.maybe,f,h(a)),g(na.not,f,ha(a)),g(na.verify,f,i(a,f+" failed"))}),na.then||(na.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 sa={then:b};sa["catch"]=b;var ta=V.bind(null,sa),ua={email:ka,nulled:j,fn:b,string:c,unemptyString:d,object:e,number:g,array:Array.isArray,positiveNumber:k,negativeNumber:l,positive:k,negative:l,defined:A,same:F,allSame:I,bit:L,bool:M,has:N,lowerCase:O,unemptyArray:P,arrayOfStrings:S,arrayOfArraysOfStrings:T,all:U,schema:a(V),raises:W,empty:Y,found:r,emptyString:X,unempty:Z,unit:ba,hexRgb:ca,sameLength:H,commitId:da,shortCommitId:ea,index:G,git:K,arrayOf:Q,badItems:R,oneOf:a(J,!0),promise:ia,validDate:B,equal:a(ja),or:fa,and:ga,primitive:D,zero:E,date:m,regexp:n,instance:p,emptyObject:f,length:a(q),floatNumber:i,intNumber:h,startsWith:s,webUrl:x,url:x,semver:C,type:a(u),http:v,https:w,secure:w,error:o,port:$,systemPort:_,userPort:aa,contains:t};Object.keys(ua).forEach(function(a){na.mixin(ua[a],a)}),"object"==typeof module&&(module.exports=na),"object"==typeof window&&(window.check=na),"object"==typeof global&&(global.check=na)}(); |
{ | ||
"name": "check-more-types", | ||
"description": "Large collection of predicates.", | ||
"version": "2.14.0", | ||
"version": "2.15.0", | ||
"author": { | ||
@@ -109,2 +109,3 @@ "name": "Gleb Bahmutov", | ||
"test": "npm run node-test && npm run mocha:synthetic && npm run mocha", | ||
"unit": "npm run mocha", | ||
"watch": "grunt watch" | ||
@@ -111,0 +112,0 @@ }, |
@@ -61,2 +61,3 @@ # check-more-types | ||
* [check.webUrl (alias `url`)](#checkweburl-alias-url) | ||
* [check.contains](#checkcontains) | ||
* [check.defined](#checkdefined) | ||
@@ -169,2 +170,11 @@ * [check.semver](#checksemver) | ||
#### check.contains | ||
Returns true if given array contains an item, or given string contains substring. | ||
```js | ||
check.contains(['foo', 42], 'foo'); // true | ||
check.contains('apple', 'pp'); // true | ||
``` | ||
#### check.defined | ||
@@ -171,0 +181,0 @@ |
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
56396
794
919