<commit_before>/**
 * @public
 * @class utils
 */

/**
 * Converts a base64 string into a Uint8Array of "binary" data.
 *
 * @private
 * @method base64ToUint8
 * @param  {string} base64String The base64 string that you'd like to be converted.
 * @return {Uint8Array} A Uint8Array of converted "binary" audio data.
 */
export function base64ToUint8(base64String) {
  const sB64Enc = base64String.replace(/[^A-Za-z0-9+/]/g, '');
  const nInLen = sB64Enc.length;
  const nOutLen = nInLen * 3 + 1 >> 2;
  const taBytes = new Uint8Array(nOutLen);

  for (let nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
    nMod4 = nInIdx & 3;

    nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;

    if (nMod4 === 3 || nInLen - nInIdx === 1) {

      for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
        taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
      }

      nUint24 = 0;
    }
  }

  return taBytes;
}

/**
 * Strips extraneous stuff from a soundfont and splits the soundfont into a JSON
 * object. Keys are note names and values are base64 encoded strings.
 *
 * @private
 * @method mungeSoundFont
 * @param {string} soundfont A soundfont as a long base64 string
 * @return {object} A JSON representation of all the notes in the font
 */
export function mungeSoundFont(soundfont) {
  const begin = soundfont.indexOf('=', soundfont.indexOf('MIDI.Soundfont.')) + 2;
  const end = soundfont.lastIndexOf('"') + 1;
  const string = (`${soundfont.slice(begin, end)}}`)
    .replace(new RegExp('data:audio/mp3;base64,', 'g'), '')
    .replace(new RegExp('data:audio/mpeg;base64,', 'g'), '')
    .replace(new RegExp('data:audio/ogg;base64,', 'g'), '');

  return JSON.parse(string);
}

function b64ToUint6(nChr) {
  return nChr > 64 && nChr < 91 ?
     nChr - 65
   : nChr > 96 && nChr < 123 ?
     nChr - 71
   : nChr > 47 && nChr < 58 ?
     nChr + 4
   : nChr === 43 ?
     62
   : nChr === 47 ?
     63
   :
     0;
}<commit_msg>b64ToUint6 use switch instead of cryptic ternary<commit_after>/**
 * @public
 * @class utils
 */

/**
 * Converts a base64 string into a Uint8Array of "binary" data.
 *
 * @private
 * @method base64ToUint8
 * @param  {string} base64String The base64 string that you'd like to be converted.
 * @return {Uint8Array} A Uint8Array of converted "binary" audio data.
 */
export function base64ToUint8(base64String) {
  const sB64Enc = base64String.replace(/[^A-Za-z0-9+/]/g, '');
  const nInLen = sB64Enc.length;
  const nOutLen = nInLen * 3 + 1 >> 2;
  const taBytes = new Uint8Array(nOutLen);

  for (let nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
    nMod4 = nInIdx & 3;

    nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;

    if (nMod4 === 3 || nInLen - nInIdx === 1) {

      for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
        taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
      }

      nUint24 = 0;
    }
  }

  return taBytes;
}

/**
 * Strips extraneous stuff from a soundfont and splits the soundfont into a JSON
 * object. Keys are note names and values are base64 encoded strings.
 *
 * @private
 * @method mungeSoundFont
 * @param {string} soundfont A soundfont as a long base64 string
 * @return {object} A JSON representation of all the notes in the font
 */
export function mungeSoundFont(soundfont) {
  const begin = soundfont.indexOf('=', soundfont.indexOf('MIDI.Soundfont.')) + 2;
  const end = soundfont.lastIndexOf('"') + 1;
  const string = (`${soundfont.slice(begin, end)}}`)
    .replace(new RegExp('data:audio/mp3;base64,', 'g'), '')
    .replace(new RegExp('data:audio/mpeg;base64,', 'g'), '')
    .replace(new RegExp('data:audio/ogg;base64,', 'g'), '');

  return JSON.parse(string);
}

function withinRange(val, min, max) {
  return val > min && val < max;
}

function b64ToUint6(nChr) {
  switch(nChr) {
    case withinRange(nChr, 64, 91):
      return nChr - 65;
    case withinRange(nChr, 96, 123):
      return nChr - 71;
    case withinRange(nChr, 47, 58):
      return nChr + 4;
    case 43:
      return 62;
    case 47:
      return 63;
    default:
      return 0;
  }
}
{'fraction_non_alphanumeric': 0.14872891423140888, 'fraction_numerical': 0.054407222618199094, 'mean_word_length': 3.1641938674579624, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '332247', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1550, 'n_words': 436}