<commit_before>const level = require('level');

module.exports = {
  
  arrayToStringWithCommas: (array, last) => {
    var string = "";
    for (i = 0; i < array.length; i++) {
      if (i == (array.length - 1)) {
        string = string + array[i];
      } else if (i == (array.length - 2)) {
        string = string + array[i] + last;
      } else {
        string = string + array[i] + ", ";
      }
    }
    return string;
  },
  
  initializeDatabase: (path) => {
    let db = level(path);
    
    db.getPromise = (key) => {
      return new Promise((resolve, reject) => {
        db.get(key, (err, res) => {
          if(err) {
            reject(err);
          } else {
            try { res = JSON.parse(res) }
            resolve(res);
          }
        });
      });
    }
    
    db.putPromise = (key, value) => {
      if(typeof value !== 'string') value = JSON.stringify(value);
      return new Promise((resolve, reject) => {
        db.put(key, value, (err) => {
          if(err) reject(err);
          else    resolve();
        });
      });
    }
    
    return db;
  }
}
<commit_msg>FUUUUUUUUUUUUUU.<commit_after>const level = require('level');

module.exports = {
  
  arrayToStringWithCommas: (array, last) => {
    var string = "";
    for (i = 0; i < array.length; i++) {
      if (i == (array.length - 1)) {
        string = string + array[i];
      } else if (i == (array.length - 2)) {
        string = string + array[i] + last;
      } else {
        string = string + array[i] + ", ";
      }
    }
    return string;
  },
  
  initializeDatabase: (path) => {
    let db = level(path);
    
    db.getPromise = (key) => {
      return new Promise((resolve, reject) => {
        db.get(key, (err, res) => {
          if(err) {
            reject(err);
          } else {
            try { res = JSON.parse(res) }
            catch(e) {}
            resolve(res);
          }
        });
      });
    }
    
    db.putPromise = (key, value) => {
      if(typeof value !== 'string') value = JSON.stringify(value);
      return new Promise((resolve, reject) => {
        db.put(key, value, (err) => {
          if(err) reject(err);
          else    resolve();
        });
      });
    }
    
    return db;
  }
}

{'fraction_non_alphanumeric': 0.17207647843485993, 'fraction_numerical': 0.0026678523788350376, 'mean_word_length': 1.5921658986175116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '430710', 'n_tokens_mistral': 742, 'n_tokens_neox': 728, 'n_words': 159}