1 // Generated by LiveScript 1.6.0
3 var parsedTypeCheck, types, toString$ = {}.toString;
4 parsedTypeCheck = require('type-check').parsedTypeCheck;
6 '*': function(value, options){
7 switch (toString$.call(value).slice(8, -1)) {
9 return typeCast(value, {
13 return typeCast(value, {
19 value: typesCast(value, [
41 ], (options.explicit = true, options))
45 Undefined: function(it){
46 if (it === 'undefined' || it === void 8) {
81 Boolean: function(it){
87 } else if (it === 'false') {
116 Date: function(value, options){
118 if (that = /^\#([\s\S]*)\#$/.exec(value)) {
121 value: new Date(+that[1] || that[1])
123 } else if (options.explicit) {
130 value: new Date(+value || value)
134 RegExp: function(value, options){
136 if (that = /^\/([\s\S]*)\/([gimy]*)$/.exec(value)) {
139 value: new RegExp(that[1], that[2])
141 } else if (options.explicit) {
148 value: new RegExp(value)
152 Array: function(value, options){
153 return castArray(value, {
159 Object: function(value, options){
160 return castFields(value, {
164 String: function(it){
166 if (toString$.call(it).slice(8, -1) !== 'String') {
171 replace = function(value, quote){
172 return value.replace(/\\([^u]|u[0-9a-fA-F]{4})/g, function(all, escaped){
173 switch (escaped[0]) {
189 return JSON.parse("\"" + all + "\"");
195 if (that = it.match(/^'([\s\S]*)'$/)) {
198 value: replace(that[1], "'")
200 } else if (that = it.match(/^"([\s\S]*)"$/)) {
203 value: replace(that[1], '"')
213 function castArray(node, type, options){
215 if (toString$.call(node).slice(8, -1) !== 'Array') {
224 var i$, ref$, len$, results$ = [];
225 for (i$ = 0, len$ = (ref$ = node).length; i$ < len$; ++i$) {
227 results$.push(typesCast(element, typeOf, options));
233 function castTuple(node, type, options){
234 var result, i, i$, ref$, len$, types, cast;
235 if (toString$.call(node).slice(8, -1) !== 'Array') {
242 for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
244 cast = typesCast(node[i], types, options);
245 if (toString$.call(cast).slice(8, -1) !== 'Undefined') {
250 if (node.length <= i) {
261 function castFields(node, type, options){
262 var typeOf, key, value;
263 if (toString$.call(node).slice(8, -1) !== 'Object') {
272 var ref$, resultObj$ = {};
273 for (key in ref$ = node) {
275 resultObj$[typesCast(key, [{
277 }], options)] = typesCast(value, typeOf[key] || [{
285 function typeCast(node, typeObj, options){
286 var type, structure, castFunc, ref$;
287 type = typeObj.type, structure = typeObj.structure;
289 castFunc = ((ref$ = options.customTypes[type]) != null ? ref$.cast : void 8) || types[type];
291 throw new Error("Type not defined: " + type + ".");
293 return castFunc(node, options, typesCast);
297 return castArray(node, typeObj, options);
299 return castTuple(node, typeObj, options);
301 return castFields(node, typeObj, options);
305 function typesCast(node, types, options){
306 var i$, len$, type, ref$, valueType, value;
307 for (i$ = 0, len$ = types.length; i$ < len$; ++i$) {
309 ref$ = typeCast(node, type, options), valueType = ref$.type, value = ref$.value;
310 if (valueType === 'Nothing') {
313 if (parsedTypeCheck([type], value, {
314 customTypes: options.customTypes
319 throw new Error("Value " + JSON.stringify(node) + " does not type check against " + JSON.stringify(types) + ".");
321 module.exports = function(node, types, options){
322 if (!options.explicit && types.length === 1 && types[0].type === 'String') {
325 return typesCast(node, types, options);