1 // Generated by LiveScript 1.6.0
3 var ref$, any, all, isItNaN, types, defaultType, toString$ = {}.toString;
4 ref$ = require('prelude-ls'), any = ref$.any, all = ref$.all, isItNaN = ref$.isItNaN;
8 validate: function(it){
18 validate: function(it){
19 return !isItNaN(it) && it % 1 === 0;
24 validate: function(it){
30 validate: function(it){
31 return !isItNaN(it.getTime());
39 function checkArray(input, type, options){
40 return all(function(it){
41 return checkMultiple(it, type.of, options);
44 function checkTuple(input, type, options){
45 var i, i$, ref$, len$, types;
47 for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
49 if (!checkMultiple(input[i], types, options)) {
54 return input.length <= i;
56 function checkFields(input, type, options){
57 var inputKeys, numInputKeys, k, numOfKeys, key, ref$, types;
65 for (key in ref$ = type.of) {
67 if (!checkMultiple(input[key], types, options)) {
74 return type.subset || numInputKeys === numOfKeys;
76 function checkStructure(input, type, options){
77 if (!(input instanceof Object)) {
80 switch (type.structure) {
82 return checkFields(input, type, options);
84 return checkArray(input, type, options);
86 return checkTuple(input, type, options);
89 function check(input, typeObj, options){
90 var type, structure, setting, that;
91 type = typeObj.type, structure = typeObj.structure;
96 setting = options.customTypes[type] || types[type];
98 return (setting.typeOf === void 8 || setting.typeOf === toString$.call(input).slice(8, -1)) && setting.validate(input);
100 return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj, options));
102 } else if (structure) {
103 if (that = defaultType[structure]) {
104 if (that !== toString$.call(input).slice(8, -1)) {
108 return checkStructure(input, typeObj, options);
110 throw new Error("No type defined. Input: " + input + ".");
113 function checkMultiple(input, types, options){
114 if (toString$.call(types).slice(8, -1) !== 'Array') {
115 throw new Error("Types must be in an array. Input: " + input + ".");
117 return any(function(it){
118 return check(input, it, options);
121 module.exports = function(parsedType, input, options){
122 options == null && (options = {});
123 if (options.customTypes == null) {
124 options.customTypes = {};
126 return checkMultiple(input, parsedType, options);