1 // Generated by LiveScript 1.2.0
3 var parsedTypeCheck, types, toString$ = {}.toString;
4 parsedTypeCheck = require('type-check').parsedTypeCheck;
7 switch (toString$.call(it).slice(8, -1)) {
9 return coerceType(it, {
13 return coerceType(it, {
19 value: coerceTypes(it, [
47 Undefined: function(it){
48 if (it === 'undefined' || it === void 8) {
83 Boolean: function(it){
89 } else if (it === 'false') {
100 Number: function(it){
115 value: parseFloat(it)
118 Date: function(value, options){
120 if (that = /^\#(.*)\#$/.exec(value)) {
123 value: new Date(+that[1] || that[1])
125 } else if (options.explicit) {
132 value: new Date(+value || value)
136 RegExp: function(value, options){
138 if (that = /^\/(.*)\/([gimy]*)$/.exec(value)) {
141 value: new RegExp(that[1], that[2])
143 } else if (options.explicit) {
150 value: new RegExp(value)
155 return coerceArray(it, {
161 Object: function(it){
162 return coerceFields(it, {
166 String: function(it){
168 if (toString$.call(it).slice(8, -1) !== 'String') {
173 if (that = it.match(/^'(.*)'$/)) {
178 } else if (that = it.match(/^"(.*)"$/)) {
191 function coerceArray(node, type){
193 if (toString$.call(node).slice(8, -1) !== 'Array') {
202 var i$, ref$, len$, results$ = [];
203 for (i$ = 0, len$ = (ref$ = node).length; i$ < len$; ++i$) {
205 results$.push(coerceTypes(element, typeOf));
211 function coerceTuple(node, type){
212 var result, i$, ref$, len$, i, types, that;
213 if (toString$.call(node).slice(8, -1) !== 'Array') {
219 for (i$ = 0, len$ = (ref$ = type.of).length; i$ < len$; ++i$) {
222 if (that = coerceTypes(node[i], types)) {
231 function coerceFields(node, type){
232 var typeOf, key, value;
233 if (toString$.call(node).slice(8, -1) !== 'Object') {
242 var ref$, results$ = {};
243 for (key in ref$ = node) {
245 results$[key] = coerceTypes(value, typeOf[key] || [{
253 function coerceType(node, typeObj, options){
254 var type, structure, coerceFunc;
255 type = typeObj.type, structure = typeObj.structure;
257 coerceFunc = types[type];
258 return coerceFunc(node, options);
262 return coerceArray(node, typeObj);
264 return coerceTuple(node, typeObj);
266 return coerceFields(node, typeObj);
270 function coerceTypes(node, types, options){
271 var i$, len$, type, ref$, valueType, value;
272 for (i$ = 0, len$ = types.length; i$ < len$; ++i$) {
274 ref$ = coerceType(node, type, options), valueType = ref$.type, value = ref$.value;
275 if (valueType === 'Nothing') {
278 if (parsedTypeCheck([type], value)) {
282 throw new Error("Value " + JSON.stringify(node) + " does not type check against " + JSON.stringify(types) + ".");
284 module.exports = coerceTypes;