<commit_before>const { sep, resolve } = require("path");
const fs = require("fs-nextra");

let baseDir;

/* eslint-disable no-confusing-arrow */
exports.init = (client) => {
  baseDir = resolve(`${client.clientBaseDir}${sep}bwd${sep}conf`);
  return fs.ensureDir(baseDir).catch(err => client.emit("log", err, "error"));
};

/* Table methods */

/**
 * Checks if a directory exists.
 * @param {string} table The name of the table you want to check.
 * @returns {Promise<boolean>}
 */
exports.hasTable = table => fs.pathExists(baseDir + sep + table);

/**
 * Creates a new directory.
 * @param {string} table The name for the new directory.
 * @returns {Promise<Void>}
 */
exports.createTable = table => fs.mkdir(baseDir + sep + table);

/**
 * Recursively deletes a directory.
 * @param {string} table The directory's name to delete.
 * @returns {Promise<Void>}
 */
exports.deleteTable = table => this.hasTable(table)
  .then(exists => exists ? fs.emptyDir(baseDir + sep + table).then(() => fs.remove(baseDir + sep + table)) : null);

/* Document methods */

/**
 * Get all documents from a directory.
 * @param {string} table The name of the directory to fetch from.
 * @returns {Promise<Object[]>}
 */
exports.getAll = (table) => {
  const dir = baseDir + sep + table + sep;
  return fs.readdir(dir)
    .then(files => Promise.all(files.map(file => fs.readJSON(dir + file))));
};

/**
 * Get a document from a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @returns {Promise<?Object>}
 */
exports.get = (table, document) => fs.readJSON(`${baseDir + sep + table + sep + document}.json`).catch(() => null);

/**
 * Get a random document from a directory.
 * @param {string} table The name of the directory.
 * @returns {Promise<Object>}
 */
exports.getRandom = table => this.getAll(table).then(data => data[Math.floor(Math.random() * data.length)]);

/**
 * Insert a new document into a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The object with all properties you want to insert into the document.
 * @returns {Promise<Void>}
 */
exports.create = (table, document, data) => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, Object.assign(data, { id: document }));

/**
 * Update a document from a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The object with all the properties you want to update.
 * @returns {Promise<Void>}
 */
exports.update = (table, document, data) => this.get(table, document)
  .then(current => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, Object.assign(current, data)));

/**
 * Replace all the data from a document.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The new data for the document.
 * @returns {Promise<Void>}
 */
exports.replace = (table, document, data) => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, data);

/**
 * Delete a document from the table.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @returns {Promise<Void>}
 */
exports.delete = (table, document) => fs.unlink(`${baseDir + sep + table + sep + document}.json`);

exports.conf = {
  moduleName: "json",
  enabled: true,
  requiredModules: [],
};

exports.help = {
  name: "json",
  type: "providers",
  description: "Allows you to use JSON functionality throught Komada",
};
<commit_msg>Change the folder the provider stores the configs (#287)<commit_after>const { sep, resolve } = require("path");
const fs = require("fs-nextra");

let baseDir;

exports.init = (client) => {
  baseDir = resolve(client.clientBaseDir, "bwd", "provider", "json");
  return fs.ensureDir(baseDir).catch(err => client.emit("log", err, "error"));
};

/* Table methods */

/**
 * Checks if a directory exists.
 * @param {string} table The name of the table you want to check.
 * @returns {Promise<boolean>}
 */
exports.hasTable = table => fs.pathExists(baseDir + sep + table);

/**
 * Creates a new directory.
 * @param {string} table The name for the new directory.
 * @returns {Promise<Void>}
 */
exports.createTable = table => fs.mkdir(baseDir + sep + table);

/**
 * Recursively deletes a directory.
 * @param {string} table The directory's name to delete.
 * @returns {Promise<Void>}
 */
exports.deleteTable = table => this.hasTable(table)
  .then(exists => (exists ? fs.emptyDir(baseDir + sep + table).then(() => fs.remove(baseDir + sep + table)) : null));

/* Document methods */

/**
 * Get all documents from a directory.
 * @param {string} table The name of the directory to fetch from.
 * @returns {Promise<Object[]>}
 */
exports.getAll = (table) => {
  const dir = baseDir + sep + table + sep;
  return fs.readdir(dir)
    .then(files => Promise.all(files.map(file => fs.readJSON(dir + file))));
};

/**
 * Get a document from a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @returns {Promise<?Object>}
 */
exports.get = (table, document) => fs.readJSON(`${baseDir + sep + table + sep + document}.json`).catch(() => null);

/**
 * Get a random document from a directory.
 * @param {string} table The name of the directory.
 * @returns {Promise<Object>}
 */
exports.getRandom = table => this.getAll(table).then(data => data[Math.floor(Math.random() * data.length)]);

/**
 * Insert a new document into a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The object with all properties you want to insert into the document.
 * @returns {Promise<Void>}
 */
exports.create = (table, document, data) => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, Object.assign(data, { id: document }));

/**
 * Update a document from a directory.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The object with all the properties you want to update.
 * @returns {Promise<Void>}
 */
exports.update = (table, document, data) => this.get(table, document)
  .then(current => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, Object.assign(current, data)));

/**
 * Replace all the data from a document.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @param {Object} data The new data for the document.
 * @returns {Promise<Void>}
 */
exports.replace = (table, document, data) => fs.outputJSON(`${baseDir + sep + table + sep + document}.json`, data);

/**
 * Delete a document from the table.
 * @param {string} table The name of the directory.
 * @param {string} document The document name.
 * @returns {Promise<Void>}
 */
exports.delete = (table, document) => fs.unlink(`${baseDir + sep + table + sep + document}.json`);

exports.conf = {
  moduleName: "json",
  enabled: true,
  requiredModules: ["fs-nextra"],
};

exports.help = {
  name: "json",
  type: "providers",
  description: "Allows you to use JSON functionality throught Komada",
};

{'fraction_non_alphanumeric': 0.16030323914541694, 'fraction_numerical': 0.0004135079255685734, 'mean_word_length': 4.038888888888889, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 61, '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': '3051759', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2203, 'n_words': 752}