<commit_before>'use babel';

// Lazy load node modules
let fs;
let mime;
let imageSize;
let moment;

const KIBIBYTE_BASE = 1024;

const SI_BASE = 1000;

const FORMAT_24_HOUR = 'HH:mm:ss';

const FORMAT_12_HOUR = 'h:mm:ss a';

const KIBIBYTE_REPRESENTATION = [
  'bytes',
  'KiB',
  'MiB',
  'GiB',
  'TiB',
  'PiB',
  'EiB',
  'ZiB',
  'YiB',
];

const SI_REPRESENTATION = [
  'bytes',
  'KB',
  'MB',
  'GB',
  'TB',
  'PB',
  'EB',
  'ZB',
  'YB',
];

const IMAGE_FORMATS = [
  'image/bmp',
  'imagem/jpeg',
  'image/png',
  'image/gif',
  'image/tiff',
  'image/x-tiff',
  'image/webp',
  'image/vnd.adobe.photoshop',
];

function loadFileInfoAsync(filepath) {
  fs = fs || require('fs');
  return new Promise((resolve, reject) => {
    if (filepath) {
      fs.stat(filepath, (err, stats) => {
        if (!err) {
          const info = {
            absolutePath: filepath,
            size: stats.size,
            dateCreated: stats.birthtime,
            dateChanged: stats.mtime,
          };
          resolve(info);
        } else {
          reject(new Error('Can\'t get size for the current path'));
        }
      });
    } else {
      reject(new Error('Please provide a valid filepath'));
    }
  });
}

function addPrettySize(info, { useKibibyteRepresentation = true }) {
  const { size } = info;
  if (size === 0) return Object.assign(info, { prettySize: '0 bytes' });
  if (size === 1) return Object.assign(info, { prettySize: '1 byte' });
  const base = (useKibibyteRepresentation) ? KIBIBYTE_BASE : SI_BASE;
  const suffixes = (useKibibyteRepresentation) ? KIBIBYTE_REPRESENTATION : SI_REPRESENTATION;
  const scale = Math.floor(Math.log(size) / Math.log(base));
  const activeSuffix = suffixes[scale];
  const scaledSize = size / Math.pow(base, scale);
  // Round size with a decimal precision of 2
  const fixedScale = Math.round(`${scaledSize}e+2`);<commit_msg>loadInfoAsync now rejects with full error object from fs<commit_after>'use babel';

// Lazy load node modules
let fs;
let mime;
let imageSize;
let moment;

const KIBIBYTE_BASE = 1024;

const SI_BASE = 1000;

const FORMAT_24_HOUR = 'HH:mm:ss';

const FORMAT_12_HOUR = 'h:mm:ss a';

const KIBIBYTE_REPRESENTATION = [
  'bytes',
  'KiB',
  'MiB',
  'GiB',
  'TiB',
  'PiB',
  'EiB',
  'ZiB',
  'YiB',
];

const SI_REPRESENTATION = [
  'bytes',
  'KB',
  'MB',
  'GB',
  'TB',
  'PB',
  'EB',
  'ZB',
  'YB',
];

const IMAGE_FORMATS = [
  'image/bmp',
  'imagem/jpeg',
  'image/png',
  'image/gif',
  'image/tiff',
  'image/x-tiff',
  'image/webp',
  'image/vnd.adobe.photoshop',
];

function loadFileInfoAsync(filepath) {
  fs = fs || require('fs');
  return new Promise((resolve, reject) => {
    if (filepath) {
      fs.stat(filepath, (err, stats) => {
        if (!err) {
          const info = {
            absolutePath: filepath,
            size: stats.size,
            dateCreated: stats.birthtime,
            dateChanged: stats.mtime,
          };
          resolve(info);
        } else {
          reject(err);
        }
      });
    } else {
      reject(new Error('Please provide a valid filepath'));
    }
  });
}

function addPrettySize(info, { useKibibyteRepresentation = true }) {
  const { size } = info;
  if (size === 0) return Object.assign(info, { prettySize: '0 bytes' });
  if (size === 1) return Object.assign(info, { prettySize: '1 byte' });
  const base = (useKibibyteRepresentation) ? KIBIBYTE_BASE : SI_BASE;
  const suffixes = (useKibibyteRepresentation) ? KIBIBYTE_REPRESENTATION : SI_REPRESENTATION;
  const scale = Math.floor(Math.log(size) / Math.log(base));
  const activeSuffix = suffixes[scale];
  const scaledSize = size / Math.pow(base, scale);
  // Round size with a decimal precision of 2
  const fixedScale = Math.round(`${scaledSize}e+2`);
{'fraction_non_alphanumeric': 0.15707084107190236, 'fraction_numerical': 0.009551605200318386, 'mean_word_length': 2.9476439790575917, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3919620', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1413, 'n_words': 316}