<commit_before>'use strict'

// const format = require('../util/sprintf').sprintf
// const callr  = require('./callsite')
const nano   = require('../time/nano')
const slice  = require('../array/slice')
const jlog   = require('../util/jcolorz')
const clrz   = require('../util/colorz')
// const xtend  = require('../object/xtend')
// const reduce = require('../array/reduce')
// const apply  = require('../function/apply')
// const diff   = require('../assertion/variable-diff')

function dlogr () {
  // don't penalize a single string/template being passed as a param
  arguments.length > 1
    ? dlogr._stdout.write(dlogr._log(slice(arguments).join(' ')))
    : dlogr._stdout.write(dlogr._log(arguments[0]))
}

dlogr.level = 1
dlogr.colors = true
dlogr.timer = false
dlogr._inspector = jlog // expose json-colorz
dlogr._colorizr = clrz // expose colorz
dlogr._stdout = process.stdout
dlogr._stderr = process.stderr
dlogr._procname = process.argv[1].split('/').pop()
dlogr._pointer = {
  tick       : '✔',
  check      : '√',
  cross      : '✖',
  star       : '★',
  bullet     : '*',
  dot        : '․',
  line       : '─',
  dash       : '-',
  ellipsis   : '…',
  info       : 'i',
  info2      : 'ℹ',
  warning    : '‼',
  warning2   : '⚠',
  flag       : '⚑',
  mark       : '✗',
  tilde      : '~',
  clip       : '❯',
  single     : '›',
  double     : '»',
  arrowUp    : '↑',
  arrowDown  : '↓',
  arrowLeft  : '←',
  arrowRight : '→',
  radioOn    : '◉',
  radioOff   : '◯'
}

dlogr.blk = clrz.black
dlogr.blu = clrz.cyan
dlogr.mag = clrz.magenta
dlogr.yel = clrz.yellow
dlogr.red = clrz.red
dlogr.grn = clrz.green
dlogr.gry = clrz.grey
dlogr.cyn = clrz.cyan
dlogr.fmt = clrz.wrap
dlogr.dim = (str) => {
  return clrz.wrap(str, ['dim', 'black'])
}

// implement base start and stop times
// adopted from debug-logger
dlogr.timeTables = {}

dlogr.strt = function time (label) {
  if (Array.isArray(label)) {
    map(label, (lab) => {
      dlogr.timeTables[lab] = process.hrtime()
    })
  }

  else {
    dlogr.timeTables[label] = process.hrtime()
  }
}

dlogr.stop = function timeEnd (label) {
  let diff = process.hrtime(dlogr.timeTables[label])
  let diffMs = nano(diff, 'ms', 3)

  if (dlogr.level !== -1 && dlogr.timer) {
    let msg = `took: ${dlogr._color(diffMs, 'grey')} ms`

    let frmt = {
      prefix: ['timer', 'white'],
      prompt: [dlogr._pointer.double, 'red'],
      name: label,
      color: 'grey'
    }

    dlogr._stdout.write(dlogr._log(msg,
      dlogr._level(frmt),
      dlogr._label()
    ))
  }

  delete dlogr.timeTables[label]
  return diffMs
}

dlogr._color = function (label, color) {
  if (!color || !dlogr.colors) return label
  return dlogr._colorizr[color](label)
}

dlogr._log = function (log, level, label) {
  log = `${log}\n`
  if (level) log = `${level} ${log}`
  if (label) log = `${label} ${log}\n`

  return log
}

dlogr._label = function () {
  return `${dlogr._procname} ${dlogr._pointer.double}`
}

dlogr._level = function (obj) {
  let msg
  let prefix
  let prompt
  obj = obj || {}

  // the prompt is essentially a separator.
  if (obj.prompt) {
    if (Array.isArray(obj.prompt)) {
      prompt = dlogr._color(obj.prompt[0], obj.prompt[1])
    } else {
      prompt = dlogr._color(obj.prompt)
    }
  } else {
    prompt = ''
  }
  if (obj.prefix) {
    if (Array.isArray(obj.prefix)) {
      prefix = dlogr._color(obj.prefix[0], obj.prefix[1]) + ' '+prompt + ' '
    } else {
      prefix = dlogr._color(obj.prefix) + ' '+prompt + ' '
    }
  } else {
    prefix = ''
  }

  if (Array.isArray(obj.name)) {
    msg = map(obj.name, (lvlname, idx) => {
      let sp
      let prompto = ' '+prompt+' '
      if (idx === obj.name.length - 1) prompto = ' '+prompt
      if (idx === 0) sp = ''
      else sp = prefix ? '' : ' '

      return sp + dlogr._color(lvlname, obj.color[idx]) + (prefix ? prompto : prompt)
    }).join('')
  } else {
    msg = dlogr._color(obj.name, obj.color) + (prefix ? ' '+prompt : prompt)
  }

  return obj.name ? prefix + msg : dlogr._color('inspect ', 'cyan') + dlogr._pointer.double
}

