-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargvalid.js
8 lines (8 loc) · 2.73 KB
/
argvalid.js
1
2
3
4
5
6
7
8
/*!
* Copyright (c) Naufal Rabbani (http://github.com/BosNaufal)
* Licensed Under MIT (http://opensource.org/licenses/MIT)
*
* Argvalid @ Version 0.0.1
*
*/
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.argvalid=r():e.argvalid=r()}(this,function(){return function(e){function r(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,r),n.loaded=!0,n.exports}var t={};return r.m=e,r.c=t,r.p="../dist/",r(0)}([function(e,r){"use strict";function t(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function o(e){return"object"===("undefined"==typeof e?"undefined":a(e))&&"number"==typeof e.length}function n(e,r){var t=void 0;if(o(e)){var n=function(){for(var r=0,t=[];r<e.length;){var o={obj:e[r],validation:e[r+1]};t.push(o),r+=2}var n=t.map(function(e){return i(e.obj,e.validation)}),a={};return n.forEach(function(e){var r=Object.keys(e),t=e[r];a[r]=t}),{v:a}}();if("object"===("undefined"==typeof n?"undefined":a(n)))return n.v}else t=i(e,r);return t}function i(e,r){var n=r.type,i=r.required,u=r.defaultValue,f=r.validator,l=Object.keys(e)[0],c=e[l],d=void 0!==f&&"function"==typeof f,v=/function (\w+)/g,s=function(e){for(var r=void 0,t=void 0;r=v.exec(e.toString());)t=r[1];return t},p=void 0;if(o(n)&&!d?(p=n.map(function(e){return s(e)}),p=p.join(" or ")):d||(p=s(n)),void 0!==u&&null!==u){var b="function"==typeof u;c=b?u():u}var y=void 0!==c&&null!==c;if(i&&!y){if(!d)throw new Error('[Argvalid]: Variable "'+l+'" is required. Please fill it with a '+p);throw new Error('[Argvalid]: Variable "'+l+'" is required. Please fill it with a valid value to your custom validator')}var m="undefined"==typeof c?"undefined":a(c),h=void 0;switch(m){case"string":h=String;break;case"number":h=Number;break;case"boolean":h=Boolean;break;case"object":var w="number"==typeof c.length;if(w)h=Array;else{if(o(n))throw new Error("[Argvalid]: Array Types With Custom Constructor Is Not Supported Yet");h=n}}var g=new h(c),j=function(e){var r=void 0;if(r="function"!=typeof e?function(e,r){return e instanceof r}:function(r){return e(r.valueOf())},o(n)&&!e){var t=!1;return n.forEach(function(e){var o=r(g,e);o&&(t=!0)}),t}return r(g,n)};if(!j(f)){if(!d)throw new Error('[Argvalid]: Variable "'+l+'" should be a '+p+" but got "+m);throw new Error('[Argvalid]: Variable "'+l+'" is not valid with your custom validator')}return t({},l,c)}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=n}])});