<commit_before>(function(){
"use strict";

var categories = [], d = document, categoriesElement = d.getElementById('categories');

function load(){
  if (window.localStorage && window.JSON){
    var s = localStorage['expenses.categories'];
    if (s){
      try {
        categories = JSON.parse(s);
      } catch(e) { /* parsing failed */ }
    }
  }
}

function save(){
  if (window.localStorage && window.JSON){
    try {
      localStorage.setItem('expenses.categories', JSON.stringify(categories));
    } catch(e) { /* storage failed */ }
  }
}

function renderCategory(c){
  var item = d.createElement('LI'),
    name = d.createElement('SPAN'),
    amount = d.createElement('SPAN');
  
  name.className = 'name fill';
  name.appendChild(d.createTextNode(c.name));
  
  amount.className = 'amount';
  amount.appendChild(d.createTextNode(c.amount));
  
  item.className = 'row';
  item.appendChild(name);
  item.appendChild(amount);
  
  return item;
}

function renderCategories(){
  var list = d.createElement('UL');
  for (var i = 0, n = categories.length; i < n; i++){
    list.appendChild(renderCategory(categories[i]));
  }
  categoriesElement.replaceChild(list, categoriesElement.firstChild);
}

function update(){
  renderCategories();
  save();
}

function getIndex(e){
  var i = 0;
  while ((e = e.previousSibling) != null){
    i += 1;
  }
  return i;
}

function onAddExpense(e){
  var t = e.target;
  if (t.tagName == 'SPAN'){
    t = t.parentElement;
  }
  if (t.tagName == 'LI'){
    var i = getIndex(t), c = categories[i];
    var expense = parseFloat(prompt(c.name + ': ' + c.amount.toString() + ' + ?'), 10);
    if (!Number.isNaN(expense)){
      c.amount += expense;
      update();
    }
  }
}

function onAddCategory(){
  var name = prompt('What is the name of the category?');
  if (name){
    categories.push({ name: name, amount: 0 });
    update();
  }
}

function onClearExpenses(){
  if (confirm('Are you sure you want to clear all expenses?')){
    for (var i = 0, n = categories.length; i < n; i++){
      categories[i].amount = 0;
    }
    update();
  }
}

load();<commit_msg>Fixed parsing of expense from prompt<commit_after>(function(){
"use strict";

var categories = [], d = document, categoriesElement = d.getElementById('categories');

function load(){
  if (window.localStorage && window.JSON){
    var s = localStorage['expenses.categories'];
    if (s){
      try {
        categories = JSON.parse(s);
      } catch(e) { /* parsing failed */ }
    }
  }
}

function save(){
  if (window.localStorage && window.JSON){
    try {
      localStorage.setItem('expenses.categories', JSON.stringify(categories));
    } catch(e) { /* storage failed */ }
  }
}

function renderCategory(c){
  var item = d.createElement('LI'),
    name = d.createElement('SPAN'),
    amount = d.createElement('SPAN');
  
  name.className = 'name fill';
  name.appendChild(d.createTextNode(c.name));
  
  amount.className = 'amount';
  amount.appendChild(d.createTextNode(c.amount));
  
  item.className = 'row';
  item.appendChild(name);
  item.appendChild(amount);
  
  return item;
}

function renderCategories(){
  var list = d.createElement('UL');
  for (var i = 0, n = categories.length; i < n; i++){
    list.appendChild(renderCategory(categories[i]));
  }
  categoriesElement.replaceChild(list, categoriesElement.firstChild);
}

function update(){
  renderCategories();
  save();
}

function getIndex(e){
  var i = 0;
  while ((e = e.previousSibling) != null){
    i += 1;
  }
  return i;
}

function parseExpense(s){
	if (/\d+(?:[.,]\d+)?/.test(s)){
		return parseFloat(s.replace(',', '.'));
	}
	return NaN;
}

function onAddExpense(e){
  var t = e.target;
  if (t.tagName == 'SPAN'){
    t = t.parentElement;
  }
  if (t.tagName == 'LI'){
    var i = getIndex(t), c = categories[i];
    var expense = parseExpense(prompt(c.name + ': ' + c.amount.toString() + ' + ?'));
    if (!isNaN(expense)){
      c.amount += expense;
      update();
    }
  }
}

function onAddCategory(){
  var name = prompt('What is the name of the category?');
  if (name){
    categories.push({ name: name, amount: 0.0 });
    update();
  }
}

function onClearExpenses(){
  if (confirm('Are you sure you want to clear all expenses?')){
    for (var i = 0, n = categories.length; i < n; i++){
      categories[i].amount = 0.0;
    }
    update();
  }
}

load();
{'fraction_non_alphanumeric': 0.17606602475928473, 'fraction_numerical': 0.0036680421824850985, 'mean_word_length': 3.281648675171737, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2439097', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1445, 'n_words': 339}