<commit_before>var rndm = require('rndm'),
    Datastore = require('nedb');

var Shorten = function(options) {
  options = options || {};

  this.db = options.db || new Datastore({filename: 'database.db', autoload: true });
  this.chars = options.chars || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
  this.codeLength = options.codeLength || 6;
  this.rndgen = rndm.create(this.chars);

  return this;
};

Shorten.prototype.decode = function(code, cb) {
  this.db.findOne({code: code}, cb);
};

Shorten.prototype.encode = function(obj, cb) {
  var self = this,
      uniqueGencode;

  if (!obj) {
    throw Error('No obj input.')
  }

  if (! (cb instanceof Function)) {
    cb = function() {};
  }

  uniqueGencode = function(code) {
    self.db.find({code: code}, function(err, docs) {
      if (err) {
        cb(err, null);
      }

      if (docs.length) {<commit_msg>Support dbFilename by pass options<commit_after>var rndm = require('rndm'),
    Datastore = require('nedb');

var Shorten = function(options) {
  options = options || {};
  options.dbFilename = options.dbFilename || '/tmp/database.db';
  this.db = options.db || new Datastore({filename: options.dbFilename, autoload: true });
  this.chars = options.chars || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
  this.codeLength = options.codeLength || 6;
  this.rndgen = rndm.create(this.chars);

  return this;
};

Shorten.prototype.decode = function(code, cb) {
  this.db.findOne({code: code}, cb);
};

Shorten.prototype.encode = function(obj, cb) {
  var self = this,
      uniqueGencode;

  if (!obj) {
    throw Error('No obj input.')
  }

  if (! (cb instanceof Function)) {
    cb = function() {};
  }

  uniqueGencode = function(code) {
    self.db.find({code: code}, function(err, docs) {
      if (err) {
        cb(err, null);
      }

      if (docs.length) {
{'fraction_non_alphanumeric': 0.15764331210191082, 'fraction_numerical': 0.01167728237791932, 'mean_word_length': 3.488095238095238, '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': '6133484', 'n_tokens_mistral': 694, 'n_tokens_neox': 658, 'n_words': 135}