<commit_before>
var os = require('os')
var fs = require('mz/fs')
var path = require('path')
var assert = require('assert')
var lru = require('lru-cache')
var memo = require('memorizer')
var db = require('polyfills-db')
var crypto = require('mz/crypto')
var gzip = require('mz/zlib').gzip
var inherits = require('util').inherits
var convert = require('convert-source-map')
var Promise = require('native-or-bluebird')
var debug = require('debug')('ecstacy:ecstacy')

var tmpdir = os.tmpdir
  ? os.tmpdir()
  : os.tmpDir()

module.exports = Ecstacy

var folder =
Ecstacy.folder =
Ecstacy.prototype.folder = path.resolve(tmpdir, 'ecstacy')
require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))

// clean the cache folder
Ecstacy.clean = function () {
  require('rimraf').sync(Ecstacy.folder)
  require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
  require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))
}

function Ecstacy() {}

Ecstacy.extend = function (constructor) {
  inherits(constructor, Ecstacy)
  return constructor
}

// default LRU cache options
Ecstacy.cache = {
  max: 100,
  maxAge: Infinity,
}

memo(Ecstacy.prototype, 'cache', function () {
  return lru(Ecstacy.cache)
})

/**
 * Builds a specific transform and returns the JSON data.
 */

Ecstacy.prototype.build = function (agents) {
  var self = this
  var transforms = this._filter(agents)
  if (!transforms.length) { // no transforms
    debug('building %o -> %o', agents, transforms.hash)
    if (this.code == null) return this.read(self.hash, '.json')
    return this._initialize().then(function () {
      return self.read(self.hash, '.json')
    })
  }
  var name = this.hash + '.' + transforms.hash
  return self.readSafely(name, '.json').then(function (json) {
    if (json) return json<commit_msg>fix .extend()<commit_after>
var os = require('os')
var fs = require('mz/fs')
var path = require('path')
var assert = require('assert')
var lru = require('lru-cache')
var memo = require('memorizer')
var db = require('polyfills-db')
var crypto = require('mz/crypto')
var gzip = require('mz/zlib').gzip
var inherits = require('util').inherits
var convert = require('convert-source-map')
var Promise = require('native-or-bluebird')
var debug = require('debug')('ecstacy:ecstacy')

var tmpdir = os.tmpdir
  ? os.tmpdir()
  : os.tmpDir()

module.exports = Ecstacy

var folder =
Ecstacy.folder =
Ecstacy.prototype.folder = path.resolve(tmpdir, 'ecstacy')
require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))

// clean the cache folder
Ecstacy.clean = function () {
  require('rimraf').sync(Ecstacy.folder)
  require('mkdirp').sync(path.join(Ecstacy.folder, 'js'))
  require('mkdirp').sync(path.join(Ecstacy.folder, 'css'))
}

function Ecstacy() {}

Ecstacy.extend = function (constructor) {
  inherits(constructor, Ecstacy)
  Object.keys(Ecstacy).forEach(function (key) {
    if (!constructor[key]) constructor[key] = Ecstacy[key]
  })
  return constructor
}

// default LRU cache options
Ecstacy.cache = {
  max: 100,
  maxAge: Infinity,
}

memo(Ecstacy.prototype, 'cache', function () {
  return lru(Ecstacy.cache)
})

/**
 * Builds a specific transform and returns the JSON data.
 */

Ecstacy.prototype.build = function (agents) {
  var self = this
  var transforms = this._filter(agents)
  if (!transforms.length) { // no transforms
    debug('building %o -> %o', agents, transforms.hash)
    if (this.code == null) return this.read(self.hash, '.json')
    return this._initialize().then(function () {
      return self.read(self.hash, '.json')
    })
  }
  var name = this.hash + '.' + transforms.hash
  return self.readSafely(name, '.json').then(function (json) {
    if (json) return json
{'fraction_non_alphanumeric': 0.16834038054968287, 'fraction_numerical': 0.0015856236786469344, 'mean_word_length': 4.4855072463768115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7506993', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1288, 'n_words': 288}