src/utils/parse.js
function parseField(fieldKey, fieldData, options) {
  let parseFn = contents => ({ contents: contents });
  let contents = fieldData;
  // Check to see if options.fieldParsers contains this key
  if (options.fieldParsers.hasOwnProperty(fieldKey)) {
    const parserKey = options.fieldParsers[fieldKey];
    parseFn = options.parsers[parserKey].parseFn;
    contents = typeof fieldData === 'string' ? fieldData : fieldData.contents;
  }
  // Check to see if there is a manually-added parser in the data
  if (typeof fieldData === 'object' && fieldData.hasOwnProperty('parser')) {
    if (options.parsers.hasOwnProperty(fieldData.parser)) {
      parseFn = options.parsers[fieldData.parser].parseFn;
    } else {
      DrizzleError.error(
        new DrizzleError(
          `parser '${fieldData.parser}' set on field '${fieldKey}' not defined`,
          DrizzleError.LEVELS.WARN
        ),
        options.debug
      );
    }
    contents = fieldData.contents;
    if (!fieldData.hasOwnProperty('contents')) {
      // TODO again
    }
  }
  return parseFn(contents);
}
function parseField(fieldKey, fieldData, options) {
  let parseFn = contents => ({ contents: contents });
  let contents = fieldData;
  // Check to see if options.fieldParsers contains this key
  if (options.fieldParsers.hasOwnProperty(fieldKey)) {
    const parserKey = options.fieldParsers[fieldKey];
    parseFn = options.parsers[parserKey].parseFn;
    contents = typeof fieldData === 'string' ? fieldData : fieldData.contents;
  }
  // Check to see if there is a manually-added parser in the data
  if (typeof fieldData === 'object' && fieldData.hasOwnProperty('parser')) {
    if (options.parsers.hasOwnProperty(fieldData.parser)) {
      parseFn = options.parsers[fieldData.parser].parseFn;
    } else {
      DrizzleError.error(
        new DrizzleError(
          `parser '${fieldData.parser}' set on field '${fieldKey}' not defined`,
          DrizzleError.LEVELS.WARN
        ),
        options.debug
      );
    }
    contents = fieldData.contents;
    if (!fieldData.hasOwnProperty('contents')) {
      // TODO again
    }
  }
  return parseFn(contents);
}
function parseField ( fieldKey , fieldData , options ) { let parseFn = contents => ( { contents : contents } ) ; let contents = fieldData ; // Check to see if options.fieldParsers contains this key if ( options . fieldParsers . hasOwnProperty ( fieldKey ) ) { const parserKey = options . fieldParsers [ fieldKey ] ; parseFn = options . parsers [ parserKey ] . parseFn ; contents = typeof fieldData === 'string' ? fieldData : fieldData . contents ; } // Check to see if there is a manually-added parser in the data if ( typeof fieldData === 'object' && fieldData . hasOwnProperty ( 'parser' ) ) { if ( options . parsers . hasOwnProperty ( fieldData . parser ) ) { parseFn = options . parsers [ fieldData . parser ] . parseFn ; } else { DrizzleError . error ( new DrizzleError ( ` ${ fieldData . parser } ${ fieldKey } ` , DrizzleError . LEVELS . WARN ) , options . debug ) ; } contents = fieldData . contents ; if ( ! fieldData . hasOwnProperty ( 'contents' ) ) { // TODO again } } return parseFn ( contents ) ; }
Evaluate a single field of data and see if it should be run through a parser.
@param {String} fieldKey
@param {Object|String} fieldData
@param {Object} options
@return {Object} parsed data; contains `contents` property.
@see parse/parsers
Evaluate a single field of data and see if it should be run through a parser .