<commit_before>import parser from 'bibtex-parse-js';


// constants
const MAX_AUTHORS_IN_REFS = 2;
const MAX_AUTHORS_IN_CITATIONS = 6;
const UNKNOWN_AUTHORS = 'Unknown authors';
const ET_AL = 'et al.';

// utils

function optional(string, fallback) {
  const str = undefined === string ? fallback : string;

  return undefined !== str ? `(${str})` : '';
}

function linkify(string, title) {
  const str = title || string;
  if (/^https?:\/\//.test(string)) {
    return `<a href="${string}" rel="noreferrer noopener">${str}</a>`;
  }

  return string;
}

function linkifyDOI(string) {
  let str = string;
  if (!/^https?:\/\//.test(str)) {
    str = `http://dx.doi.org/${str}`;
  }

  return linkify(str);
}

function linkifyTitle(title, link) {
  if (/^https?:\/\//.test(link)) {
    return linkify(link, title);
  }

  return title;
}

function replaceLaTeXChars(string) {
  // TODO: need more replacements
  return string
    .replace(/\\'e/g, 'é')
    .replace(/\\'\{e\}/g, 'é')
    .replace(/\{/g, '')
    .replace(/\}/g, '')
    .replace(/--/g, '—')
    .replace(/\s+/g, ' ')
  ;
}

// sorting

// first author's latname, then year
function sortCitations(e1, e2) {
  if (!e1.authors[0] || !e1.authors[0].lastname) {
    return 1;
  }

  if (!e2.authors[0] || !e2.authors[0].lastname) {<commit_msg>refactor URL checking in bibtex.js and add positive match for ftp hosted files<commit_after>import parser from 'bibtex-parse-js';


// constants
const MAX_AUTHORS_IN_REFS = 2;
const MAX_AUTHORS_IN_CITATIONS = 6;
const UNKNOWN_AUTHORS = 'Unknown authors';
const ET_AL = 'et al.';

// utils

function optional(string, fallback) {
  const str = undefined === string ? fallback : string;

  return undefined !== str ? `(${str})` : '';
}

function validUrl(string) {
  return (/^https?:\/\//.test(string) || /^ftp:\/\//.test(string))
}

function linkify(string, title) {
  const str = title || string;
  if (validUrl(string)) {
    return `<a href="${string}" rel="noreferrer noopener">${str}</a>`;
  }

  return string;
}

function linkifyDOI(string) {
  let str = string;
  if (!validUrl(str)) {
    str = `http://dx.doi.org/${str}`;
  }

  return linkify(str);
}

function linkifyTitle(title, link) {
  if (validUrl(link)) {
    return linkify(link, title);
  }

  return title;
}

function replaceLaTeXChars(string) {
  // TODO: need more replacements
  return string
    .replace(/\\'e/g, 'é')
    .replace(/\\'\{e\}/g, 'é')
    .replace(/\{/g, '')
    .replace(/\}/g, '')
    .replace(/--/g, '—')
    .replace(/\s+/g, ' ')
  ;
}

// sorting

// first author's latname, then year
function sortCitations(e1, e2) {
  if (!e1.authors[0] || !e1.authors[0].lastname) {
    return 1;
  }

  if (!e2.authors[0] || !e2.authors[0].lastname) {
{'fraction_non_alphanumeric': 0.20394736842105263, 'fraction_numerical': 0.009502923976608187, 'mean_word_length': 3.1722560975609757, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5672707', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1022, 'n_words': 225}