function findType(raw) {
  // If there is no value assume null
  if ((raw === null) || (raw === undefined)) return null;

  const string = raw.trim();
  if (string.length === 0) return null;

  const object = safeJSONParse(string);
  const multiple = Array.isArray(object);
  let type;

  if (multiple) {
    type = 'string';
    type = determineType(object.map(findType)).type;

    if (type.multiple) {
      throw new Error('Multidimensional arrays are not supported!');
    }
  } else {
    // Check for floats
    if (/^-?((\d+\.\d*)|(\d+\.\d*))$/.test(string)) {
      type = 'float';
    } else if (/^-?(\d+)$/.test(string)) {
      type = 'integer';
    } else {
      type = 'string';
    }
  }

  return {
    type,
    multiple,
    example: string,
  };
}
// Given a string, finds the most likely type
Given a string, finds the most likely type
Given a string finds the most likely type
function findType(raw) {
  if ((raw === null) || (raw === undefined)) return null;
  const string = raw.trim();
  if (string.length === 0) return null;
  const object = safeJSONParse(string);
  const multiple = Array.isArray(object);
  let type;
  if (multiple) {
    type = 'string';
    type = determineType(object.map(findType)).type;
    if (type.multiple) {
      throw new Error('Multidimensional arrays are not supported!');
    }
  } else {
    if (/^-?((\d+\.\d*)|(\d+\.\d*))$/.test(string)) {
      type = 'float';
    } else if (/^-?(\d+)$/.test(string)) {
      type = 'integer';
    } else {
      type = 'string';
    }
  }
  return {
    type,
    multiple,
    example: string,
  };
}
function findType ( raw ) { if ( ( raw === null ) || ( raw === undefined ) ) return null ; const string = raw . trim ( ) ; if ( string . length === 0 ) return null ; const object = safeJSONParse ( string ) ; const multiple = Array . isArray ( object ) ; let type ; if ( multiple ) { type = 'string' ; type = determineType ( object . map ( findType ) ) . type ; if ( type . multiple ) { throw new Error ( 'Multidimensional arrays are not supported!' ) ; } } else { if ( / ^-?((\d+\.\d*)|(\d+\.\d*))$ / . test ( string ) ) { type = 'float' ; } else if ( / ^-?(\d+)$ / . test ( string ) ) { type = 'integer' ; } else { type = 'string' ; } } return { type , multiple , example : string , } ; }
Given a string, finds the most likely type
Given a string finds the most likely type
// If there is no value assume null // Check for floats