<commit_before>let watcher = null
try {
  watcher = require('../build/Release/watcher.node')
} catch (err) {
  watcher = require('../build/Debug/watcher.node')
}

// Private: Logging mode constants
const DISABLE = Symbol('disable')
const STDERR = Symbol('stderr')
const STDOUT = Symbol('stdout')

function logOption (baseName, options, normalized) {
  const value = options[baseName]

  if (value === undefined) return

  if (value === DISABLE) {
    normalized[`${baseName}Disable`] = true
    return
  }

  if (value === STDERR) {
    normalized[`${baseName}Stderr`] = true
    return
  }

  if (value === STDOUT) {
    normalized[`${baseName}Stdout`] = true
    return
  }

  if (typeof value === 'string' || value instanceof String) {
    normalized[`${baseName}File`] = value
    return
  }

  throw new Error(`option ${baseName} must be DISABLE, STDERR, STDOUT, or a filename`)
}

function configure (options) {
  if (!options) {
    return Promise.reject(new Error('configure() requires an option object'))
  }

  const normalized = {}

  logOption('mainLog', options, normalized)
  logOption('workerLog', options, normalized)
  logOption('pollingLog', options, normalized)

  if (options.pollingThrottle) normalized.pollingThrottle = options.pollingThrottle
  if (options.pollingInterval) normalized.pollingInterval = options.pollingInterval

  return new Promise((resolve, reject) => {
    watcher.configure(normalized, err => (err ? reject(err) : resolve(err)))
  })
}

module.exports = {
  watch: watcher.watch,
  unwatch: watcher.unwatch,
  configure,
  status: watcher.status,

  DISABLE,
  STDERR,
  STDOUT
}<commit_msg>Lazily require native bindings<commit_after>let watcher = null

function getWatcher () {
  if (!watcher) {
    try {
      watcher = require('../build/Release/watcher.node')
    } catch (err) {
      watcher = require('../build/Debug/watcher.node')
    }
  }
  return watcher
}

// Private: Logging mode constants
const DISABLE = Symbol('disable')
const STDERR = Symbol('stderr')
const STDOUT = Symbol('stdout')

function logOption (baseName, options, normalized) {
  const value = options[baseName]

  if (value === undefined) return

  if (value === DISABLE) {
    normalized[`${baseName}Disable`] = true
    return
  }

  if (value === STDERR) {
    normalized[`${baseName}Stderr`] = true
    return
  }

  if (value === STDOUT) {
    normalized[`${baseName}Stdout`] = true
    return
  }

  if (typeof value === 'string' || value instanceof String) {
    normalized[`${baseName}File`] = value
    return
  }

  throw new Error(`option ${baseName} must be DISABLE, STDERR, STDOUT, or a filename`)
}

function configure (options) {
  if (!options) {
    return Promise.reject(new Error('configure() requires an option object'))
  }

  const normalized = {}

  logOption('mainLog', options, normalized)
  logOption('workerLog', options, normalized)
  logOption('pollingLog', options, normalized)

  if (options.pollingThrottle) normalized.pollingThrottle = options.pollingThrottle
  if (options.pollingInterval) normalized.pollingInterval = options.pollingInterval

  return new Promise((resolve, reject) => {
    getWatcher().configure(normalized, err => (err ? reject(err) : resolve(err)))
  })
}

function lazy (key) {
  return function (...args) {
    getWatcher()[key](...args)
  }
}

module.exports = {
  watch: lazy('watch'),
  unwatch: lazy('unwatch'),
  configure,
  status: lazy('status'),

  DISABLE,
  STDERR,
  STDOUT
}
{'fraction_non_alphanumeric': 0.14306316700317276, 'fraction_numerical': 0.0, 'mean_word_length': 3.9899280575539566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2918026', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1104, 'n_words': 268}