lib/parse.js
function parseFile (file, options) {
  return new Promise(function (resolve, reject) {
    // console.log('Parsing %s', file.url);

    // Find the parsers that can read this file type.
    // If none of the parsers are an exact match for this file, then we'll try ALL of them.
    // This handles situations where the file IS a supported type, just with an unknown extension.
    var allParsers = plugins.all(options.parse);
    var filteredParsers = plugins.filter(allParsers, "canParse", file);
    var parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;

    // Run the parsers, in order, until one of them succeeds
    plugins.sort(parsers);
    plugins.run(parsers, "parse", file)
      .then(onParsed, onError);

    function onParsed (parser) {
      if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
        reject(ono.syntax('Error parsing "%s" as %s. \nParsed value is empty', file.url, parser.plugin.name));
      }
      else {
        resolve(parser);
      }
    }

    function onError (err) {
      if (err) {
        err = err instanceof Error ? err : new Error(err);
        reject(ono.syntax(err, "Error parsing %s", file.url));
      }
      else {
        reject(ono.syntax("Unable to parse %s", file.url));
      }
    }
  });
}
function parseFile (file, options) {
  return new Promise(function (resolve, reject) {
    // console.log('Parsing %s', file.url);

    // Find the parsers that can read this file type.
    // If none of the parsers are an exact match for this file, then we'll try ALL of them.
    // This handles situations where the file IS a supported type, just with an unknown extension.
    var allParsers = plugins.all(options.parse);
    var filteredParsers = plugins.filter(allParsers, "canParse", file);
    var parsers = filteredParsers.length > 0 ? filteredParsers : allParsers;

    // Run the parsers, in order, until one of them succeeds
    plugins.sort(parsers);
    plugins.run(parsers, "parse", file)
      .then(onParsed, onError);

    function onParsed (parser) {
      if (!parser.plugin.allowEmpty && isEmpty(parser.result)) {
        reject(ono.syntax('Error parsing "%s" as %s. \nParsed value is empty', file.url, parser.plugin.name));
      }
      else {
        resolve(parser);
      }
    }

    function onError (err) {
      if (err) {
        err = err instanceof Error ? err : new Error(err);
        reject(ono.syntax(err, "Error parsing %s", file.url));
      }
      else {
        reject(ono.syntax("Unable to parse %s", file.url));
      }
    }
  });
}
function parseFile ( file , options ) { return new Promise ( function ( resolve , reject ) { // console.log('Parsing %s', file.url); // Find the parsers that can read this file type. // If none of the parsers are an exact match for this file, then we'll try ALL of them. // This handles situations where the file IS a supported type, just with an unknown extension. var allParsers = plugins . all ( options . parse ) ; var filteredParsers = plugins . filter ( allParsers , "canParse" , file ) ; var parsers = filteredParsers . length > 0 ? filteredParsers : allParsers ; // Run the parsers, in order, until one of them succeeds plugins . sort ( parsers ) ; plugins . run ( parsers , "parse" , file ) . then ( onParsed , onError ) ; function onParsed ( parser ) { if ( ! parser . plugin . allowEmpty && isEmpty ( parser . result ) ) { reject ( ono . syntax ( 'Error parsing "%s" as %s. \nParsed value is empty' , file . url , parser . plugin . name ) ) ; } else { resolve ( parser ) ; } } function onError ( err ) { if ( err ) { err = err instanceof Error ? err : new Error ( err ) ; reject ( ono . syntax ( err , "Error parsing %s" , file . url ) ) ; } else { reject ( ono . syntax ( "Unable to parse %s" , file . url ) ) ; } } } ) ; }
Parses the given file's contents, using the configured parser plugins.

@param {object} file           - An object containing information about the referenced file
@param {string} file.url       - The full URL of the referenced file
@param {string} file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
@param {*}      file.data      - The file contents. This will be whatever data type was returned by the resolver
@param {$RefParserOptions} options

@returns {Promise}
The promise resolves with the parsed file contents and the parser that was used.
Parses the given file s contents using the configured parser plugins .