1 // Generated by LiveScript 1.2.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') {
113 value: parseFloat(it)
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 if (that = it.match(/^'([\s\S]*)'$/)) {
174 value: that[1].replace(/\\'/g, "'")
176 } else if (that = it.match(/^"([\s\S]*)"$/)) {
179 value: that[1].replace(/\\"/g, '"')
189 function castArray(node, type, options){
191 if (toString$.call(node).slice(8, -1) !== 'Array') {
200 var i$, ref$, len$, results$ = [];
201 for (i$ = 0, len$ = (ref$ = node).length; i$ < len$; ++i$) {
203 results$.push(typesCast(element, typeOf, options));
209 function castTuple(node, type, options){
210 var result, i, i$, ref$, len$, types, cast;
211 if (toString$.call(node).slice(8, -1) !== 'Array') {
218 for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
220 cast = typesCast(node[i], types, options);
221 if (toString$.call(cast).slice(8, -1) !== 'Undefined') {
226 if (node.length <= i) {
237 function castFields(node, type, options){
238 var typeOf, key, value;
239 if (toString$.call(node).slice(8, -1) !== 'Object') {
248 var ref$, results$ = {};
249 for (key in ref$ = node) {
251 results$[typesCast(key, [{
253 }], options)] = typesCast(value, typeOf[key] || [{
261 function typeCast(node, typeObj, options){
262 var type, structure, castFunc, ref$;
263 type = typeObj.type, structure = typeObj.structure;
265 castFunc = ((ref$ = options.customTypes[type]) != null ? ref$.cast : void 8) || types[type];
267 throw new Error("Type not defined: " + type + ".");
269 return castFunc(node, options, typesCast);
273 return castArray(node, typeObj, options);
275 return castTuple(node, typeObj, options);
277 return castFields(node, typeObj, options);
281 function typesCast(node, types, options){
282 var i$, len$, type, ref$, valueType, value;
283 for (i$ = 0, len$ = types.length; i$ < len$; ++i$) {
285 ref$ = typeCast(node, type, options), valueType = ref$.type, value = ref$.value;
286 if (valueType === 'Nothing') {
289 if (parsedTypeCheck([type], value, {
290 customTypes: options.customTypes
295 throw new Error("Value " + JSON.stringify(node) + " does not type check against " + JSON.stringify(types) + ".");
297 module.exports = typesCast;