<commit_before>


############################################################################################################
njs_path                  = require 'path'
njs_fs                    = require 'fs'
njs_util                  = require 'util'
rpr                       = njs_util.inspect
CND                       = require './main'
@flatten                  = require 'lodash.flattendeep'

#-----------------------------------------------------------------------------------------------------------
@equals = ( P... ) -> ( require './jkroso-equals' ) P...

#-----------------------------------------------------------------------------------------------------------
@is_empty = ( x ) ->
  return ( x.length is 0 ) if x.length?
  return ( x.size   is 0 ) if x.size?
  throw new Error "unable to determine length of a #{CND.type_of x}"

#-----------------------------------------------------------------------------------------------------------
@jr     = JSON.stringify
@assign = Object.assign

#-----------------------------------------------------------------------------------------------------------
@copy = ( P... ) ->
  return switch type = @type_of P[ 0 ]
    when 'pod'  then @assign {}, P...
    when 'list' then @assign [], P...
    else throw new Error "µ09231 unable to copy a #{type}"

#-----------------------------------------------------------------------------------------------------------
@deep_copy = ( P... ) -> ( require './universal-copy' ) P...

#-----------------------------------------------------------------------------------------------------------
@format_number = ( n, grouper = "'" ) ->
  ### A simple number formatter. ###
  n       = n.toString()
  f       = ( n ) -> return h n, /(\d+)(\d{3})/
  h       = ( n, re ) -> n = n.replace re, "$1" + grouper + "$2" while re.test n; return n
  return f n<commit_msg>add some path methods, update flatten, format_number<commit_after>


############################################################################################################
njs_path                  = require 'path'
njs_fs                    = require 'fs'
njs_util                  = require 'util'
rpr                       = njs_util.inspect
CND                       = require './main'
PATH                      = require 'path'
@flatten                  = ( x, depth = Infinity ) -> x.flat depth

#-----------------------------------------------------------------------------------------------------------
@equals = ( P... ) -> ( require './jkroso-equals' ) P...

#-----------------------------------------------------------------------------------------------------------
@is_empty = ( x ) ->
  return ( x.length is 0 ) if x.length?
  return ( x.size   is 0 ) if x.size?
  throw new Error "unable to determine length of a #{CND.type_of x}"

#-----------------------------------------------------------------------------------------------------------
@jr     = JSON.stringify
@assign = Object.assign

#-----------------------------------------------------------------------------------------------------------
@here_abspath             = ( dirname, P... ) -> PATH.resolve   dirname,        P...
@cwd_abspath              = ( P...          ) -> PATH.resolve   process.cwd(),  P...
@cwd_relpath              = ( P...          ) -> PATH.relative  process.cwd(),  P...

#-----------------------------------------------------------------------------------------------------------
@ensure_directory = ( path ) -> new Promise ( resolve, reject ) =>
  ( require 'mkdirp' ) path, ( error ) =>
    throw error if error?
    resolve()

#-----------------------------------------------------------------------------------------------------------
@copy = ( P... ) ->
  return switch type = @type_of P[ 0 ]
    when 'pod'  then @assign {}, P...
    when 'list' then @assign [], P...
    else throw new Error "µ09231 unable to copy a #{type}"

#-----------------------------------------------------------------------------------------------------------
@deep_copy = ( P... ) -> ( require './universal-copy' ) P...

#-----------------------------------------------------------------------------------------------------------
number_formatter = new Intl.NumberFormat 'en-US'
@format_number = ( x ) -> number_formatter.format x
{'fraction_non_alphanumeric': 0.4984795321637427, 'fraction_numerical': 0.0044444444444444444, 'mean_word_length': 0.7467320261437909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '4475146', 'n_tokens_mistral': 923, 'n_tokens_neox': 879, 'n_words': 252}