<commit_before>/*
 * Helpers to manage action on configuration changes.
 */

var fs = require('fs-extra');
var nodeHelpers = require('./node-helpers');


var configWatcher = function (path){

  var pW = {

    mainWatcher: null,
    watchers: [],

    trigger: function () {
      pW.watchers.forEach(nodeHelpers.invoke);
    },

    on: function (newWatcher) {
      var index = pW.watchers.indexOf(newWatcher);
      if (index === -1) { pW.watchers.push(newWatcher); }
    },

    off: function (watcher) {
      this.watchers.splice(pW.watchers.indexOf(watcher), 1);
    },

    one: function (watcher) {
      var oner = function () {
        pW.off(oner);
        nodeHelpers.invoke(watcher);
      };
      pW.on(oner);
    },

    release: function () {
      fs.unwatchFile(path, pW.trigger);
      pW.watchers = [];
      pW.mainWatcher = null;
    }
  };

  var options = {persistent: false, interval: 1000};
  pW.mainWatcher = fs.watchFile(
    path, options, pW.trigger
  );

  return pW;
};
module.exports = configWatcher;<commit_msg>rename pW to instance<commit_after>/*
 * Helpers to manage action on configuration changes.
 */

var fs = require('fs-extra');
var nodeHelpers = require('./node-helpers');


var configWatcher = function (path){

  var instance = {

    mainWatcher: null,
    watchers: [],

    trigger: function () {
      instance.watchers.forEach(nodeHelpers.invoke);
    },

    on: function (newWatcher) {
      var index = instance.watchers.indexOf(newWatcher);
      if (index === -1) {
        instance.watchers.push(newWatcher);
      }
    },

    off: function (watcher) {
      this.watchers.splice(instance.watchers.indexOf(watcher), 1);
    },

    one: function (watcher) {
      var oner = function () {
        instance.off(oner);
        nodeHelpers.invoke(watcher);
      };
      instance.on(oner);
    },

    release: function () {
      fs.unwatchFile(path, instance.trigger);
      instance.watchers = [];
      instance.mainWatcher = null;
    }
  };

  var options = {persistent: false, interval: 1000};
  instance.mainWatcher = fs.watchFile(
    path, options, instance.trigger
  );

  return instance;
};
module.exports = configWatcher;
{'fraction_non_alphanumeric': 0.1431175934366454, 'fraction_numerical': 0.0054694621695533276, 'mean_word_length': 2.6461794019933556, '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': '3998689', 'n_tokens_mistral': 732, 'n_tokens_neox': 705, 'n_words': 146}