-
Notifications
You must be signed in to change notification settings - Fork 2
/
typecast.min.js
1 lines (1 loc) · 10.1 KB
/
typecast.min.js
1
(function(e,t){if(typeof exports=="object")return module.exports=t(e);if(typeof define=="function"&&define.amd)return define(["type"],t);e.type=t(e)})(window||this,function(e){var t,n,r,i,s,o=function(){},u=e&&e.console&&e.console.log?e.console.log:o,f=function(e){return function(){return e}},l=function(e){return function(t){return e===t}},c=function(e){return function(t){var n=s[e];return t===n.a()||t!=n.a()&&n.to(t)===n.a()}};return e._?(n=e._,e.Math?(r=e.Math,e.JSON?(i=e.JSON,s=function(e){return s.arr(e)?"array":s.nan(e)?"nan":s.nul(e)?"null":s.args(e)?"arguments":typeof e},s.extend=function(e){var t=!1;s[e.name]||(t=!0,s[e.name]=e.is),e.inherits&&(e.inherits instanceof Array||(e.inherits=[e.inherits]),n.each(e.inherits,function(t){n.extend(s[e.name],s[t])})),e.methods&&n.extend(s[e.name],e.methods),t&&(s[e.name].a=f(e.a),s[e.name].to=e.to,s[e.name].can=e.can)},s.extend({"name":"nul","a":null,"is":n.isNull,"to":f(null),"can":f(!0)}),s.extend({"name":"undef","a":t,"is":n.isUndefined,"to":f(t),"can":f(!0)}),s.extend({"name":"nan","a":NaN,"is":n.isNaN,"to":f(NaN),"can":f(!0)}),s.extend({"name":"def","a":!0,"is":function(e){return!(s.nan(e)||s.undef(e)||s.nul(e))},"to":function(e){return s.def(e)?e:s.def.a()},"can":function(e){return s.def(e)?!0:!1}}),s.extend({"name":"bool","a":!0,"is":n.isBoolean,"to":function(e){return/^true$/i.test(e)},"can":c("bool"),"methods":{"not":function(e){return!e}}}),s.extend({"name":"tru","inherits":"bool","a":!0,"is":l(!0),"to":s.bool.a,"can":f(!0)}),s.extend({"name":"fal","inherits":"bool","a":!1,"is":l(!1),"to":f(!1),"can":f(!1)}),s.extend({"name":"truy","inherits":"bool","a":!0,"is":function(e){return e==1},"to":function(e){return e?e:!0},"can":f(!0)}),s.extend({"name":"faly","inherits":"bool","a":!1,"is":function(e){return e!==!0},"to":function(e){return e?!1:e},"can":f(!1)}),s.extend({"name":"num","a":0,"is":function(e){return n.isNumber(e)&&!s.nan(parseFloat(e))},"to":function(e){var t,n;if(s.num(e))return e;if(s.bool(e))return e?1:0;if(s.fn(e)){t=e();if(s.num(t))return t}return s.obj(e)&&s.fn(e.a)&&s.num(e.a())?e.a():s.arr(e)?e.length:s.str(e)?(n=e*1||0,n===0&&!e.match(/^0+$/)?s.num.a():n):s.num.a()},"can":c("num"),"methods":{"random":n.random,"range":n.range,"abs":r.abs,"acos":r.acos,"asin":r.asin,"atan":r.atan,"ceil":r.ceil,"cos":r.cos,"exp":r.exp,"floor":r.floor,"log":r.log,"max":r.max,"min":r.min,"pow":r.pow,"round":r.round,"sin":r.sin,"sqrt":r.sqrt,"tan":r.tan,"plus":function(e,t){return e+t},"minus":function(e,t){return e-t},"mod":function(e,t){return e%t},"times":function(e,t){return e*t},"div":function(e,t){return e/t},"sign":function(e){return e==0?0:e/r.abs(e)},"between":function(e,t,n){return e>=t&&e<=n},"eq":function(e,t){return e===t},"neq":function(e,t){return e!==t},"lt":function(e,t){return e<t},"lte":function(e,t){return e<=t},"gt":function(e,t){return e>t},"gte":function(e,t){return e>=t},"fixed":function(e,t){return parseFloat(e.toFixed(s.int(t)?t:2),10)},"hex":function(e){return e.toString(16)},"binary":function(e){return e.toString(2)}}}),s.extend({"name":"int","a":1,"inherits":"num","is":function(e){return r.floor(e)===e},"to":function(e){var t=parseInt(e,10);return isNaN(t)?s.num.a():t},"can":c("int"),"methods":{"dec":function(e){return--e},"inc":function(e){return++e}}}),s.extend({"name":"flt","a":.1,"inherits":"num","is":function(e,t){return e===s.num.fixed(e,t)},"to":function(e,t){return s.num.fixed(s.num.to(e),t)},"can":c("flt"),"methods":{"eq":function(e,t,n){return s.num.fixed(e,n)===s.num.fixed(t,n)},"decimal":function(e){return e%1}}}),s.extend({"name":"str","a":"","is":n.isString,"to":function(e){return s.def(e)?String(e):s.str.a()},"can":c("str"),"methods":{"fromCharCode":String.fromCharCode,"charAt":function(e,t){return e.charAt(t)},"charCodeAt":function(e,t){return e.charCodeAt(t)},"lower":function(e){return e.toLowerCase()},"upper":function(e){return e.toUpperCase()},"escape":n.escape,"unescape":n.unescape,"template":n.template,"contains":n.contains,"array":n.toArray,"length":n.size,"trim":function(e){return s.str.ltrim(s.str.rtrim(e))},"ltrim":function(e){return e.replace(/^\s+/,"")},"rtrim":function(e){return e.replace(/\s+$/,"")},"truncate":function(e,t,n){return e.length>t&&t&&!isNaN(t)?s.faly(n)?e.substr(0,t):e.substr(0,t)+"…":e}}}),s.extend({"name":"plain","a":"","inherits":"str","is":function(e){return s.plain.to(e).length===e.length},"to":function(e){return s.str(e)?e.replace(/^[^a-zA-Z0-9@!#\$\^%&*()+=\-\[\]\\\';,\.\/\{\}\|\":<>\? ]+$/,""):s.plain.a()},"can":function(e){return s.str.can(e)}}),s.extend({"name":"email","a":"[email protected]","inherits":"str","is":function(e){var t=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return t.test(e)},"to":function(e,t,n){return s.email(e)?e:s.def(e)&&s.def(t)&&s.def(n)?e+"@"+t+"."+n:s.def(e)&&s.def(t)?e+"@"+t:s.email.a()},"can":c("email")}),s.extend({"name":"unique","a":"0","is":function(e){return e=s.str(e),e?n.indexOf(s.unique.ids,e)!==-1:!1},"can":function(e){return e=Type.make("str",e),e?n.indexOf(s.unique.ids,e)===-1:!1},"to":function(e){e=Type.make("str",e);while(n.indexOf(s.unique.ids,e)!==-1)e=n.uniqueId();return s.unique.ids.push(e),e},"methods":{"ids":["0"]}}),s.extend({"name":"col","a":[],"is":function(e){return n.isObject(e)||n.isArray(e)},"can":function(e){return s.col(e)},"to":function(e){return s.col(e)?e:s.arr.to(e)},"methods":{"each":n.each,"map":n.map,"reduce":n.reduce,"reduceRight":n.reduceRight,"find":n.find,"filter":n.filter,"where":n.where,"reject":n.reject,"contains":n.contains,"invoke":n.invoke,"pluck":n.pluck,"sortBy":n.sortBy,"groupBy":n.groupBy,"countBy":n.countBy,"shuffle":n.shuffle,"toArray":n.toArray,"length":n.length,"all":n.all,"any":n.any,"max":n.max,"min":n.min,"mapValues":function(e,t){return n.reduce(e,function(n,r,i){return n[i]=t(r,i,e),n},{})}}}),s.extend({"name":"arr","a":[],"inherits":"col","is":n.isArray,"to":function(e){return s.args(e)?n.toArray(e):s.arr(e)?e:s.obj(e)?n.map(e,function(e){return e}):s.fn(e)&&s.arr(e())?e():s.def(e)?n.toArray(arguments):!1},"can":c("arr"),"methods":{"push":function(e,t){return e.push(t)},"pop":function(e){return e.pop()},"unshift":function(e,t){return e.unshift(t)},"shift":function(e){return e.shift()},"slice":function(e,t,n){return e.slice(t,n)},"splice":function(e){return e.splice.apply(this,arguments)},"sort":function(e,t){return e.sort(t)},"range":n.range,"toObject":n.object,"zip":n.zip,"indexOf":n.indexOf,"lastIndexOf":n.lastIndexOf,"first":n.first,"last":n.last,"initial":n.initial,"rest":n.rest,"compact":n.compact,"flatten":n.flatten,"without":n.without,"union":n.union,"intersection":n.intersection,"difference":n.difference,"unique":n.unique,"sortedIndex":n.sortedIndex,"average":function(e){return n.reduce(e,function(e,t){return e+t},0)/e.length}}}),s.extend({"name":"args","a":function(){return arguments}(),"inherits":"arr","is":function(e){return e!=null&&(Object.prototype.toString.call(e)=="[object Arguments]"||!!e.callee)},"can":function(e){return s.args.is(e)||s.arr(e)},"to":function(){return arguments},"methods":{"toArray":function(e){return Array.prototype.slice.call(e)},"sub":function(e,t){return s.arr.to(e).slice(t||1,e.length)},"pre":function(e,t){return s.arr.to(e).unshift(t)}}}),s.extend({"name":"obj","a":{},"inherits":"col","is":function(e){return n.isObject(e)&&!s.arr(e)},"to":function(e,t){return s.obj(e)?e:s.arr(e)?s.arr(t)?n.object(e,t):n.extend({},e):s.fn(e)&&s.obj(e())?e():s.def(e)?{"a":f(e)}:!1},"can":c("obj"),"methods":{"extend":n.extend,"clone":n.clone,"pairs":n.pairs,"invert":n.invert,"functions":n.functions,"pick":n.pick,"omit":n.omit,"defaults":n.defaults,"tap":n.tap,"keys":n.keys,"values":n.values,"isEqual":n.isEqual,"isEmpty":n.isEmpty,"isElement":n.isElement,"has":n.has,"result":n.result,"isSubobject":function(e,t){return n.isEqual(e,n.pick(t,n.keys(e)))}}}),s.extend({"name":"fn","a":o,"is":n.isFunction,"can":function(e){return n.isFunction(e)},"to":function(e){return s.fn.is(e)?e:s.fn.a()},"methods":{"noop":o,"compose":n.compose,"identity":n.identity,"bind":n.bind,"memorize":n.memorize,"delay":n.delay,"defer":n.defer,"throttle":n.throttle,"debounce":n.debounce,"once":n.once,"after":n.after,"wrap":n.wrap,"times":n.times,"always":function(e){return function(){return e}},"sample":function(e,t){var n,i;return function(){n=this,i=arguments,r.random()<t&&e.apply(n,i)}}}}),s.extend({"name":"reg","a":new RegExp,"is":n.isRegExp,"to":function(e,t){return new RegExp(e,t)},"can":c("reg")}),s.extend({"name":"date","a":new Date,"is":n.isDate,"to":function(e){return new Date(e)},"can":c("date"),"methods":{"shortMonth":function(e){var t=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return t[e]||t},"day":function(e){var t=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return t[e]||t},"shortDay":function(e){var t=["Su","M","Tu","W","Th","F","Sa"];return t[e]||t}}}),s.extend({"name":"vec","a":[0],"is":function(e,t){var r;s.int(e)&&(r=e,e=t);if(s.arr(e)&&n.all(e,function(e){return s.num(e)})){if(!s.def(r))return!0;if(e.length===r)return!0}return!1},"to":function(e,t){var r,i;return s.int(e)&&(r=e,e=t),s.arr(e)?(i=n.map(e,function(e){return s.num(e)}),s.def(r)?i.slice(0,r):i):n.all(arguments,function(e){return s.num(e)})?n.map(arguments,f):s.vec.a()},"can":function(e){return s.vec(e)}}),s.extend({"name":"geo","a":{"lat":0,"long":0},"is":function(e){return s.obj(e)&&e.hasOwnProperty("lat")&&e.hasOwnProperty("long")&&s.num(e.lat)&&s.num(e.long)?!0:!1},"to":function(e,t){return s.num(t)&&s.num(e)?{"lat":e,"long":t}:s.geo(e)?e:s.obj(e)?n.extend(s.geo.a(),e):s.arr(e)&&e.length===2?{"lat":a[0],"long":a[1]}:s.fn(e)&&s.geo(e())?e():s.geo.a()},"can":c("geo")}),s.extend({"name":"json","a":{},"is":function(e){return s.str(e)?s.obj(i.parse(e)):s.obj(e)||s.arr(e)?s.str(i.stringify(e)):!1},"to":function(e){return s.str(e)?i.parse(e):s.obj(e)||s.arr(e)?i.stringify(e):this.a()},"methods":{"stringify":i.stringify,"parse":i.parse}}),s.extend({"name":"que","a":[],"is":function(e){return s.arr(e)&&n.all(e,function(e){return s.fn(e)})},"to":function(e){return s.que(e)?e:s.fn(e)?[e]:[]},"can":c("que")}),s):(u("type requires JSON"),!1)):(u("type requires Math"),!1)):(u("type requires underscore.js"),!1)})