/**
 * @module input/doi
 */

import fetchDoiType from './type'

/**
 * Format CrossRef JSON
 *
 * @access protected
 * @method parseDoiJson
 *
 * @param {Object} data - The input data
 *
 * @return {CSL} The formatted input data
 */
const parseDoiJson = function (data) {
  const res = {
    type: fetchDoiType(data.type)
  }

  const dateFields = ['submitted', 'issued', 'event-date', 'original-date', 'container', 'accessed']
  dateFields.forEach(field => {
    if (data[field] && typeof data[field]['date-parts'][0] === 'number') {
      data[field]['date-parts'] = [data[field]['date-parts']]
    }
  })

  return Object.assign({}, data, res)
}

export {
  parseDoiJson as parse,
  parseDoiJson as default
}

/**
 * @module input/doi
 */

import fetchDoiType from './type'

/**
 * Format CrossRef JSON
 *
 * @access protected
 * @method parseDoiJson
 *
 * @param {Object} data - The input data
 *
 * @return {CSL} The formatted input data
 */
const parseDoiJson = function (data) {
  const res = {
    type: fetchDoiType(data.type)
  }

  const dateFields = ['submitted', 'issued', 'event-date', 'original-date', 'container', 'accessed']
  dateFields.forEach(field => {
    let value = data[field]
    if (value && value['date-parts'] && typeof value['date-parts'][0] === 'number') {
      value['date-parts'] = [value['date-parts']]
    }
  })

  return Object.assign({}, data, res)
}

export {
  parseDoiJson as parse,
  parseDoiJson as default
}

Make check when parsing API data safe
[input:doi] Make check when parsing API data safe

Make a check when polishing API data not fail
when a date field is an empty object.

Close #147
