<commit_before>var excel = require('xlsx');
var fs = require('fs');
var path = require('path');


function writeObjSync(filepath, obj) {
    createDir(path.dirname(filepath));
    fs.writeFileSync(filepath, JSON.stringify(obj, null, 4));
}

function createDir(dir, callback) {
    dir = path.resolve(dir);
    var originDir = dir;

    try {

        if (fs.existsSync(dir)) return;

        while (!fs.existsSync(path.join(dir + '/..'))) { 
            dir += '/..';
        }

        while (originDir.length <= dir.length) { 
            fs.mkdirSync(path.resolve(dir), '0777');
            dir = dir.substring(0, dir.length - 3);
        }
        if (callback) callback();
    } catch (e) {
        console.log(e);
    }
}

function parse(file, dest, key, langArr) {
    var wb = excel.readFileSync(file, {
        cellFormula: false
    });

    var sheet_name_list = wb.SheetNames;
    sheet_name_list.forEach(function(y) { /* 遍历sheets */
        var ws = excel.utils.sheet_to_json(wb.Sheets[y]);
        //遍历多国语内容
        var langObj = {};
        for (var row = 0, rlen = ws.length; row < rlen; row++) { //遍历表格行
            if (!ws[row][key]) {
                throw new Error('not find key `' + key + '` in excel!');
            }
            if (!langArr) {//如果没有指定需要输出的语言,则<commit_msg>Update excel.js<commit_after>var excel = require('xlsx');
var fs = require('fs');
var path = require('path');


function writeObjSync(filepath, obj) {
    createDir(path.dirname(filepath));
    fs.writeFileSync(filepath, JSON.stringify(obj, null, 4));
}

function createDir(dir, callback) {
    dir = path.resolve(dir);
    var originDir = dir;

    try {

        if (fs.existsSync(dir)) return;

        while (!fs.existsSync(path.join(dir, '/..'))) { 
            dir += '/..';
        }

        while (originDir.length <= dir.length) { 
            fs.mkdirSync(path.resolve(dir), '0777');
            dir = dir.substring(0, dir.length - 3);
        }
        if (callback) callback();
    } catch (e) {
        console.log(e);
    }
}

function parse(file, dest, key, langArr) {
    var wb = excel.readFileSync(file, {
        cellFormula: false
    });

    var sheet_name_list = wb.SheetNames;
    sheet_name_list.forEach(function(y) { /* 遍历sheets */
        var ws = excel.utils.sheet_to_json(wb.Sheets[y]);
        //遍历多国语内容
        var langObj = {};
        for (var row = 0, rlen = ws.length; row < rlen; row++) { //遍历表格行
            if (!ws[row][key]) {
                throw new Error('not find key `' + key + '` in excel!');
            }
            if (!langArr) {//如果没有指定需要输出的语言,则
{'fraction_non_alphanumeric': 0.1622350674373796, 'fraction_numerical': 0.006165703275529865, 'mean_word_length': 2.1581508515815084, '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': '6559596', 'n_tokens_mistral': 927, 'n_tokens_neox': 899, 'n_words': 182}