-// Generated by LiveScript 1.4.0
+// Generated by LiveScript 1.6.0
(function(){
- var ref$, any, all, isItNaN, types, defaultType, customTypes, toString$ = {}.toString;
+ var ref$, any, all, isItNaN, types, defaultType, toString$ = {}.toString;
ref$ = require('prelude-ls'), any = ref$.any, all = ref$.all, isItNaN = ref$.isItNaN;
types = {
Number: {
array: 'Array',
tuple: 'Array'
};
- function checkArray(input, type){
+ function checkArray(input, type, options){
return all(function(it){
- return checkMultiple(it, type.of);
+ return checkMultiple(it, type.of, options);
}, input);
}
- function checkTuple(input, type){
+ function checkTuple(input, type, options){
var i, i$, ref$, len$, types;
i = 0;
for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
types = ref$[i$];
- if (!checkMultiple(input[i], types)) {
+ if (!checkMultiple(input[i], types, options)) {
return false;
}
i++;
}
return input.length <= i;
}
- function checkFields(input, type){
+ function checkFields(input, type, options){
var inputKeys, numInputKeys, k, numOfKeys, key, ref$, types;
inputKeys = {};
numInputKeys = 0;
numOfKeys = 0;
for (key in ref$ = type.of) {
types = ref$[key];
- if (!checkMultiple(input[key], types)) {
+ if (!checkMultiple(input[key], types, options)) {
return false;
}
if (inputKeys[key]) {
}
return type.subset || numInputKeys === numOfKeys;
}
- function checkStructure(input, type){
+ function checkStructure(input, type, options){
if (!(input instanceof Object)) {
return false;
}
switch (type.structure) {
case 'fields':
- return checkFields(input, type);
+ return checkFields(input, type, options);
case 'array':
- return checkArray(input, type);
+ return checkArray(input, type, options);
case 'tuple':
- return checkTuple(input, type);
+ return checkTuple(input, type, options);
}
}
- function check(input, typeObj){
+ function check(input, typeObj, options){
var type, structure, setting, that;
type = typeObj.type, structure = typeObj.structure;
if (type) {
if (type === '*') {
return true;
}
- setting = customTypes[type] || types[type];
+ setting = options.customTypes[type] || types[type];
if (setting) {
- return setting.typeOf === toString$.call(input).slice(8, -1) && setting.validate(input);
+ return (setting.typeOf === void 8 || setting.typeOf === toString$.call(input).slice(8, -1)) && setting.validate(input);
} else {
- return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj));
+ return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj, options));
}
} else if (structure) {
if (that = defaultType[structure]) {
return false;
}
}
- return checkStructure(input, typeObj);
+ return checkStructure(input, typeObj, options);
} else {
throw new Error("No type defined. Input: " + input + ".");
}
}
- function checkMultiple(input, types){
+ function checkMultiple(input, types, options){
if (toString$.call(types).slice(8, -1) !== 'Array') {
throw new Error("Types must be in an array. Input: " + input + ".");
}
return any(function(it){
- return check(input, it);
+ return check(input, it, options);
}, types);
}
module.exports = function(parsedType, input, options){
options == null && (options = {});
- customTypes = options.customTypes || {};
- return checkMultiple(input, parsedType);
+ if (options.customTypes == null) {
+ options.customTypes = {};
+ }
+ return checkMultiple(input, parsedType, options);
};
}).call(this);