check-types
Advanced tools
Comparing version 3.3.1 to 4.0.0
{ | ||
"name": "check-types", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"main": "src/check-types.min.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
{ | ||
"name": "check-types", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"description": "A tiny library for asserting types and values.", | ||
@@ -5,0 +5,0 @@ "repo": "philbooth/check-types.js", |
# History | ||
## 4.0 | ||
* Breaking changes: | ||
* Rename `unemptyString` => `nonEmptyString`. | ||
* Support derived error objects in `error`. | ||
## 3.3 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "check-types", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"description": "A little library for asserting types and values.", | ||
@@ -32,5 +32,5 @@ "homepage": "https://github.com/philbooth/check-types.js", | ||
"devDependencies": { | ||
"jshint": "2.6.x", | ||
"mocha": "2.2.x", | ||
"chai": "2.1.x", | ||
"jshint": "2.8.x", | ||
"mocha": "2.3.x", | ||
"chai": "3.3.x", | ||
"uglify-js": "2.4.x" | ||
@@ -37,0 +37,0 @@ }, |
@@ -28,2 +28,3 @@ # check-types.js | ||
* [Where can I use it?](#where-can-i-use-it) | ||
* [What changed from 3.x to 4.x?](#what-changed-from-3x-to-4x) | ||
* [What changed from 2.x to 3.x?](#what-changed-from-2x-to-3x) | ||
@@ -217,3 +218,3 @@ * [What changed from 1.x to 2.x?](#what-changed-from-1x-to-2x) | ||
* `check.unemptyString(thing)`: | ||
* `check.nonEmptyString(thing)`: | ||
Returns `true` | ||
@@ -513,3 +514,3 @@ if `thing` is a non-empty string, | ||
to the same predicate, | ||
ignore nested objects. | ||
ignoring nested objects. | ||
@@ -571,3 +572,3 @@ * `check.all(results)`: | ||
```javascript | ||
check.apply([ 'foo', 'bar', '' ], check.unemptyString); | ||
check.apply([ 'foo', 'bar', '' ], check.nonEmptyString); | ||
// Returns [ true, true, false ] | ||
@@ -582,3 +583,3 @@ ``` | ||
foo: check.odd, | ||
bar: { baz: check.unemptyString } | ||
bar: { baz: check.nonEmptyString } | ||
}); | ||
@@ -628,2 +629,15 @@ // Returns { foo: false, bar: { baz: true } } | ||
## What changed from 3.x to 4.x? | ||
Breaking changes | ||
were made to the API | ||
in version 4.0.0. | ||
Specifically, | ||
the predicate `unemptyString` | ||
was renamed to `nonEmptyString` | ||
and the predicate `error` | ||
was changed to support | ||
derived Error objects. | ||
## What changed from 2.x to 3.x? | ||
@@ -630,0 +644,0 @@ |
@@ -31,3 +31,3 @@ /*globals define, module, Symbol */ | ||
contains: 'Invalid string', | ||
unemptyString: 'Invalid string', | ||
nonEmptyString: 'Invalid string', | ||
string: 'Invalid string', | ||
@@ -68,3 +68,3 @@ odd: 'Invalid number', | ||
contains: contains, | ||
unemptyString: unemptyString, | ||
nonEmptyString: nonEmptyString, | ||
string: string, | ||
@@ -153,7 +153,7 @@ odd: odd, | ||
function instance (data, prototype) { | ||
if (data && isFunction(prototype) && data instanceof prototype) { | ||
return true; | ||
try { | ||
return data instanceof prototype; | ||
} catch (error) { | ||
return false; | ||
} | ||
return false; | ||
} | ||
@@ -296,3 +296,3 @@ | ||
function error (data) { | ||
return Object.prototype.toString.call(data) === '[object Error]'; | ||
return data instanceof Error || Object.prototype.toString.call(data) === '[object Error]'; | ||
} | ||
@@ -334,3 +334,3 @@ | ||
/** | ||
* Public function `unemptyString`. | ||
* Public function `nonEmptyString`. | ||
* | ||
@@ -341,3 +341,3 @@ * Returns `true` if something is a non-empty string, | ||
*/ | ||
function unemptyString (data) { | ||
function nonEmptyString (data) { | ||
return string(data) && data !== ''; | ||
@@ -687,3 +687,3 @@ } | ||
var message = args[args.length - 1]; | ||
assertImpl(predicate.apply(null, args), unemptyString(message) ? message : defaultMessage); | ||
assertImpl(predicate.apply(null, args), nonEmptyString(message) ? message : defaultMessage); | ||
} | ||
@@ -690,0 +690,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(n){"use strict";function r(n,t){var e;for(e in t)if(t.hasOwnProperty(e)){if(n.hasOwnProperty(e)===!1||typeof n[e]!=typeof t[e])return!1;if(u(n[e])&&r(n[e],t[e])===!1)return!1}return!0}function t(n,r){return n&&v(r)&&n instanceof r?!0:!1}function e(n){return u(n)&&0===Object.keys(n).length}function u(n){return"[object Object]"===Object.prototype.toString.call(n)}function i(n){return!o(n)&&!a(n)}function o(n){return void 0===n}function a(n){return null===n}function c(n,r){return i(n)&&n.length===r}function f(n){return l(n)&&0===n.length}function l(n){return Array.isArray(n)}function d(n){return i(n)&&T(n.length)}function s(n){return"undefined"==typeof Symbol?d(n):i(n)&&v(n[Symbol.iterator])}function b(n){return"[object Date]"===Object.prototype.toString.call(n)&&!isNaN(n.getTime())}function y(n){return"[object Error]"===Object.prototype.toString.call(n)}function v(n){return"function"==typeof n}function p(n,r){return I(n)&&!!n.match(r)}function m(n,r){return I(n)&&-1!==n.indexOf(r)}function g(n){return I(n)&&""!==n}function I(n){return"string"==typeof n}function h(n){return O(n)&&!j(n)}function j(n){return T(n)&&n%2===0}function O(n){return T(n)&&n%1===0}function E(n,r,t){return t>r?k(n,r)&&w(n,t):w(n,r)&&k(n,t)}function k(n,r){return T(n)&&n>=r}function w(n,r){return T(n)&&r>=n}function N(n,r,t){return t>r?S(n,r)&&A(n,t):A(n,r)&&S(n,t)}function S(n,r){return T(n)&&n>r}function A(n,r){return T(n)&&r>n}function L(n){return S(n,0)}function P(n){return A(n,0)}function T(n){return"number"==typeof n&&isNaN(n)===!1&&n!==Number.POSITIVE_INFINITY&&n!==Number.NEGATIVE_INFINITY}function q(n){return 0===n}function _(n){return n===!1||n===!0}function x(n,r){return dn.array(n),v(r)?n.map(function(n){return r(n)}):(dn.array(r),dn.hasLength(n,r.length),n.map(function(n,t){return r[t](n)}))}function z(n,r){return dn.object(n),v(r)?F(n,r):(dn.object(r),M(n,r))}function F(n,r){var t={};return Object.keys(n).forEach(function(e){t[e]=r(n[e])}),t}function M(n,r){var t={};return Object.keys(r).forEach(function(e){var i=r[e];v(i)?sn.assigned(n)?t[e]=!!i._isMaybefied:t[e]=i(n[e]):u(i)&&(t[e]=M(n[e],i))}),t}function R(n){return l(n)?V(n,!1):(dn.object(n),Y(n,!1))}function V(n,r){var t;for(t=0;t<n.length;t+=1)if(n[t]===r)return r;return!r}function Y(n,r){var t,e;for(t in n)if(n.hasOwnProperty(t)){if(e=n[t],u(e)&&Y(e,r)===r)return r;if(e===r)return r}return!r}function D(n){return l(n)?V(n,!0):(dn.object(n),Y(n,!0))}function G(n,r){return Object.keys(r).forEach(function(t){n[t]=r[t]}),n}function B(n,r){return function(){C(n,arguments,r)}}function C(n,r,t){var e=r[r.length-1];H(n.apply(null,r),g(e)?e:t)}function H(n,r){if(n===!1)throw new Error(r||"Assertion failed")}function J(n,r){return function(){function t(n,r){return n[r]=function(){if(e&&!fn[r].apply(null,arguments))throw e},n}var e;try{C(n,arguments,r)}catch(u){e=u}return{or:Object.keys(fn).reduce(t,{})}}}function K(n){return function(){return Q(n.apply(null,arguments))}}function Q(n){return!n}function U(n){var r=function(){return i(arguments[0])?n.apply(null,arguments):!0};return r._isMaybefied=!0,r}function W(n){return i(n)===!1?!0:n}function X(n){function r(){return!0}return function(){function t(n,t){return n[t]=e?r:fn[t],n}var e=n.apply(null,arguments);return{or:Object.keys(fn).reduce(t,{})}}}function Z(n,r,t){return function(){var e,u;if(e=arguments[0],!r(e))return!1;e=$(r,e),u=pn.call(arguments,1);try{e.forEach(function(r){if(("maybe"!==n||i(r))&&!t.apply(null,[r].concat(u)))throw 0})}catch(o){return!1}return!0}}function $(n,r){switch(n){case d:return pn.call(r);case u:return Object.keys(r).map(function(n){return r[n]});default:return r}}function nn(n,r){return rn([n,fn,r])}function rn(n){var r,t,e,u;return r=n.shift(),t=n.pop(),e=n.pop(),u=t||{},Object.keys(e).forEach(function(t){Object.defineProperty(u,t,{configurable:!1,enumerable:!0,writable:!1,value:r.apply(null,n.concat(e[t],cn[t]))})}),u}function tn(n,r){return rn([n,r,null])}function en(n){fn[n].of=rn([Z.bind(null,null),fn[n],fn,null])}function un(n,r){vn.forEach(function(t){n[t].of=tn(r,fn[t].of)})}function on(n){bn[n].of=rn([Z.bind(null,"maybe"),fn[n],fn,null]),dn.maybe[n].of=tn(B,bn[n].of),dn.not[n].of=tn(B,sn[n].of)}function an(r){"function"==typeof define&&define.amd?define(function(){return r}):"undefined"!=typeof module&&null!==module&&module.exports?module.exports=r:n.check=r}var cn,fn,ln,dn,sn,bn,yn,vn,pn;cn={like:"Invalid type",instance:"Invalid type",emptyObject:"Invalid object",object:"Invalid object",assigned:"Invalid value",undefined:"Invalid value","null":"Invalid value",hasLength:"Invalid length",emptyArray:"Invalid array",array:"Invalid array",arrayLike:"Invalid array-like object",iterable:"Invalid iterable",date:"Invalid date",error:"Invalid error",fn:"Invalid function",match:"Invalid string",contains:"Invalid string",unemptyString:"Invalid string",string:"Invalid string",odd:"Invalid number",even:"Invalid number",inRange:"Invalid number",greaterOrEqual:"Invalid number",lessOrEqual:"Invalid number",between:"Invalid number",greater:"Invalid number",less:"Invalid number",positive:"Invalid number",negative:"Invalid number",integer:"Invalid number",zero:"Invalid number",number:"Invalid number","boolean":"Invalid boolean"},fn={like:r,instance:t,emptyObject:e,object:u,assigned:i,undefined:o,"null":a,hasLength:c,emptyArray:f,array:l,arrayLike:d,iterable:s,date:b,error:y,"function":v,match:p,contains:m,unemptyString:g,string:I,odd:h,even:j,inRange:E,greaterOrEqual:k,lessOrEqual:w,between:N,greater:S,less:A,positive:L,negative:P,integer:O,zero:q,number:T,"boolean":_},ln={apply:x,map:z,all:R,any:D},vn=["array","arrayLike","iterable","object"],pn=Array.prototype.slice,ln=G(ln,fn),dn=nn(B,H),sn=nn(K,Q),bn=nn(U,W),yn=nn(X),dn.not=tn(B,sn),dn.maybe=tn(B,bn),dn.either=tn(J,fn),vn.forEach(en),un(dn,B),un(sn,K),vn.forEach(on),an(G(ln,{assert:dn,not:sn,maybe:bn,either:yn}))}(this); | ||
!function(n){"use strict";function r(n,t){var e;for(e in t)if(t.hasOwnProperty(e)){if(n.hasOwnProperty(e)===!1||typeof n[e]!=typeof t[e])return!1;if(u(n[e])&&r(n[e],t[e])===!1)return!1}return!0}function t(n,r){try{return n instanceof r}catch(t){return!1}}function e(n){return u(n)&&0===Object.keys(n).length}function u(n){return"[object Object]"===Object.prototype.toString.call(n)}function i(n){return!o(n)&&!a(n)}function o(n){return void 0===n}function a(n){return null===n}function c(n,r){return i(n)&&n.length===r}function f(n){return l(n)&&0===n.length}function l(n){return Array.isArray(n)}function s(n){return i(n)&&T(n.length)}function d(n){return"undefined"==typeof Symbol?s(n):i(n)&&v(n[Symbol.iterator])}function b(n){return"[object Date]"===Object.prototype.toString.call(n)&&!isNaN(n.getTime())}function y(n){return n instanceof Error||"[object Error]"===Object.prototype.toString.call(n)}function v(n){return"function"==typeof n}function p(n,r){return I(n)&&!!n.match(r)}function m(n,r){return I(n)&&-1!==n.indexOf(r)}function g(n){return I(n)&&""!==n}function I(n){return"string"==typeof n}function h(n){return O(n)&&!j(n)}function j(n){return T(n)&&n%2===0}function O(n){return T(n)&&n%1===0}function E(n,r,t){return t>r?k(n,r)&&w(n,t):w(n,r)&&k(n,t)}function k(n,r){return T(n)&&n>=r}function w(n,r){return T(n)&&r>=n}function N(n,r,t){return t>r?S(n,r)&&A(n,t):A(n,r)&&S(n,t)}function S(n,r){return T(n)&&n>r}function A(n,r){return T(n)&&r>n}function L(n){return S(n,0)}function P(n){return A(n,0)}function T(n){return"number"==typeof n&&isNaN(n)===!1&&n!==Number.POSITIVE_INFINITY&&n!==Number.NEGATIVE_INFINITY}function q(n){return 0===n}function _(n){return n===!1||n===!0}function x(n,r){return lr.array(n),v(r)?n.map(function(n){return r(n)}):(lr.array(r),lr.hasLength(n,r.length),n.map(function(n,t){return r[t](n)}))}function z(n,r){return lr.object(n),v(r)?F(n,r):(lr.object(r),M(n,r))}function F(n,r){var t={};return Object.keys(n).forEach(function(e){t[e]=r(n[e])}),t}function M(n,r){var t={};return Object.keys(r).forEach(function(e){var i=r[e];v(i)?t[e]=sr.assigned(n)?!!i._isMaybefied:i(n[e]):u(i)&&(t[e]=M(n[e],i))}),t}function R(n){return l(n)?V(n,!1):(lr.object(n),Y(n,!1))}function V(n,r){var t;for(t=0;t<n.length;t+=1)if(n[t]===r)return r;return!r}function Y(n,r){var t,e;for(t in n)if(n.hasOwnProperty(t)){if(e=n[t],u(e)&&Y(e,r)===r)return r;if(e===r)return r}return!r}function D(n){return l(n)?V(n,!0):(lr.object(n),Y(n,!0))}function G(n,r){return Object.keys(r).forEach(function(t){n[t]=r[t]}),n}function B(n,r){return function(){C(n,arguments,r)}}function C(n,r,t){var e=r[r.length-1];H(n.apply(null,r),g(e)?e:t)}function H(n,r){if(n===!1)throw new Error(r||"Assertion failed")}function J(n,r){return function(){function t(n,r){return n[r]=function(){if(e&&!cr[r].apply(null,arguments))throw e},n}var e;try{C(n,arguments,r)}catch(u){e=u}return{or:Object.keys(cr).reduce(t,{})}}}function K(n){return function(){return Q(n.apply(null,arguments))}}function Q(n){return!n}function U(n){var r=function(){return i(arguments[0])?n.apply(null,arguments):!0};return r._isMaybefied=!0,r}function W(n){return i(n)===!1?!0:n}function X(n){function r(){return!0}return function(){function t(n,t){return n[t]=e?r:cr[t],n}var e=n.apply(null,arguments);return{or:Object.keys(cr).reduce(t,{})}}}function Z(n,r,t){return function(){var e,u;if(e=arguments[0],!r(e))return!1;e=$(r,e),u=vr.call(arguments,1);try{e.forEach(function(r){if(("maybe"!==n||i(r))&&!t.apply(null,[r].concat(u)))throw 0})}catch(o){return!1}return!0}}function $(n,r){switch(n){case s:return vr.call(r);case u:return Object.keys(r).map(function(n){return r[n]});default:return r}}function nr(n,r){return rr([n,cr,r])}function rr(n){var r,t,e,u;return r=n.shift(),t=n.pop(),e=n.pop(),u=t||{},Object.keys(e).forEach(function(t){Object.defineProperty(u,t,{configurable:!1,enumerable:!0,writable:!1,value:r.apply(null,n.concat(e[t],ar[t]))})}),u}function tr(n,r){return rr([n,r,null])}function er(n){cr[n].of=rr([Z.bind(null,null),cr[n],cr,null])}function ur(n,r){yr.forEach(function(t){n[t].of=tr(r,cr[t].of)})}function ir(n){dr[n].of=rr([Z.bind(null,"maybe"),cr[n],cr,null]),lr.maybe[n].of=tr(B,dr[n].of),lr.not[n].of=tr(B,sr[n].of)}function or(r){"function"==typeof define&&define.amd?define(function(){return r}):"undefined"!=typeof module&&null!==module&&module.exports?module.exports=r:n.check=r}var ar,cr,fr,lr,sr,dr,br,yr,vr;ar={like:"Invalid type",instance:"Invalid type",emptyObject:"Invalid object",object:"Invalid object",assigned:"Invalid value",undefined:"Invalid value","null":"Invalid value",hasLength:"Invalid length",emptyArray:"Invalid array",array:"Invalid array",arrayLike:"Invalid array-like object",iterable:"Invalid iterable",date:"Invalid date",error:"Invalid error","function":"Invalid function",match:"Invalid string",contains:"Invalid string",nonEmptyString:"Invalid string",string:"Invalid string",odd:"Invalid number",even:"Invalid number",inRange:"Invalid number",greaterOrEqual:"Invalid number",lessOrEqual:"Invalid number",between:"Invalid number",greater:"Invalid number",less:"Invalid number",positive:"Invalid number",negative:"Invalid number",integer:"Invalid number",zero:"Invalid number",number:"Invalid number","boolean":"Invalid boolean"},cr={like:r,instance:t,emptyObject:e,object:u,assigned:i,undefined:o,"null":a,hasLength:c,emptyArray:f,array:l,arrayLike:s,iterable:d,date:b,error:y,"function":v,match:p,contains:m,nonEmptyString:g,string:I,odd:h,even:j,inRange:E,greaterOrEqual:k,lessOrEqual:w,between:N,greater:S,less:A,positive:L,negative:P,integer:O,zero:q,number:T,"boolean":_},fr={apply:x,map:z,all:R,any:D},yr=["array","arrayLike","iterable","object"],vr=Array.prototype.slice,fr=G(fr,cr),lr=nr(B,H),sr=nr(K,Q),dr=nr(U,W),br=nr(X),lr.not=tr(B,sr),lr.maybe=tr(B,dr),lr.either=tr(J,cr),yr.forEach(er),ur(lr,B),ur(sr,K),yr.forEach(ir),or(G(fr,{assert:lr,not:sr,maybe:dr,either:br}))}(this); |
Sorry, the diff of this file is too big to display
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
124422
2329
731