conditional
Version:
A preconditions package based on Google's Preconditions library
5 lines • 7.71 kB
JavaScript
// Preconditions (version 5.3.0)
// https://github.com/anshulverma/conditional
// License MIT
// Copyright 2014 Anshul Verma
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.preconditions=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){(function(){var c,d;try{c=a("debug")}catch(e){d=e,c=function(a){return function(b){return console.log(""+a+" :: "+b)}}}b.exports=c("conditional")}).call(this)},{debug:"debug"}],2:[function(a,b){(function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={}.hasOwnProperty,K=function(a,b){function c(){this.constructor=a}for(var d in b)J.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},L=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};I=a("./util"),D=I.isObject,w=I.isArray,z=I.isNotArray,C=I.isNumeric,F=I.isString,x=I.isEmptyString,B=I.isNotUndefined,G=I.isUndefined,y=I.isEqual,A=I.isNotPrimitive,E=I.isPrimitive,H=I.xor,v=a("./debug_wrapper"),g=function(a){if(null!=a)throw a},e=function(){function a(a,c,d,e){this.name=a,this.defaultMessage=c,this.negate=null!=d?d:!1,this.argc=null!=e?e:1,b.exports[this.name]=function(a){return function(){return a.check.apply(a,arguments)}}(this),v("registered checker '"+this.name+"'")}return a.prototype.check=function(){var a,b,c,d,e,f,h,i;for(e=arguments[this.argc],c=arguments[this.argc+1]||g,"function"==typeof e&&(c=e,e=null),b=[],i=Array.prototype.splice.call(arguments,0,this.argc),f=0,h=i.length;h>f;f++)a=i[f],Array.prototype.push.call(b,a);null==e&&(e=this.getErrorMessage.apply(this,b));try{return H(this.doCheck.apply(this,b),this.negate)||this.invokeError(e),c(null)}catch(j){return d=j,c(d)}},a.prototype.invokeError=function(){throw new Error("something went wrong")},a.prototype.doCheck=function(){return!1},a.prototype.getErrorMessage=function(){return"function"==typeof this.defaultMessage?this.defaultMessage.apply(this,arguments):this.defaultMessage},a}(),d=function(a){function b(a,c,d){null==d&&(d=h.INVALID_ARGUMENT),b.__super__.constructor.call(this,a,d,c)}return K(b,a),b.prototype.doCheck=function(a){return F(a)||C(a)||a},b.prototype.invokeError=function(a){throw new l(a)},b}(e),q=function(a){function b(a,c,d){null==d&&(d=h.INVALID_TYPE),b.__super__.constructor.call(this,a,d,c)}return K(b,a),b.prototype.doCheck=function(a){return C(a)},b.prototype.invokeError=function(a){throw new o(a)},b}(e),f=function(a){function b(a,c,d){b.__super__.constructor.call(this,a,d,c,2)}return K(b,a),b.prototype.doCheck=function(a,b){switch(u.check(b,"invalid collection value"),!1){case!F(b):return!(!F(a)||a.length>b.length||x(b)^x(a)||!(x(b)||L.call(b,a)>=0));case!w(b):return L.call(b,a)>=0;case!C(b):return~b.toString().indexOf(a);default:return a in b}},b.prototype.invokeError=function(a){throw new t(a)},b}(e),k=function(a){function b(a,c,d){b.__super__.constructor.call(this,a,d,c,2)}return K(b,a),b.prototype.doCheck=function(a,b){return u.check(B(b),"invalid value expected"),y(a,b)},b.prototype.invokeError=function(a){throw new t(a)},b}(e),i=function(a){function b(a,c,d){null==d&&(d=h.UNDEFINED_VALUE),b.__super__.constructor.call(this,a,d,c)}return K(b,a),b.prototype.doCheck=function(a){return B(a)},b.prototype.invokeError=function(a){throw new s(a)},b}(e),j=function(a){function b(a,c,d){null==d&&(d=h.ILLEGAL_VALUE),b.__super__.constructor.call(this,a,d,c)}return K(b,a),b.prototype.doCheck=function(a){return null===a||G(a)||A(a)&&(hasOwnProperty.call(a,"length")&&0===a.length||"object"==typeof a&&0===Object.keys(a).length)},b.prototype.invokeError=function(a){throw new n(a)},b}(e),r=function(a){function b(a){b.__super__.constructor.call(this,a,!1,h.ILLEGAL_STATE)}return K(b,a),b.prototype.invokeError=function(a){throw new m(a)},b}(d),p=function(a){function b(a,c,d){null==d&&(d=h.NULL_VALUE),b.__super__.constructor.call(this,a,d,c)}return K(b,a),b.prototype.doCheck=function(a){return G(a)||null===a},b.prototype.invokeError=function(a){throw new n(a)},b}(e),h={INVALID_ARGUMENT:"invalid argument",INVALID_TYPE:"invalid type",UNKNOWN_VALUE:"unknown value",UNDEFINED_VALUE:"undefined value",ILLEGAL_VALUE:"illegal value",ILLEGAL_STATE:"illegal state",NULL_VALUE:"value is null"},c=function(a){var b,c;return this.message=a,Error.call(this),Error.captureStackTrace(this,arguments.callee),this.name=(null!=(b=arguments.callee)&&null!=(c=b.caller)?c.name:void 0)||"Error"},c.prototype.__proto__=Error.prototype,l=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),o=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),t=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),s=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),n=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),m=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return K(b,a),b}(c),u=new d("checkArgument"),new q("checkNumberType"),new q("checkNotNumberType",!0),new f("checkContains",!1,function(a){return"unknown value '"+a+"'"}),new f("checkDoesNotContain",!0,function(a){return"'"+a+"' is a known value"}),new k("checkEquals",!1,function(a,b){return"expected '"+b+"' but got '"+a+"'"}),new k("checkDoesNotEqual",!0,function(a){return"did not expect value '"+a+"'"}),new i("checkDefined"),new i("checkUndefined",!0,function(a){return"'"+a+"' is a defined value"}),new j("checkEmpty",!1,function(a){return"'"+a+"' is not empty"}),new j("checkNotEmpty",!0),new r("checkState"),new p("checkNull",!1,function(a){return"'"+a+"' is not null"}),new p("checkNotNull",!0),b.exports.IllegalArgumentError=l,b.exports.InvalidTypeError=o,b.exports.UnknownValueError=t,b.exports.UndefinedValueError=s,b.exports.IllegalValueError=n,b.exports.IllegalStateError=m}).call(this)},{"./debug_wrapper":1,"./util":3}],3:[function(a,b){(function(){var a,c,d,e,f,g,h,i,j,k,l,m,n,o;m=function(a){return function(b){return!a(b)}},i=function(a){return null!=a&&"object"==typeof a},a=Array.isArray,f=m(a),h=function(b){return!a(b)&&b-parseFloat(b)+1>=0},c=function(a){return"boolean"==typeof a},n=Object.prototype.toString,k=function(a){return"[object String]"===n.call(a)},d=function(a){return k(a)&&!a},l=function(a){return"undefined"==typeof a},g=m(l),e=function(b,c){var d,h,j,k,l;switch(!1){case!a(c):if(f(b)||b.length!==c.length)return!1;for(d=k=0,l=c.length;l>=0?l>k:k>l;d=l>=0?++k:--k)if(!e(b[d],c[d])||!g(b[d]))return!1;break;case!i(c):for(h in c)if(j=c[h],!e(b[h],j))return!1;break;case b===c:return!1}return!0},j=function(a){return h(a)||c(a)},o=function(a,b){return!a!=!b},b.exports.negate=m,b.exports.isObject=i,b.exports.isArray=a,b.exports.isNotArray=f,b.exports.isNumeric=h,b.exports.isString=k,b.exports.isEmptyString=d,b.exports.isUndefined=l,b.exports.isNotUndefined=g,b.exports.isEqual=e,b.exports.isPrimitive=j,b.exports.isNotPrimitive=m(j),b.exports.xor=o}).call(this)},{}]},{},[2])(2)});