Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rufflib-validate

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rufflib-validate - npm Package Compare versions

Comparing version 2.0.0 to 2.0.3

main.js

6

dist/rufflib-validate.es.js
/**
* rufflib-validate 2.0.0
* rufflib-validate 2.0.3
* A RuffLIB library for succinctly validating JavaScript values.

@@ -876,3 +876,3 @@ * https://richplastow.com/rufflib-validate

const NAME = 'Validate';
const VERSION = '2.0.0';
const VERSION = '2.0.3';

@@ -923,4 +923,2 @@

// rufflib-validate/src/entry-point-main.js
export { Validate as default };
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):((t="undefined"!=typeof globalThis?globalThis:t||self).rufflib=t.rufflib||{},t.rufflib.validate=t.rufflib.validate||{},t.rufflib.validate.main=n())}(this,(function(){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(n)}function n(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function r(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function e(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function a(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,n){if(!t)return;if("string"==typeof t)return c(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(t,n)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}
/**
* rufflib-validate 2.0.0
* rufflib-validate 2.0.3
* A RuffLIB library for succinctly validating JavaScript values.
* https://richplastow.com/rufflib-validate
* @license MIT
*/()}function c(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var i="array",o="boolean",s="integer",l="number",u="string",f="object",h="undefined";function y(n,r,e){var a=r.concat(e).join(".");return t(n)===h?"'".concat(a,"' of a value"):"".concat(n,".").concat(a)}function m(n,r,e,c,y){if(null===n||t(n)!==f||Array.isArray(n)){var b=v(n);return r||0!==e.length?r?0===e.length?"'".concat(r,"' is ").concat(b," not an object"):"'".concat(r,".").concat(e.join("."),"' is ").concat(b," not an object"):"'".concat(e.join("."),"' of the schema is ").concat(b," not an object"):"the schema is ".concat(b," not an object")}var d=n._meta;if(null===d||t(d)!==f||Array.isArray(d)){var g=v(d);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta' is ").concat(g," not an object"):"'".concat(r,".").concat(e.join("."),"._meta' is ").concat(g," not an object"):"'".concat(e.join("."),"._meta' of the schema is ").concat(g," not an object"):"top level '_meta' of the schema is ".concat(g," not an object")}var k=n._meta.inst;if(void 0!==k){if(null===k||"function"!==t(k)||Array.isArray(k)){var x=v(k);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta.inst' is ").concat(x," not type 'function'"):"'".concat(r,".").concat(e.join("."),"._meta.inst' is ").concat(x," not type 'function'"):"'".concat(e.join("."),"._meta.inst' of the schema is ").concat(x," not type 'function'"):"top level '._meta.inst' of the schema is ".concat(x," not type 'function'")}if("string"!=typeof k.name){var A=v(k.name);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta.inst.name' is ").concat(A," not 'string'"):"'".concat(r,".").concat(e.join("."),"._meta.inst.name' is ").concat(A," not 'string'"):"'".concat(e.join("."),"._meta.inst.name' of the schema is ").concat(A," not 'string'"):"top level '._meta.inst.name' of the schema is ".concat(A," not 'string'")}}for(var j in n){var _=n[j];if(null===_||t(_)!==f||Array.isArray(_))return p(r,e,j,"is ".concat(v(_)," not an object"));if("_meta"!==j)if(_._meta){var N=m(_,r,[].concat(a(e),[j]),c,y);if(N)return N}else{if(null===_.fallback)return p(r,e,j,"is null","fallback");if(null===_.max)return p(r,e,j,"is null","max");if(null===_.min)return p(r,e,j,"is null","min");if(null===_.rule)return p(r,e,j,"is null","rule");if(null===_.set)return p(r,e,j,"is null","set");var w=Array.isArray(_.fallback)?i:t(_.fallback),E=Array.isArray(_.max)?i:t(_.max),S=Array.isArray(_.min)?i:t(_.min),V=Array.isArray(_.rule)?i:t(_.rule),O=Array.isArray(_.set)?i:t(_.set),T=w!==h,I=E!==h,P=S!==h,C=V!==h,D=O!==h,R=I+P+C+D;if(R>1&&(2!==R||!I||!P))return p(r,e,j,"has '".concat(R,"' qualifiers, only 0 or 1 allowed"));switch(_.kind){case i:return"@TODO array";case o:if(w!==o&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(o,"' or '").concat(h,"'"));if(I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(h,"'"));if(P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(h,"'"));if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(h,"'"));if(D)return p(r,e,j,"has '".concat(O,"' set, not '").concat(h,"'"));break;case s:case l:if(w!==l&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(l,"' or '").concat(h,"'"));if(E!==l&&I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(l,"' or '").concat(h,"'"));if(S!==l&&P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(l,"' or '").concat(h,"'"));if(V===f){var q=t(_.rule.test);if("function"!==q)return p(r,e,j,"has '".concat(q,"' rule.test, not 'function'"))}else if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(f,"' or '").concat(h,"'"));if(O===i)for(var M=0,U=_.set.length;M<U;M++){var $=t(_.set[M]);if($!==l)return p(r,e,j,"has '".concat($,"' set[").concat(M,"], not '").concat(l,"'"))}else if(D)return p(r,e,j,"has '".concat(O,"' set, not an array or '").concat(h,"'"));break;case u:if(w!==u&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(u,"' or '").concat(h,"'"));if(E!==l&&I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(l,"' or '").concat(h,"'"));if(S!==l&&P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(l,"' or '").concat(h,"'"));if(V===f){var z=t(_.rule.test);if("function"!==z)return p(r,e,j,"has '".concat(z,"' rule.test, not 'function'"))}else if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(f,"' or '").concat(h,"'"));if(O===i)for(var B=0,F=_.set.length;B<F;B++){var G=t(_.set[B]);if(G!==u)return p(r,e,j,"has '".concat(G,"' set[").concat(B,"], not '").concat(u,"'"))}else if(D)return p(r,e,j,"has '".concat(O,"' set, not an array or '").concat(h,"'"));break;default:return p(r,e,j,"not recognised","kind")}}else if(c){var H=r&&e.length?"".concat(r,".").concat(e.join("."),"._meta"):r?"".concat(r,"._meta"):e.length?"".concat(e.join("."),"._meta"):"top level _meta";if(!y.object(_,H,c))return y.err.slice(y.prefix.length+2)}}return null}function p(t,n,r,e,a){return"'".concat(t?t+".":"").concat(0===n.length?"":n.join(".")+".").concat(r||"").concat(a?"."+a:"","'").concat(t?"":" of the schema"," ").concat(e)}function v(n){return null===n?"null":Array.isArray(n)?"an array":"type '".concat(t(n),"'")}var b=r((function t(n,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.err=null,this.prefix=n||"(anon)",this.skip=r||!1}));return e(b,"name","Validate"),e(b,"VERSION","2.0.0"),b.prototype._type=function(n,r,e){var a=t(n);if(a===e)return!0;var c="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";return this.err=null===n?"".concat(this.prefix,": ").concat(c," is null not type '").concat(e,"'"):Array.isArray(n)?"".concat(this.prefix,": ").concat(c," is an array not type '").concat(e,"'"):"".concat(this.prefix,": ").concat(c," is type '").concat(a,"' not '").concat(e,"'"),!1},b.prototype._validateAgainstSchema=function(n,r,e){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];if(e._meta.inst&&!(n instanceof e._meta.inst))return r||0!==a.length?r?0===a.length?this.err="".concat(this.prefix,": '").concat(r,"' is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": '").concat(r,".").concat(a.join("."),"' is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": '").concat(a.join("."),"' of the top level object is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": the top level object is not an instance of '").concat(e._meta.inst.name,"'"),!1;for(var c in e)if("_meta"!==c){var m=n[c],p=t(m),v=e[c];if(v._meta){if(null===m||p!==f||Array.isArray(m)){var b=y(r,a,c),d=" of a value"===b.slice(-11)?b:"'".concat(b,"'"),g=null===m?"null":p!==f?"type '".concat(p,"'"):"an array";return this.err="".concat(this.prefix,": ").concat(d," is ").concat(g," not an object"),!1}if(!this._validateAgainstSchema(m,r,v,a.concat(c)))return!1}else{var k=t(v.fallback),x=k!==h,A=p===h;if(!x||!A){var j=y(r,a,c);switch(v.kind){case i:return"@TODO array";case o:if(!this.boolean(m,j))return!1;continue;case s:case l:case u:var _=t(v.max)!==h,N=t(v.min)!==h;if(_&&N){if(!this[v.kind](m,j,v.min,v.max))return!1}else if(N){if(!this[v.kind](m,j,v.min))return!1}else if(_){if(!this[v.kind](m,j,void 0,v.max))return!1}else if(v.rule){if(!this[v.kind](m,j,v.rule))return!1}else if(v.set){if(!this[v.kind](m,j,v.set))return!1}else if(!this[v.kind](m,j))return!1;continue;default:throw this.err="oops!!",Error(this.err)}}}}return!0},b.prototype.array=function(n,r){if(this.err=null,this.skip)return!0;if(!Array.isArray(n)){var e="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";return this.err=null===n?"".concat(this.prefix,": ").concat(e," is null not an array"):"".concat(this.prefix,": ").concat(e," is type '").concat(t(n),"' not an array"),!1}for(var c=arguments.length,i=new Array(c>2?c-2:0),o=2;o<c;o++)i[o-2]=arguments[o];var s=i.length;if(!s)return!0;var l=0,u=1/0,f=null,h=[],y=t(i[0]),m="function"===y?"fn":"number"===y?"num":null==i[0]?"null":"other",p=t(i[1]),v="function"===p?"fn":"number"===p?"num":null==i[1]?"null":"other",b=t(i[2]),d="function"===b?"fn":"number"===b?"num":null==i[2]?"null":"other";switch("".concat(m,",").concat(v,",").concat(d)){case"null,null,null":for(var g=3;g<s;g++)if(null!=i[g])throw this.err="Validate.array() incorrectly invoked 1: args[".concat(g,"] not nullish!"),Error(this.err);return!0;case"num,null,null":for(var k=3;k<s;k++)if(null!=i[k])throw this.err="Validate.array() incorrectly invoked 2: args[".concat(k,"] not nullish!"),Error(this.err);l=i[0];break;case"num,num,null":for(var x=3;x<s;x++)if(null!=i[x])throw this.err="Validate.array() incorrectly invoked 3: args[".concat(x,"] not nullish!"),Error(this.err);l=i[0],u=i[1];break;case"null,num,null":for(var A=3;A<s;A++)if(null!=i[A])throw this.err="Validate.array() incorrectly invoked 4: args[".concat(A,"] not nullish!"),Error(this.err);u=i[1];break;case"num,num,fn":l=i[0],u=i[1],f=i[2],h=i.slice(3);break;case"num,null,fn":l=i[0],f=i[2],h=i.slice(3);break;case"null,num,fn":u=i[1],f=i[2],h=i.slice(3);break;default:if("fn"===m)f=i[0],h=i.slice(1);else{if("num"!==m||"fn"!==v)throw this.err="Validate.array() incorrectly invoked 5: args is not one of the nine configurations!",Error(this.err);l=i[0],f=i[1],h=i.slice(2)}}if(Number.isNaN(l))throw this.err="Validate.array() incorrectly invoked: min is NaN!",Error(this.err);if(Number.isNaN(u))throw this.err="Validate.array() incorrectly invoked: max is NaN!",Error(this.err);if(n.length<l){var j=r?"'".concat(r,"'"):"array";return this.err="".concat(this.prefix,": ").concat(j," length ").concat(n.length," is < ").concat(l),!1}if(n.length>u){var _=r?"'".concat(r,"'"):"array";return this.err="".concat(this.prefix,": ").concat(_," length ").concat(n.length," is > ").concat(u),!1}if(null==f)return!0;for(var N=r||"",w=0,E=n.length;w<E;w++)if(!f.bind(this).apply(void 0,[n[w],"".concat(N,"[").concat(w,"]")].concat(a(h))))return!1;return!0},b.prototype.boolean=function(t,n){return this.err=null,!!this.skip||this._type(t,n,"boolean")},b.prototype.class=function(n,r,e){if(this.err=null,this.skip)return!0;if(t(r)!==u||" of a value"===r.slice(-11)||"'".concat(r,"'"),!this._type(n,r,"function"))return!1;if(t(e)===h)return!0;if(!this.schema(e,"schema"))throw Error("Validate.class() incorrectly invoked: ".concat(this.err));return!!this._validateAgainstSchema(n,r,e)},b.prototype.integer=function(t,n,r,e){if(this.err=null,this.skip)return!0;if(!this.number(t,n,r,e))return!1;if(0!=t%1){var a="string"==typeof n?" of a value"===n.slice(-11)?n:"'".concat(n,"'"):"number";return this.err="".concat(this.prefix,": ").concat(a," ").concat(t," is not an integer"),!1}return!0},b.prototype.number=function(n,r,e,a){if(this.err=null,this.skip)return!0;if(!this._type(n,r,"number"))return!1;if(Number.isNaN(n))return this.err="".concat(this.prefix,": '").concat(r,"' is NaN, not a valid number"),!1;var c="object"===t(e)&&null!=e,i="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"number";if(c&&Array.isArray(e)){if(-1!==e.indexOf(n))return!0;var o="[".concat(e,"]");return o=o.length<21?o:"".concat(o.slice(0,12),"...").concat(o.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is not in ").concat(o),!1}if(c&&"function"==typeof e.test){if(e.test(n))return!0;var s="".concat(e.test);return s=s.length<21?s:"".concat(s.slice(0,12),"...").concat(s.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(n," fails ").concat(s),!1}if("number"==typeof e){var l=e;if(Number.isNaN(l))throw this.err="Validate.number() incorrectly invoked: min is NaN!",Error(this.err);if(n<l)return this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is < ").concat(l),!1}if("number"==typeof a){if(Number.isNaN(a))throw this.err="Validate.number() incorrectly invoked: max is NaN!",Error(this.err);if(n>a)return this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is > ").concat(a),!1}return!0},b.prototype.object=function(n,r,e){if(this.err=null,this.skip)return!0;var a=t(r)===u?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";if(null===n)return this.err="".concat(this.prefix,": ").concat(a," is null not an object"),!1;if(Array.isArray(n))return this.err="".concat(this.prefix,": ").concat(a," is an array not an object"),!1;if(!this._type(n,r,"object"))return!1;if(t(e)===h)return!0;if(!this.schema(e,"schema"))throw Error("Validate.object() incorrectly invoked: ".concat(this.err));return!!this._validateAgainstSchema(n,r,e)},b.prototype.schema=function(n,r,e){if(this.err=null,this.skip)return!0;if(t(e)!==h&&(null===e||t(e)!==f||Array.isArray(e))){var a=v(e);throw Error("Validate.schema() incorrectly invoked: ".concat(this.prefix,": ")+"optional 'metaSchema' is ".concat(a," not an object"))}var c=m(n,r,[],e,this);return!c||(this.err="".concat(this.prefix,": ").concat(c),!1)},b.prototype.string=function(n,r,e,a){if(this.err=null,this.skip)return!0;if(!this._type(n,r,"string"))return!1;var c="object"===t(e)&&null!=e,i="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"string";if(c&&Array.isArray(e)){if(-1!==e.indexOf(n))return!0;var o='"'.concat(n,'"');o=o.length<21?o:"".concat(o.slice(0,12),"...").concat(o.slice(-5));var s="[".concat(e,"]");return s=s.length<21?s:"".concat(s.slice(0,12),"...").concat(s.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(o," is not in ").concat(s),!1}if(c&&"function"==typeof e.test){if(e.test(n))return!0;var l='"'.concat(n,'"');l=l.length<21?l:"".concat(l.slice(0,12),"...").concat(l.slice(-5));var u="".concat(e instanceof RegExp?e:e.test);return u=u.length<21?u:"".concat(u.slice(0,12),"...").concat(u.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(l," fails ").concat(u),!1}if("number"==typeof e){var f=e;if(Number.isNaN(f))throw this.err="Validate.string() incorrectly invoked: min is NaN!",Error(this.err);if(n.length<f)return this.err="".concat(this.prefix,": ").concat(i," length ").concat(n.length," is < ").concat(f),!1}if("number"==typeof a){if(Number.isNaN(a))throw this.err="Validate.string() incorrectly invoked: max is NaN!",Error(this.err);if(n.length>a)return this.err="".concat(this.prefix,": ").concat(i," length ").concat(n.length," is > ").concat(a),!1}return!0},b}));
*/()}function c(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}var i="array",o="boolean",s="integer",l="number",u="string",f="object",h="undefined";function y(n,r,e){var a=r.concat(e).join(".");return t(n)===h?"'".concat(a,"' of a value"):"".concat(n,".").concat(a)}function m(n,r,e,c,y){if(null===n||t(n)!==f||Array.isArray(n)){var b=v(n);return r||0!==e.length?r?0===e.length?"'".concat(r,"' is ").concat(b," not an object"):"'".concat(r,".").concat(e.join("."),"' is ").concat(b," not an object"):"'".concat(e.join("."),"' of the schema is ").concat(b," not an object"):"the schema is ".concat(b," not an object")}var d=n._meta;if(null===d||t(d)!==f||Array.isArray(d)){var g=v(d);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta' is ").concat(g," not an object"):"'".concat(r,".").concat(e.join("."),"._meta' is ").concat(g," not an object"):"'".concat(e.join("."),"._meta' of the schema is ").concat(g," not an object"):"top level '_meta' of the schema is ".concat(g," not an object")}var k=n._meta.inst;if(void 0!==k){if(null===k||"function"!==t(k)||Array.isArray(k)){var x=v(k);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta.inst' is ").concat(x," not type 'function'"):"'".concat(r,".").concat(e.join("."),"._meta.inst' is ").concat(x," not type 'function'"):"'".concat(e.join("."),"._meta.inst' of the schema is ").concat(x," not type 'function'"):"top level '._meta.inst' of the schema is ".concat(x," not type 'function'")}if("string"!=typeof k.name){var A=v(k.name);return r||0!==e.length?r?0===e.length?"'".concat(r,"._meta.inst.name' is ").concat(A," not 'string'"):"'".concat(r,".").concat(e.join("."),"._meta.inst.name' is ").concat(A," not 'string'"):"'".concat(e.join("."),"._meta.inst.name' of the schema is ").concat(A," not 'string'"):"top level '._meta.inst.name' of the schema is ".concat(A," not 'string'")}}for(var j in n){var _=n[j];if(null===_||t(_)!==f||Array.isArray(_))return p(r,e,j,"is ".concat(v(_)," not an object"));if("_meta"!==j)if(_._meta){var N=m(_,r,[].concat(a(e),[j]),c,y);if(N)return N}else{if(null===_.fallback)return p(r,e,j,"is null","fallback");if(null===_.max)return p(r,e,j,"is null","max");if(null===_.min)return p(r,e,j,"is null","min");if(null===_.rule)return p(r,e,j,"is null","rule");if(null===_.set)return p(r,e,j,"is null","set");var w=Array.isArray(_.fallback)?i:t(_.fallback),E=Array.isArray(_.max)?i:t(_.max),S=Array.isArray(_.min)?i:t(_.min),V=Array.isArray(_.rule)?i:t(_.rule),O=Array.isArray(_.set)?i:t(_.set),T=w!==h,I=E!==h,P=S!==h,C=V!==h,D=O!==h,R=I+P+C+D;if(R>1&&(2!==R||!I||!P))return p(r,e,j,"has '".concat(R,"' qualifiers, only 0 or 1 allowed"));switch(_.kind){case i:return"@TODO array";case o:if(w!==o&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(o,"' or '").concat(h,"'"));if(I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(h,"'"));if(P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(h,"'"));if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(h,"'"));if(D)return p(r,e,j,"has '".concat(O,"' set, not '").concat(h,"'"));break;case s:case l:if(w!==l&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(l,"' or '").concat(h,"'"));if(E!==l&&I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(l,"' or '").concat(h,"'"));if(S!==l&&P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(l,"' or '").concat(h,"'"));if(V===f){var q=t(_.rule.test);if("function"!==q)return p(r,e,j,"has '".concat(q,"' rule.test, not 'function'"))}else if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(f,"' or '").concat(h,"'"));if(O===i)for(var M=0,U=_.set.length;M<U;M++){var $=t(_.set[M]);if($!==l)return p(r,e,j,"has '".concat($,"' set[").concat(M,"], not '").concat(l,"'"))}else if(D)return p(r,e,j,"has '".concat(O,"' set, not an array or '").concat(h,"'"));break;case u:if(w!==u&&T)return p(r,e,j,"has '".concat(w,"' fallback, not '").concat(u,"' or '").concat(h,"'"));if(E!==l&&I)return p(r,e,j,"has '".concat(E,"' max, not '").concat(l,"' or '").concat(h,"'"));if(S!==l&&P)return p(r,e,j,"has '".concat(S,"' min, not '").concat(l,"' or '").concat(h,"'"));if(V===f){var z=t(_.rule.test);if("function"!==z)return p(r,e,j,"has '".concat(z,"' rule.test, not 'function'"))}else if(C)return p(r,e,j,"has '".concat(V,"' rule, not '").concat(f,"' or '").concat(h,"'"));if(O===i)for(var B=0,F=_.set.length;B<F;B++){var G=t(_.set[B]);if(G!==u)return p(r,e,j,"has '".concat(G,"' set[").concat(B,"], not '").concat(u,"'"))}else if(D)return p(r,e,j,"has '".concat(O,"' set, not an array or '").concat(h,"'"));break;default:return p(r,e,j,"not recognised","kind")}}else if(c){var H=r&&e.length?"".concat(r,".").concat(e.join("."),"._meta"):r?"".concat(r,"._meta"):e.length?"".concat(e.join("."),"._meta"):"top level _meta";if(!y.object(_,H,c))return y.err.slice(y.prefix.length+2)}}return null}function p(t,n,r,e,a){return"'".concat(t?t+".":"").concat(0===n.length?"":n.join(".")+".").concat(r||"").concat(a?"."+a:"","'").concat(t?"":" of the schema"," ").concat(e)}function v(n){return null===n?"null":Array.isArray(n)?"an array":"type '".concat(t(n),"'")}var b=r((function t(n,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),this.err=null,this.prefix=n||"(anon)",this.skip=r||!1}));return e(b,"name","Validate"),e(b,"VERSION","2.0.3"),b.prototype._type=function(n,r,e){var a=t(n);if(a===e)return!0;var c="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";return this.err=null===n?"".concat(this.prefix,": ").concat(c," is null not type '").concat(e,"'"):Array.isArray(n)?"".concat(this.prefix,": ").concat(c," is an array not type '").concat(e,"'"):"".concat(this.prefix,": ").concat(c," is type '").concat(a,"' not '").concat(e,"'"),!1},b.prototype._validateAgainstSchema=function(n,r,e){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];if(e._meta.inst&&!(n instanceof e._meta.inst))return r||0!==a.length?r?0===a.length?this.err="".concat(this.prefix,": '").concat(r,"' is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": '").concat(r,".").concat(a.join("."),"' is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": '").concat(a.join("."),"' of the top level object is not an instance of '").concat(e._meta.inst.name,"'"):this.err="".concat(this.prefix,": the top level object is not an instance of '").concat(e._meta.inst.name,"'"),!1;for(var c in e)if("_meta"!==c){var m=n[c],p=t(m),v=e[c];if(v._meta){if(null===m||p!==f||Array.isArray(m)){var b=y(r,a,c),d=" of a value"===b.slice(-11)?b:"'".concat(b,"'"),g=null===m?"null":p!==f?"type '".concat(p,"'"):"an array";return this.err="".concat(this.prefix,": ").concat(d," is ").concat(g," not an object"),!1}if(!this._validateAgainstSchema(m,r,v,a.concat(c)))return!1}else{var k=t(v.fallback),x=k!==h,A=p===h;if(!x||!A){var j=y(r,a,c);switch(v.kind){case i:return"@TODO array";case o:if(!this.boolean(m,j))return!1;continue;case s:case l:case u:var _=t(v.max)!==h,N=t(v.min)!==h;if(_&&N){if(!this[v.kind](m,j,v.min,v.max))return!1}else if(N){if(!this[v.kind](m,j,v.min))return!1}else if(_){if(!this[v.kind](m,j,void 0,v.max))return!1}else if(v.rule){if(!this[v.kind](m,j,v.rule))return!1}else if(v.set){if(!this[v.kind](m,j,v.set))return!1}else if(!this[v.kind](m,j))return!1;continue;default:throw this.err="oops!!",Error(this.err)}}}}return!0},b.prototype.array=function(n,r){if(this.err=null,this.skip)return!0;if(!Array.isArray(n)){var e="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";return this.err=null===n?"".concat(this.prefix,": ").concat(e," is null not an array"):"".concat(this.prefix,": ").concat(e," is type '").concat(t(n),"' not an array"),!1}for(var c=arguments.length,i=new Array(c>2?c-2:0),o=2;o<c;o++)i[o-2]=arguments[o];var s=i.length;if(!s)return!0;var l=0,u=1/0,f=null,h=[],y=t(i[0]),m="function"===y?"fn":"number"===y?"num":null==i[0]?"null":"other",p=t(i[1]),v="function"===p?"fn":"number"===p?"num":null==i[1]?"null":"other",b=t(i[2]),d="function"===b?"fn":"number"===b?"num":null==i[2]?"null":"other";switch("".concat(m,",").concat(v,",").concat(d)){case"null,null,null":for(var g=3;g<s;g++)if(null!=i[g])throw this.err="Validate.array() incorrectly invoked 1: args[".concat(g,"] not nullish!"),Error(this.err);return!0;case"num,null,null":for(var k=3;k<s;k++)if(null!=i[k])throw this.err="Validate.array() incorrectly invoked 2: args[".concat(k,"] not nullish!"),Error(this.err);l=i[0];break;case"num,num,null":for(var x=3;x<s;x++)if(null!=i[x])throw this.err="Validate.array() incorrectly invoked 3: args[".concat(x,"] not nullish!"),Error(this.err);l=i[0],u=i[1];break;case"null,num,null":for(var A=3;A<s;A++)if(null!=i[A])throw this.err="Validate.array() incorrectly invoked 4: args[".concat(A,"] not nullish!"),Error(this.err);u=i[1];break;case"num,num,fn":l=i[0],u=i[1],f=i[2],h=i.slice(3);break;case"num,null,fn":l=i[0],f=i[2],h=i.slice(3);break;case"null,num,fn":u=i[1],f=i[2],h=i.slice(3);break;default:if("fn"===m)f=i[0],h=i.slice(1);else{if("num"!==m||"fn"!==v)throw this.err="Validate.array() incorrectly invoked 5: args is not one of the nine configurations!",Error(this.err);l=i[0],f=i[1],h=i.slice(2)}}if(Number.isNaN(l))throw this.err="Validate.array() incorrectly invoked: min is NaN!",Error(this.err);if(Number.isNaN(u))throw this.err="Validate.array() incorrectly invoked: max is NaN!",Error(this.err);if(n.length<l){var j=r?"'".concat(r,"'"):"array";return this.err="".concat(this.prefix,": ").concat(j," length ").concat(n.length," is < ").concat(l),!1}if(n.length>u){var _=r?"'".concat(r,"'"):"array";return this.err="".concat(this.prefix,": ").concat(_," length ").concat(n.length," is > ").concat(u),!1}if(null==f)return!0;for(var N=r||"",w=0,E=n.length;w<E;w++)if(!f.bind(this).apply(void 0,[n[w],"".concat(N,"[").concat(w,"]")].concat(a(h))))return!1;return!0},b.prototype.boolean=function(t,n){return this.err=null,!!this.skip||this._type(t,n,"boolean")},b.prototype.class=function(n,r,e){if(this.err=null,this.skip)return!0;if(t(r)!==u||" of a value"===r.slice(-11)||"'".concat(r,"'"),!this._type(n,r,"function"))return!1;if(t(e)===h)return!0;if(!this.schema(e,"schema"))throw Error("Validate.class() incorrectly invoked: ".concat(this.err));return!!this._validateAgainstSchema(n,r,e)},b.prototype.integer=function(t,n,r,e){if(this.err=null,this.skip)return!0;if(!this.number(t,n,r,e))return!1;if(0!=t%1){var a="string"==typeof n?" of a value"===n.slice(-11)?n:"'".concat(n,"'"):"number";return this.err="".concat(this.prefix,": ").concat(a," ").concat(t," is not an integer"),!1}return!0},b.prototype.number=function(n,r,e,a){if(this.err=null,this.skip)return!0;if(!this._type(n,r,"number"))return!1;if(Number.isNaN(n))return this.err="".concat(this.prefix,": '").concat(r,"' is NaN, not a valid number"),!1;var c="object"===t(e)&&null!=e,i="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"number";if(c&&Array.isArray(e)){if(-1!==e.indexOf(n))return!0;var o="[".concat(e,"]");return o=o.length<21?o:"".concat(o.slice(0,12),"...").concat(o.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is not in ").concat(o),!1}if(c&&"function"==typeof e.test){if(e.test(n))return!0;var s="".concat(e.test);return s=s.length<21?s:"".concat(s.slice(0,12),"...").concat(s.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(n," fails ").concat(s),!1}if("number"==typeof e){var l=e;if(Number.isNaN(l))throw this.err="Validate.number() incorrectly invoked: min is NaN!",Error(this.err);if(n<l)return this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is < ").concat(l),!1}if("number"==typeof a){if(Number.isNaN(a))throw this.err="Validate.number() incorrectly invoked: max is NaN!",Error(this.err);if(n>a)return this.err="".concat(this.prefix,": ").concat(i," ").concat(n," is > ").concat(a),!1}return!0},b.prototype.object=function(n,r,e){if(this.err=null,this.skip)return!0;var a=t(r)===u?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"a value";if(null===n)return this.err="".concat(this.prefix,": ").concat(a," is null not an object"),!1;if(Array.isArray(n))return this.err="".concat(this.prefix,": ").concat(a," is an array not an object"),!1;if(!this._type(n,r,"object"))return!1;if(t(e)===h)return!0;if(!this.schema(e,"schema"))throw Error("Validate.object() incorrectly invoked: ".concat(this.err));return!!this._validateAgainstSchema(n,r,e)},b.prototype.schema=function(n,r,e){if(this.err=null,this.skip)return!0;if(t(e)!==h&&(null===e||t(e)!==f||Array.isArray(e))){var a=v(e);throw Error("Validate.schema() incorrectly invoked: ".concat(this.prefix,": ")+"optional 'metaSchema' is ".concat(a," not an object"))}var c=m(n,r,[],e,this);return!c||(this.err="".concat(this.prefix,": ").concat(c),!1)},b.prototype.string=function(n,r,e,a){if(this.err=null,this.skip)return!0;if(!this._type(n,r,"string"))return!1;var c="object"===t(e)&&null!=e,i="string"==typeof r?" of a value"===r.slice(-11)?r:"'".concat(r,"'"):"string";if(c&&Array.isArray(e)){if(-1!==e.indexOf(n))return!0;var o='"'.concat(n,'"');o=o.length<21?o:"".concat(o.slice(0,12),"...").concat(o.slice(-5));var s="[".concat(e,"]");return s=s.length<21?s:"".concat(s.slice(0,12),"...").concat(s.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(o," is not in ").concat(s),!1}if(c&&"function"==typeof e.test){if(e.test(n))return!0;var l='"'.concat(n,'"');l=l.length<21?l:"".concat(l.slice(0,12),"...").concat(l.slice(-5));var u="".concat(e instanceof RegExp?e:e.test);return u=u.length<21?u:"".concat(u.slice(0,12),"...").concat(u.slice(-5)),this.err="".concat(this.prefix,": ").concat(i," ").concat(l," fails ").concat(u),!1}if("number"==typeof e){var f=e;if(Number.isNaN(f))throw this.err="Validate.string() incorrectly invoked: min is NaN!",Error(this.err);if(n.length<f)return this.err="".concat(this.prefix,": ").concat(i," length ").concat(n.length," is < ").concat(f),!1}if("number"==typeof a){if(Number.isNaN(a))throw this.err="Validate.string() incorrectly invoked: max is NaN!",Error(this.err);if(n.length>a)return this.err="".concat(this.prefix,": ").concat(i," length ").concat(n.length," is > ").concat(a),!1}return!0},b}));
{
"name": "rufflib-validate",
"version": "2.0.0",
"version": "2.0.3",
"description": "A RuffLIB library for succinctly validating JavaScript values.",
"main": "dist/rufflib-validate.es.js",
"main": "main.js",
"type": "module",
"scripts": {
"build": "npm run clean && rollup -c && mkdir docs/dist && cp dist/* docs/dist",
"clean": "rm -r dist; rm -r docs/dist; rm -r docs/test",
"test:docs": "node docs/run-nodejs-tests.js # test docs/ using NodeJS",
"test:src": "node src/run-nodejs-tests.js # test src/ using NodeJS",
"test": "[ -z $npm_config_src ]&&D=docs||D=src;npm run test:$D"
"build": "npm run clean && rollup -c && npm run build:css && npm run build:module && npm run build:static",
"build:css": "node scripts/build-css.js",
"build:module": "cp node_modules/rufflib-expect/dist/rufflib-expect.umd.es5.min.js docs/test",
"build:static": "cp -r {dist,src/docs/{index.html,img,test}} docs",
"clean": "rm -r dist ||:; rm -r docs ||:",
"test:dist": "node docs/test/run-nodejs-tests.js # test dist/ using NodeJS",
"test:src": "node src/docs/test/run-nodejs-tests.js # test src/ using NodeJS",
"test": "[ -z $npm_config_src ]&&D=dist||D=src;npm run test:$D"
},

@@ -32,3 +35,3 @@ "keywords": [

"@rollup/plugin-babel": "^5.3.1",
"rollup-plugin-copy": "^2.0.1",
"csso": "^5.0.4",
"rollup-plugin-terser": "^7.0.2",

@@ -35,0 +38,0 @@ "rufflib-expect": "^3.0.0"

@@ -5,7 +5,7 @@ # RuffLIB Validate

▶&nbsp; __Version:__ 2.0.0
▶&nbsp; __Version:__ 2.0.3
▶&nbsp; __Homepage:__ <https://richplastow.com/rufflib-validate>
▶&nbsp; __NPM:__ <https://www.npmjs.com/package/rufflib-validate>
▶&nbsp; __Repo:__ <https://github.com/richplastow/rufflib-validate>
▶&nbsp; __Tests:__ <https://richplastow.com/rufflib-validate/run-browser-tests.html>
▶&nbsp; __Tests:__ <https://richplastow.com/rufflib-validate/test/run-browser-tests.html>

@@ -12,0 +12,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc