<commit_before>// node modules
import fs from 'fs';
// npm modules
import homedir from 'homedir';

const configFilePath = `${homedir()}/.urcli/config.json`;

export class Config {
  constructor() {
    try {
      const config = JSON.parse(fs.readFileSync(configFilePath));
      Object.assign(this, config);
    } catch (e) {
      // We can ignore ENOENT and throw on everything else.
      if (e.code !== 'ENOENT') {
        console.error('Error reading from filesystem.');
        throw new Error(e);
      }
    }
  }
  save() {
    const newConfigs = JSON.stringify(this, null, 2);
    try {
      fs.writeFileSync(configFilePath, newConfigs);
    } catch (e) {
      // We can create both the config folder and file on ENOENT and throw on
      // everything else.
      if (e.code !== 'ENOENT') {
        console.error('Error while saving the config file.');
        throw new Error(e);
      }
      fs.mkdirSync(`${homedir()}/.urcli`);
      fs.writeFileSync(configFilePath, newConfigs);
    }
    return this;
  }
}<commit_msg>Export object instead of class<commit_after>// node modules
import fs from 'fs';
// npm modules
import homedir from 'homedir';

const configFilePath = `${homedir()}/.urcli/config.json`;

class Config {
  constructor() {
    try {
      const config = JSON.parse(fs.readFileSync(configFilePath));
      Object.assign(this, config);
    } catch (e) {
      // We can ignore ENOENT and throw on everything else.
      if (e.code !== 'ENOENT') {
        console.error('Error reading from filesystem.');
        throw new Error(e);
      }
    }
  }
  save() {
    const newConfigs = JSON.stringify(this, null, 2);
    try {
      fs.writeFileSync(configFilePath, newConfigs);
    } catch (e) {
      // We can create both the config folder and file on ENOENT and throw on
      // everything else.
      if (e.code !== 'ENOENT') {
        console.error('Error while saving the config file.');
        throw new Error(e);
      }
      fs.mkdirSync(`${homedir()}/.urcli`);
      fs.writeFileSync(configFilePath, newConfigs);
    }
    return this;
  }
}

export const config = new Config();
{'fraction_non_alphanumeric': 0.13377296278850684, 'fraction_numerical': 0.0009420631182289214, 'mean_word_length': 2.5459098497495827, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3906393', 'n_tokens_mistral': 655, 'n_tokens_neox': 653, 'n_words': 190}