text: import { DateConvertIn, DateIsValidInternal, DateIsValidExternal, DateConvertOut } from './dates';
  
  export default function parseInput(input) {
  
      //following code is to make a best guess at
      //the type for a variable being submitted.
  
      //we are working with a serialized data representation
      input = input.trim();
      try {
          input = JSON.stringify(
              JSON.parse(input)
          );
          if (input[0] === '[') {
              //array
              return formatResponse('array', JSON.parse(input));
          } else if (input[0] === '{') {
              //object
              return formatResponse('object', JSON.parse(input));
          } else if (
              input.match(/\-?\d+\.\d+/)
              && input.match(/\-?\d+\.\d+/)[0] === input
          ) {
              //integer
              return formatResponse('float', parseFloat(input));
          } else if (
              input.match(/\-?\d+/)
              && input.match(/\-?\d+/)[0] === input
          ) {
              //float
              return formatResponse('integer', parseInt(input));
          }
      } catch (e) {
          // no-op
      }
  
      //run in case input was not serializable
      const inputLower = input.toLowerCase();
      switch (inputLower) {
      case 'undefined': {
          return formatResponse('undefined', undefined);
      }
      case 'nan': {
          return formatResponse('nan', NaN);
      }
      case 'null': {
          return formatResponse('null', null);
      }
      case 'true': {
          return formatResponse('boolean', true);
      }
      case 'false': {
          return formatResponse('boolean', false);
      }
      default: {
          //check to see if this is a date
          if (DateIsValidInternal(input)) {
              return (formatResponse('date', DateConvertIn(input)));
          }
          if (DateIsValidExternal(input)) {
              return (formatResponse('date', DateConvertOut(input)));
          }
      }
      }
  
      return formatResponse(false, null);
  
  }
  
  function formatResponse(type, value) {
      return {
          type: type,
          value: value
      };
  }
  