<commit_before>/* global self */
'use strict'

const isNode = require('detect-node')
const path = require('path')

module.exports = function loadFixtures (filePath, module) {
  // note: filePath needs to be relative to the module root
  if (module) {
    filePath = path.join('node_modules', module, filePath)
  }

  if (isNode) {
    return require('fs').readFileSync(path.join(process.cwd(), filePath))
  } else {
    return syncXhr(filePath)
  }
}

// @dignifiedquire: I know this is considered bad practice, but it makes testing life so much nicer!
function syncXhr (filePath) {
  const target = path.join('/base', filePath)

  const request = new self.XMLHttpRequest()
  request.open('GET', target, false)
  request.overrideMimeType('text/plain; charset=x-user-defined')
  request.send(null)

  if (request.status === 200) {
    const filestream = request.responseText
    let res = new Uint8Array(filestream.length)

    for (let i = 0; i < filestream.length; i++) {
      res[i] = filestream.charCodeAt(i) & 0xff
    }

    return Buffer.from(res)
  }
}<commit_msg>fix: throw an error if fixture is not found<commit_after>/* global self */
'use strict'

const isNode = require('detect-node')
const path = require('path')

module.exports = function loadFixtures (filePath, module) {
  // note: filePath needs to be relative to the module root
  if (module) {
    filePath = path.join('node_modules', module, filePath)
  }

  if (isNode) {
    return require('fs').readFileSync(path.join(process.cwd(), filePath))
  } else {
    return syncXhr(filePath)
  }
}

// @dignifiedquire: I know this is considered bad practice (syncXhr), but it
// makes testing life so much nicer!
function syncXhr (filePath) {
  const target = path.join('/base', filePath)

  const request = new self.XMLHttpRequest()
  request.open('GET', target, false)
  request.overrideMimeType('text/plain; charset=x-user-defined')
  request.send(null)

  if (request.status === 200) {
    const filestream = request.responseText
    let res = new Uint8Array(filestream.length)

    for (let i = 0; i < filestream.length; i++) {
      res[i] = filestream.charCodeAt(i) & 0xff
    }

    return Buffer.from(res)
  } else {
    throw new Error('Could not get the Fixture')
  }
}
{'fraction_non_alphanumeric': 0.1303960836671117, 'fraction_numerical': 0.0053404539385847796, 'mean_word_length': 3.7326315789473683, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4353457', 'n_tokens_mistral': 752, 'n_tokens_neox': 726, 'n_words': 207}