<commit_before>"use strict";

var
FilePath    = require('filepath').FilePath,
U           = require('./u'),
Objects     = require('./objects'),
Action      = require('./action'),
initializer = require('./initializer');


exports.newAPI = Objects.factory({

  initialize: function (spec) {
    var
    argv;

    Object.defineProperties(this, {

      Promise : {
        enumerable : true,
        value      : require('./promise')
      },

      print : {
        enumerable : true,
        value      : console.log
      },

      U : {
        enumerable : true,
        value      : U
      },

      factory : {
        enumerable : true,
        value      : Objects.factory
      },

      path : {
        enumerable : true,
        value      : FilePath.create
      },

      initializer : {
        enumerable : true,
        value      : initializer
      },

      action : {
        enumerable : true,
        value      : Action.create
      },

      // Smartly get the application directory.
      appdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.appdir) {
            return FilePath.create(configs.appdir);
          }
          return spec.appdir;
        }
      },

      // Smartly get the system configurations directory.
      sysconfigsdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.sysconfigsdir) {
            return FilePath.create(configs.sysconfigsdir);
          }
          return spec.sysconfigsdir;
        }
      },

      // Smartly get the user configurations directory.
      usrconfigsdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.usrconfigsdir) {
            return FilePath.create(configs.usrconfigsdir);
          }
          return spec.usrconfigsdir;
        }
      },

      // Set and get the commandline argv.
      argv : {
        enumerable : true,
        value      : function (val) {
          if (argv) {
            return argv;
          }
          argv = val;
          return argv;
        }
      }
    });
  },

  freeze: function () {
    var
    api,
    self = this;
    api = Object.keys(self).reduce(function (api, key) {
      api[key] = self[key];
      return api;
    }, Object.create(null));
    return Object.freeze(api);
  }
});<commit_msg>fixes #38 and makes API.configs a getter/setter<commit_after>"use strict";

var
FilePath    = require('filepath').FilePath,
U           = require('./u'),
Objects     = require('./objects'),
Action      = require('./action'),
initializer = require('./initializer');


exports.newAPI = Objects.factory({

  initialize: function (spec) {
    var
    argv, _configs;

    Object.defineProperties(this, {

      Promise : {
        enumerable : true,
        value      : require('./promise')
      },

      print : {
        enumerable : true,
        value      : console.log
      },

      U : {
        enumerable : true,
        value      : U
      },

      factory : {
        enumerable : true,
        value      : Objects.factory
      },

      path : {
        enumerable : true,
        value      : FilePath.create
      },

      initializer : {
        enumerable : true,
        value      : initializer
      },

      action : {
        enumerable : true,
        value      : Action.create
      },

      // Smartly get the application directory.
      appdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.appdir) {
            return FilePath.create(configs.appdir);
          }
          return spec.appdir;
        }
      },

      // Smartly get the system configurations directory.
      sysconfigsdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.sysconfigsdir) {
            return FilePath.create(configs.sysconfigsdir);
          }
          return spec.sysconfigsdir;
        }
      },

      // Smartly get the user configurations directory.
      usrconfigsdir : {
        enumerable : true,
        value      : function (configs) {
          configs = configs || Object.create(null);
          if (configs.usrconfigsdir) {
            return FilePath.create(configs.usrconfigsdir);
          }
          return spec.usrconfigsdir;
        }
      },

      // Set and get the commandline argv.
      argv : {
        enumerable : true,
        value      : function (val) {
          if (argv) {
            return argv;
          }
          argv = val;
          return argv;
        }
      },

      configs : {
        enumerable : true,
        set : function (val) {
          if (typeof _configs === 'undefined') {
            if (typeof val !== 'object' || val === null) {
              throw new Error('API.configs must be an Object.');
            }
            _configs = val;
          } else {
            throw new Error('API.configs is already set.');
          }
        },
        get : function () {
          return _configs;
        }
      }
    });
  },

  freeze: function () {
    var
    api,
    self = this;
    api = Object.keys(self).reduce(function (api, key) {
      api[key] = self[key];
      return api;
    }, Object.create(null));
    return Object.freeze(api);
  }
});
{'fraction_non_alphanumeric': 0.11248654467168999, 'fraction_numerical': 0.0003588087549336204, 'mean_word_length': 1.4376912986445125, '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': '1238991', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1535, 'n_words': 353}