<commit_before>#!/usr/bin/env node

'use strict';
var prog = require('commander');
var pkg = require('./package.json');
var XLSX = require('xlsx');
var converter;

var workbook;
function readWorkbook(wb) { return XLSX.readFile(workbook); }

module.exports = converter =  {
  toJson: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = {};
    workbook.SheetNames.forEach(function (sheetName) {
      var roa = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
      if(roa.length > 0) {
        result[sheetName] = roa;

        result[sheetName].forEach(function (obj) { // makes sure numbers are properly parsed
          for (var property in obj) {
            if (!isNaN(obj[property])) {
              obj[property] = Number(obj[property].trim());
            }
          }
        });
      }
    });

    result = JSON.stringify(result, 2, 2);

    console.log(result);
  },

  toCsv: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = [];
    workbook.SheetNames.forEach(function (sheetName) {
      var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
      if(csv.length > 0) {
        result.push('SHEET: ' + sheetName);
        result.push('');
        result.push(csv);
      }
    });
    console.log(result.join('\n'));
  },

  toFormulae: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = [];
    workbook.SheetNames.forEach(function (sheetName) {
      var formulae = XLSX.utils.get_formulae(workbook.Sheets[sheetName]);
      if(formulae.length > 0) {
        result.push('SHEET: ' + sheetName);
        result.push('');
        result.push(formulae.join('\n'));
      }<commit_msg>parses boolean types properly<commit_after>#!/usr/bin/env node

'use strict';
var prog = require('commander');
var pkg = require('./package.json');
var XLSX = require('xlsx');
var converter;

var workbook;
function readWorkbook(wb) { return XLSX.readFile(workbook); }

module.exports = converter =  {
  toJson: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = {};
    workbook.SheetNames.forEach(function (sheetName) {
      var roa = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
      if (roa.length > 0) {
        result[sheetName] = roa;

        result[sheetName].forEach(function (obj) {
          for (var property in obj) {
            if (!isNaN(obj[property])) {
              obj[property] = Number(obj[property].trim());
            }

            if (obj[property] === 'TRUE' || obj[property] === 'true') {
              obj[property] = Boolean(obj[property].trim());
            }
          }
        });
      }
    });

    result = JSON.stringify(result, 2, 2);
    console.log(result);
  },

  toCsv: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = [];
    workbook.SheetNames.forEach(function (sheetName) {
      var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
      if (csv.length > 0) {
        result.push('SHEET: ' + sheetName);
        result.push('');
        result.push(csv);
      }
    });
    console.log(result.join('\n'));
  },

  toFormulae: function (wb) {
    workbook = wb;
    workbook = readWorkbook(workbook);

    var result = [];
    workbook.SheetNames.forEach(function (sheetName) {
      var formulae = XLSX.utils.get_formulae(workbook.Sheets[sheetName]);
      if (formulae.length > 0) {
        result.push('SHEET: ' + sheetName);
        result.push('');
        result.push(formulae.join('\n'));
      }
{'fraction_non_alphanumeric': 0.1537824406405301, 'fraction_numerical': 0.0027609055770292656, 'mean_word_length': 2.6157684630738522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4635970', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1182, 'n_words': 215}