<commit_before>
const API_BLUEPRINT_HEADER = /^[\uFEFF]?(((VERSION:( |\t)2)|(FORMAT:( |\t)(X-)?1A))([\n\r]{1,2}|$))/i;
const API_BLUEPRINT_RESPONSE = /\+\s+Response\s+\d{3}/i;

const LEGACY_BLUEPRINT_TITLE = /\-{3} ([^\n\r]+ )?\-{3}([\n\r]{1,2}|$)/;


/**
 * Identifies given source.
 * @param {string} source - The source code of API description file.
 * @returns {string|null} Media type of given file.
 */
function identify(source) {
  // Stay awhile and listen!

  if (source.match(API_BLUEPRINT_HEADER)) {
    // I spotted 'FORMAT: 1A' header, which gives us a clear clue that
    // the file is API Blueprint.
    return 'text/vnd.apiblueprint';
  }

  if (source.match(LEGACY_BLUEPRINT_TITLE)) {
    // I spotted '--- Sample Title ---' title. This looks like
    // we are dealing with the legacy Apiary Blueprint.
    return 'text/vnd.legacyblueprint';
  }

  if (source.match(API_BLUEPRINT_RESPONSE)) {
    // I can not see the '--- Sample Title ---' and at the same time
    // there is something like '+ Response 200' in the document, which is
    // pretty distinctive for API Blueprint.
    return 'text/vnd.apiblueprint';
  }

  try {
    const json = JSON.parse(source);

    // It looks like the source is a valid JSON file. I suspect it to
    // be a Swagger file.
    if (json.swagger) {
      // Indeed, we are dealing with Swagger file!
      return 'application/swagger+json';
    }

    // Nothing I could identify. Maybe Horadric Cube could magically
    // turn it into a rather smart casual leather armor?
    return null;
  } catch(e) {
    return null;
  }
}


export default {identify};<commit_msg>Added yaml detection<commit_after>import YAML from 'js-yaml';

const API_BLUEPRINT_HEADER = /^[\uFEFF]?(((VERSION:( |\t)2)|(FORMAT:( |\t)(X-)?1A))([\n\r]{1,2}|$))/i;
const API_BLUEPRINT_RESPONSE = /\+\s+Response\s+\d{3}/i;

const LEGACY_BLUEPRINT_TITLE = /\-{3} ([^\n\r]+ )?\-{3}([\n\r]{1,2}|$)/;


/**
 * Identifies given source.
 * @param {string} source - The source code of API description file.
 * @returns {string|null} Media type of given file.
 */
function identify(source) {
  // Stay awhile and listen!

  if (source.match(API_BLUEPRINT_HEADER)) {
    // I spotted 'FORMAT: 1A' header, which gives us a clear clue that
    // the file is API Blueprint.
    return 'text/vnd.apiblueprint';
  }

  if (source.match(LEGACY_BLUEPRINT_TITLE)) {
    // I spotted '--- Sample Title ---' title. This looks like
    // we are dealing with the legacy Apiary Blueprint.
    return 'text/vnd.legacyblueprint';
  }

  if (source.match(API_BLUEPRINT_RESPONSE)) {
    // I can not see the '--- Sample Title ---' and at the same time
    // there is something like '+ Response 200' in the document, which is
    // pretty distinctive for API Blueprint.
    return 'text/vnd.apiblueprint';
  }

  try {
    const json = JSON.parse(source);

    // It looks like the source is a valid JSON file. I suspect it to
    // be a Swagger file.
    if (json.swagger) {
      // Indeed, we are dealing with Swagger file!
      return 'application/swagger+json';
    }

    // Nothing I could identify. Maybe Horadric Cube could magically
    // turn it into a rather smart casual leather armor?

    return null;
  } catch(e) {
    // Well ok, it's not a JSON...Maybe we're dealing with YAML file?
    try {
      const yaml = YAML.safeLoad(source);

      if (yaml.swagger) {
        // Indeed, we are dealing with Swagger file!
        return 'application/swagger+yaml';
      }
    } catch (e) {
      // To be honest, I have no idea.
      return null;
    }

  }
}


export default {identify};
{'fraction_non_alphanumeric': 0.142975893599335, 'fraction_numerical': 0.0072042116929897475, 'mean_word_length': 2.710174717368962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1636189', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1196, 'n_words': 383}