<commit_before>class Cartograph

  # Private

  param_regexp  = /:([\w\d]+)/g
  splat_regexp  = /\*/g

  routeToParamRegExp = ( route ) ->
    param_replace = "([^\/]+)"
    splat_replace = ".*"
    routeToRegexp route, param_replace, splat_replace

  routeToSplatRegExp = ( route ) ->
    param_replace = "[^\/]+"
    splat_replace = "(.*)"
    routeToRegexp route, param_replace, splat_replace

  routeToRegexp = ( route, param_replace, splat_replace ) ->
    escape_regexp = /[\-{}\[\]+?.,\\\^$|#\s]/g
    route =
      route
        .replace( escape_regexp, "\\$&" )
        .replace( param_regexp, param_replace )
        .replace( splat_regexp, splat_replace )
    new RegExp "^#{ route }$", "i"

  extractParamNames = ( route ) ->
    name_regexp = /[:|\*]([\w\d]+)/g
    names = name[1] while name = name_regexp.exec route

  parseQueryParams = ( querystr ) ->
    params = {}
    if querystr?
      re = /[\?&]([^=&]+)=?([^&$]+)?/g
      params[ match[1] ] = match[2] while match = re.exec querystr
    params

  peek = ( array, idx = 1 ) ->
    array[ array.length - idx ]

  # Public

  constructor: ( fn ) ->
    @draw fn if typeof fn is "function"

  draw: ( fn ) ->
    fn.call @

  map: ( route, fn ) ->
    @mappings ?= []

    unless typeof route is "string"
      return throw new Error("route must be a string")
    unless typeof fn is "function"
      return throw new Error("callback must be a function")

    @_prefixes ?= []
    prefixed_route = ( peek(@_prefixes) || "" ) + route

    @mappings.push
      route: prefixed_route
      callback: fn

  match: ( path, mixin ) ->
    for mapping in @mappings
      if match = @scan path, mapping.route
        if mixin?
          params = mixin.params
          delete mixin.params
          match[ key ] = val for key, val of mixin
          if params? and not match.params?
            match.params = params
          else
            match.params[ key ] = val for key, val of params
        mapping.callback match
        break

  matchRequest: ( req = window.location ) ->
    mixin = {}
    mixin.params = parseQueryParams req.search if req.search?
    mixin[ key ] = val for key, val of req
    @match req.pathname, mixin

  scan: ( path, route, mapping = {} ) ->
    param_re = mapping.param_regexp || routeToParamRegExp route
    mapping.param_regexp = param_re
    return false unless param_re.test path
    splat_re = mapping.splat_regexp || routeToSplatRegExp route
    mapping.splat_regexp = splat_re
    param_data = param_re.exec path
    splat_data = splat_re.exec path
    param_names = mapping.param_names || extractParamNames route
    mapping.param_names = param_names
    params = {}
    params[ name ] = param_data[ i + 1 ] for name, i in param_names
    params.splats = splat_data[1..]
    match =
      params: params

  namespace: ( ns, fn ) ->
    @_prefixes ?= []
    @_prefixes.push ( peek(@_prefixes) || "" ) + ns
    fn.call @
    @_prefixes.pop

# Export as:
# CommonJS module
if exports?
  if module? and module.exports?
    exports = module.exports = Cartograph
  exports.Cartograph = Cartograph
# AMD module
else if typeof define is "function" and define.amd
  define ->
    Cartograph
# Browser global
else
  @Cartograph = Cartograph
<commit_msg>no need to return here...<commit_after>class Cartograph

  # Private

  param_regexp  = /:([\w\d]+)/g
  splat_regexp  = /\*/g

  routeToParamRegExp = ( route ) ->
    param_replace = "([^\/]+)"
    splat_replace = ".*"
    routeToRegexp route, param_replace, splat_replace

  routeToSplatRegExp = ( route ) ->
    param_replace = "[^\/]+"
    splat_replace = "(.*)"
    routeToRegexp route, param_replace, splat_replace

  routeToRegexp = ( route, param_replace, splat_replace ) ->
    escape_regexp = /[\-{}\[\]+?.,\\\^$|#\s]/g
    route =
      route
        .replace( escape_regexp, "\\$&" )
        .replace( param_regexp, param_replace )
        .replace( splat_regexp, splat_replace )
    new RegExp "^#{ route }$", "i"

  extractParamNames = ( route ) ->
    name_regexp = /[:|\*]([\w\d]+)/g
    names = name[1] while name = name_regexp.exec route

  parseQueryParams = ( querystr ) ->
    params = {}
    if querystr?
      re = /[\?&]([^=&]+)=?([^&$]+)?/g
      params[ match[1] ] = match[2] while match = re.exec querystr
    params

  peek = ( array, idx = 1 ) ->
    array[ array.length - idx ]

  # Public

  constructor: ( fn ) ->
    @draw fn if typeof fn is "function"

  draw: ( fn ) ->
    fn.call @

  map: ( route, fn ) ->
    @mappings ?= []

    unless typeof route is "string"
      throw new Error("route must be a string")
    unless typeof fn is "function"
      throw new Error("callback must be a function")

    @_prefixes ?= []
    prefixed_route = ( peek(@_prefixes) || "" ) + route

    @mappings.push
      route: prefixed_route
      callback: fn

  match: ( path, mixin ) ->
    for mapping in @mappings
      if match = @scan path, mapping.route
        if mixin?
          params = mixin.params
          delete mixin.params
          match[ key ] = val for key, val of mixin
          if params? and not match.params?
            match.params = params
          else
            match.params[ key ] = val for key, val of params
        mapping.callback match
        break

  matchRequest: ( req = window.location ) ->
    mixin = {}
    mixin.params = parseQueryParams req.search if req.search?
    mixin[ key ] = val for key, val of req
    @match req.pathname, mixin

  scan: ( path, route, mapping = {} ) ->
    param_re = mapping.param_regexp || routeToParamRegExp route
    mapping.param_regexp = param_re
    return false unless param_re.test path
    splat_re = mapping.splat_regexp || routeToSplatRegExp route
    mapping.splat_regexp = splat_re
    param_data = param_re.exec path
    splat_data = splat_re.exec path
    param_names = mapping.param_names || extractParamNames route
    mapping.param_names = param_names
    params = {}
    params[ name ] = param_data[ i + 1 ] for name, i in param_names
    params.splats = splat_data[1..]
    match =
      params: params

  namespace: ( ns, fn ) ->
    @_prefixes ?= []
    @_prefixes.push ( peek(@_prefixes) || "" ) + ns
    fn.call @
    @_prefixes.pop

# Export as:
# CommonJS module
if exports?
  if module? and module.exports?
    exports = module.exports = Cartograph
  exports.Cartograph = Cartograph
# AMD module
else if typeof define is "function" and define.amd
  define ->
    Cartograph
# Browser global
else
  @Cartograph = Cartograph

{'fraction_non_alphanumeric': 0.12942443828870423, 'fraction_numerical': 0.0018467220683287165, 'mean_word_length': 2.456914893617021, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '5792499', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2109, 'n_words': 566}