module.exports = dlogr
<commit_msg>update debug/logr — clean up<commit_after>'use strict'

const nano   = require('../time/nano')
const slice  = require('../array/slice')
const jlog   = require('../util/jcolorz')
const clrz   = require('../util/colorz')

function logr () {
  // don't penalize a single string/template being passed as a param
  arguments.length > 1
    ? logr._stdout.write(logr._log(slice(arguments).join(' ')))
    : logr._stdout.write(logr._log(arguments[0]))
}

function loggr () {
  logr._stdout.write(logr._log(
    slice(arguments, 1).join(' '),
    logr._level({name: arguments[0]}),
    logr._label()
  ))
}
logr.log = loggr
logr.level = 1
logr.colors = true
logr.timer = false

logr.nano = nano // expose nano
logr._inspector = jlog // expose json-colorz
logr._colorizr = clrz // expose colorz
logr._stdout = process.stdout
logr._stderr = process.stderr
logr._procname = process.argv[1].split('/').pop()
logr._pointer = {
  tick       : '✔',
  check      : '√',
  cross      : '✖',
  star       : '★',
  bullet     : '*',
  dot        : '․',
  line       : '─',
  dash       : '-',
  ellipsis   : '…',
  info       : 'i',
  info2      : 'ℹ',
  warning    : '‼',
  warning2   : '⚠',
  flag       : '⚑',
  mark       : '✗',
  tilde      : '~',
  clip       : '❯',
  single     : '›',
  double     : '»',
  arrowUp    : '↑',
  arrowDown  : '↓',
  arrowLeft  : '←',
  arrowRight : '→',
  radioOn    : '◉',
  radioOff   : '◯'
}

logr.blk = clrz.black
logr.blu = clrz.cyan
logr.mag = clrz.magenta
logr.yel = clrz.yellow
logr.red = clrz.red
logr.grn = clrz.green
logr.gry = clrz.grey
logr.cyn = clrz.cyan
logr.fmt = clrz.wrap
logr.dim = (str) => {
  return clrz.wrap(str, ['dim', 'black'])
}

// implement base start and stop times
// adopted from debug-logger
logr.timeTables = {}

logr.strt = function time (label) {
  if (Array.isArray(label)) {
    map(label, (lab) => {
      logr.timeTables[lab] = process.hrtime()
    })
  }

  else {
    logr.timeTables[label] = process.hrtime()
  }
}

logr.stop = function timeEnd (label) {
  let diff = process.hrtime(logr.timeTables[label])
  let diffMs = nano(diff, 'ms', 3)

  if (logr.level !== -1 && logr.timer) {
    let msg = `took: ${logr._color(diffMs, 'grey')} ms`

    let frmt = {
      prefix: ['timer', 'white'],
      prompt: [logr._pointer.double, 'red'],
      name: label,
      color: 'grey'
    }

    logr._stdout.write(logr._log(msg,
      logr._level(frmt),
      logr._label()
    ))
  }

  delete logr.timeTables[label]
  return diffMs
}

logr._color = function (label, color) {
  if (!color || !logr.colors) return label
  return logr._colorizr[color](label)
}

logr._log = function (log, level, label) {
  log = `${log}\n`
  if (level) log = `${level} ${log}`
  if (label) log = `${label} ${log}`

  return log
}

logr._label = function () {
  return `${logr._procname} ${logr._pointer.double}`
}

logr._level = function (obj) {
  let msg
  let prefix
  let prompt
  obj = obj || {}

  // the prompt is essentially a separator.
  if (obj.prompt) {
    if (Array.isArray(obj.prompt)) {
      prompt = logr._color(obj.prompt[0], obj.prompt[1])
    } else {
      prompt = logr._color(obj.prompt)
    }
  } else {
    prompt = ''
  }
  if (obj.prefix) {
    if (Array.isArray(obj.prefix)) {
      prefix = logr._color(obj.prefix[0], obj.prefix[1]) + ' '+prompt + ' '
    } else {
      prefix = logr._color(obj.prefix) + ' '+prompt + ' '
    }
  } else {
    prefix = ''
  }

  if (Array.isArray(obj.name)) {
    msg = map(obj.name, (lvlname, idx) => {
      let sp
      let prompto = ' '+prompt+' '
      if (idx === obj.name.length - 1) prompto = ' '+prompt
      if (idx === 0) sp = ''
      else sp = prefix ? '' : ' '

      return sp + logr._color(lvlname, obj.color[idx]) + (prefix ? prompto : prompt)
    }).join('')
  } else {
    msg = logr._color(obj.name, obj.color) + (prefix ? ' '+prompt : prompt)
  }

  return obj.name ? prefix + msg : ''
}

module.exports = logr

{'fraction_non_alphanumeric': 0.1856361829025845, 'fraction_numerical': 0.003727634194831014, 'mean_word_length': 2.5271691498685365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4693868', 'n_tokens_mistral': 3159, 'n_tokens_neox': 3112, 'n_words': 657}