<commit_before>import $ = require('jquery')
import bootstrap = require('bootstrap')
import Sammy = require('sammy')
import PushLocationProxy from './sammy/push_location_proxy'
import Handlebars = require('handlebars')
import SammyHandlebars = require('sammy.handlebars')
import fade from './sammy/fade'
import resolve from './resolve'

var a = $
var b = bootstrap

Handlebars.registerHelper('replace', (str: string, substr: string, newSubStr: string) => str.replace(substr, newSubStr))

var app = Sammy('#content', app => {
  app.debug = true
  app.use(SammyHandlebars, 'hb')
  app.use(fade)
  app.setLocationProxy(new PushLocationProxy(app, 'a', 'body'))

  var basicRoute = (partial: string) => (route: Sammy.EventContext, next: () => void) => route
    .partial('/views/' + partial + '.hb')
    .then(next)

  var apiRoute = (partial: string, partials: { [key: string]: string } = {}) => {
    var map: { [key: string]: string } = {}
    Object.keys(partials).forEach(key => map[key] = '/views/' + partials[key] + '.hb')
    return (route: Sammy.EventContext, next: () => void) => route
      .loadPartials(map)
      .load('/api' + route.path)
      .then(JSON.parse)
      .then(resolve)
      .partial('/views/' + partial + '.hb')
      .then(next)
  }

  app.get('/', basicRoute('index'))
  app.get('/about', basicRoute('about'))
  app.get('/packages/:package', apiRoute('package'))
  app.get('/packages/:package/:version', apiRoute('package'))
  app.get('/packages/:package/:version/assemblies/:assembly', apiRoute('assembly', { namespace: 'assembly/namespace' }))
  app.get('/packages/:package/:version/assemblies/:assembly/:framework', apiRoute('assembly'))

  app.get('/404', (route, next) => route.partial('/views/404.hb', route.params).then(next))

  var notFound = app.notFound
  app.notFound = (verb: string, path: string) => {
    if (path === '/404') {
      notFound.call(app, verb, path)
    } else {
      app.runRoute('get', '/404', { path })
    }
  }
})

app.run()
<commit_msg>Make replace global so it works on many-level namespaces<commit_after>import $ = require('jquery')
import bootstrap = require('bootstrap')
import Sammy = require('sammy')
import PushLocationProxy from './sammy/push_location_proxy'
import Handlebars = require('handlebars')
import SammyHandlebars = require('sammy.handlebars')
import fade from './sammy/fade'
import resolve from './resolve'

var a = $
var b = bootstrap

Handlebars.registerHelper('replace', (str: string, substr: string, newSubStr: string) => str.replace(new RegExp(substr, 'g'), newSubStr))

var app = Sammy('#content', app => {
  app.debug = true
  app.use(SammyHandlebars, 'hb')
  app.use(fade)
  app.setLocationProxy(new PushLocationProxy(app, 'a', 'body'))

  var basicRoute = (partial: string) => (route: Sammy.EventContext, next: () => void) => route
    .partial('/views/' + partial + '.hb')
    .then(next)

  var apiRoute = (partial: string, partials: { [key: string]: string } = {}) => {
    var map: { [key: string]: string } = {}
    Object.keys(partials).forEach(key => map[key] = '/views/' + partials[key] + '.hb')
    return (route: Sammy.EventContext, next: () => void) => route
      .loadPartials(map)
      .load('/api' + route.path)
      .then(JSON.parse)
      .then(resolve)
      .partial('/views/' + partial + '.hb')
      .then(next)
  }

  app.get('/', basicRoute('index'))
  app.get('/about', basicRoute('about'))
  app.get('/packages/:package', apiRoute('package'))
  app.get('/packages/:package/:version', apiRoute('package'))
  app.get('/packages/:package/:version/assemblies/:assembly', apiRoute('assembly', { namespace: 'assembly/namespace' }))
  app.get('/packages/:package/:version/assemblies/:assembly/:framework', apiRoute('assembly'))

  app.get('/404', (route, next) => route.partial('/views/404.hb', route.params).then(next))

  var notFound = app.notFound
  app.notFound = (verb: string, path: string) => {
    if (path === '/404') {
      notFound.call(app, verb, path)
    } else {
      app.runRoute('get', '/404', { path })
    }
  }
})

app.run()

{'fraction_non_alphanumeric': 0.19507389162561575, 'fraction_numerical': 0.005911330049261084, 'mean_word_length': 4.025990099009901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5769763', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1310, 'n_words': 284}