source/convertToJson.js
function parseValueOfType(value, type, options) {
  switch (type) {
    case String:
      return { value }

    case Number:
    case 'Integer':
    case Integer:
      // The global isFinite() function determines
      // whether the passed value is a finite number.
      // If  needed, the parameter is first converted to a number.
      if (!isFinite(value)) {
        return { error: 'invalid' }
      }
      if (type === Integer && !isInteger(value)) {
        return { error: 'invalid' }
      }
      // Convert strings to numbers.
      // Just an additional feature.
      // Won't happen when called from `readXlsx()`.
      if (typeof value === 'string') {
        value = parseFloat(value)
      }
      return { value }

    case 'URL':
    case URL:
      if (!isURL(value)) {
        return { error: 'invalid' }
      }
      return { value }

    case 'Email':
    case Email:
      if (!isEmail(value)) {
        return { error: 'invalid' }
      }
      return { value }

    case Date:
      // XLSX has no specific format for dates.
      // Sometimes a date can be heuristically detected.
      // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
      if (value instanceof Date) {
        return { value }
      }
      if (typeof value === 'number') {
        if (!isFinite(value)) {
          return { error: 'invalid' }
        }
        value = parseInt(value)
        const date = parseDate(value, options.properties)
        if (!date) {
          return { error: 'invalid' }
        }
        return { value: date }
      }
      return { error: 'invalid' }

    case Boolean:
      if (typeof value === 'boolean') {
        return { value }
      }
      return { error: 'invalid' }

    default:
      throw new Error(`Unknown schema type: ${type && type.name || type}`)
  }
}
function parseValueOfType(value, type, options) {
  switch (type) {
    case String:
      return { value }

    case Number:
    case 'Integer':
    case Integer:
      // The global isFinite() function determines
      // whether the passed value is a finite number.
      // If  needed, the parameter is first converted to a number.
      if (!isFinite(value)) {
        return { error: 'invalid' }
      }
      if (type === Integer && !isInteger(value)) {
        return { error: 'invalid' }
      }
      // Convert strings to numbers.
      // Just an additional feature.
      // Won't happen when called from `readXlsx()`.
      if (typeof value === 'string') {
        value = parseFloat(value)
      }
      return { value }

    case 'URL':
    case URL:
      if (!isURL(value)) {
        return { error: 'invalid' }
      }
      return { value }

    case 'Email':
    case Email:
      if (!isEmail(value)) {
        return { error: 'invalid' }
      }
      return { value }

    case Date:
      // XLSX has no specific format for dates.
      // Sometimes a date can be heuristically detected.
      // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
      if (value instanceof Date) {
        return { value }
      }
      if (typeof value === 'number') {
        if (!isFinite(value)) {
          return { error: 'invalid' }
        }
        value = parseInt(value)
        const date = parseDate(value, options.properties)
        if (!date) {
          return { error: 'invalid' }
        }
        return { value: date }
      }
      return { error: 'invalid' }

    case Boolean:
      if (typeof value === 'boolean') {
        return { value }
      }
      return { error: 'invalid' }

    default:
      throw new Error(`Unknown schema type: ${type && type.name || type}`)
  }
}
function parseValueOfType ( value , type , options ) { switch ( type ) { case String : return { value } case Number : case 'Integer' : case Integer : // The global isFinite() function determines // whether the passed value is a finite number. // If  needed, the parameter is first converted to a number. if ( ! isFinite ( value ) ) { return { error : 'invalid' } } if ( type === Integer && ! isInteger ( value ) ) { return { error : 'invalid' } } // Convert strings to numbers. // Just an additional feature. // Won't happen when called from `readXlsx()`. if ( typeof value === 'string' ) { value = parseFloat ( value ) } return { value } case 'URL' : case URL : if ( ! isURL ( value ) ) { return { error : 'invalid' } } return { value } case 'Email' : case Email : if ( ! isEmail ( value ) ) { return { error : 'invalid' } } return { value } case Date : // XLSX has no specific format for dates. // Sometimes a date can be heuristically detected. // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777 if ( value instanceof Date ) { return { value } } if ( typeof value === 'number' ) { if ( ! isFinite ( value ) ) { return { error : 'invalid' } } value = parseInt ( value ) const date = parseDate ( value , options . properties ) if ( ! date ) { return { error : 'invalid' } } return { value : date } } return { error : 'invalid' } case Boolean : if ( typeof value === 'boolean' ) { return { value } } return { error : 'invalid' } default : throw new Error ( ` ${ type && type . name || type } ` ) } }
Converts textual value to a javascript typed value.
@param  {string} value
@param  {} type
@return {{ value: (string|number|Date|boolean), error: string }}
Converts textual value to a javascript typed value .