<commit_before>import { IHttpContent, IHttpOperation, IHttpResponse } from '@stoplight/types/http';
import { IHttpNegotiationResult } from './types';

function findBestExample(httpContent: IHttpContent) {
  return httpContent.examples && httpContent.examples[0];
}

function findExampleByKey(httpContent: IHttpContent, exampleKey: string) {
  return httpContent.examples && httpContent.examples.find(example => example.key === exampleKey);
}

function findHttpContentByMediaType(
  response: IHttpResponse,
  mediaType: string
): IHttpContent | undefined {
  return response.content.find(content => content.mediaType === mediaType);
}

function findLowest2xx(httpResponses: IHttpResponse[]): IHttpResponse | undefined {
  const generic2xxResponse = findResponseByStatusCode(httpResponses, '2XX');
  const sorted2xxResponses = httpResponses
    .filter(response => response.code.match(/2\d\d/))
    .sort((a: IHttpResponse, b: IHttpResponse) => Number(a.code) - Number(b.code));

  return sorted2xxResponses[0] || generic2xxResponse;
}

function findResponseByStatusCode(
  responses: IHttpResponse[],
  statusCode: string
): IHttpResponse | undefined {
  return responses.find(response => response.code.toLowerCase() === statusCode.toLowerCase());
}

const helpers = {
  negotiateByPartialOptionsAndHttpContent(
    { code, exampleKey, dynamic }: {
      readonly code: string;
      readonly dynamic?: boolean;
      readonly exampleKey?: string;
    },
    httpContent: IHttpContent
  ): IHttpNegotiationResult {
    const { mediaType } = httpContent;

    if (exampleKey) {
      // the user provided exampleKey - highest priority
      const example = findExampleByKey(httpContent, exampleKey);
      if (example) {
        // example exists, return
        return {
          code,
          mediaType,
          example,
        };
      } else {<commit_msg>- fix prettier errors<commit_after>import { IHttpContent, IHttpOperation, IHttpResponse } from '@stoplight/types/http';
import { IHttpNegotiationResult } from './types';

function findBestExample(httpContent: IHttpContent) {
  return httpContent.examples && httpContent.examples[0];
}

function findExampleByKey(httpContent: IHttpContent, exampleKey: string) {
  return httpContent.examples && httpContent.examples.find(example => example.key === exampleKey);
}

function findHttpContentByMediaType(
  response: IHttpResponse,
  mediaType: string
): IHttpContent | undefined {
  return response.content.find(content => content.mediaType === mediaType);
}

function findLowest2xx(httpResponses: IHttpResponse[]): IHttpResponse | undefined {
  const generic2xxResponse = findResponseByStatusCode(httpResponses, '2XX');
  const sorted2xxResponses = httpResponses
    .filter(response => response.code.match(/2\d\d/))
    .sort((a: IHttpResponse, b: IHttpResponse) => Number(a.code) - Number(b.code));

  return sorted2xxResponses[0] || generic2xxResponse;
}

function findResponseByStatusCode(
  responses: IHttpResponse[],
  statusCode: string
): IHttpResponse | undefined {
  return responses.find(response => response.code.toLowerCase() === statusCode.toLowerCase());
}

const helpers = {
  negotiateByPartialOptionsAndHttpContent(
    {
      code,
      exampleKey,
      dynamic,
    }: {
      readonly code: string;
      readonly dynamic?: boolean;
      readonly exampleKey?: string;
    },
    httpContent: IHttpContent
  ): IHttpNegotiationResult {
    const { mediaType } = httpContent;

    if (exampleKey) {
      // the user provided exampleKey - highest priority
      const example = findExampleByKey(httpContent, exampleKey);
      if (example) {
        // example exists, return
        return {
          code,
          mediaType,
          example,
        };
      } else {
{'fraction_non_alphanumeric': 0.10960361798350625, 'fraction_numerical': 0.004788507581803671, 'mean_word_length': 4.033467202141901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '413346', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1068, 'n_words': 235}