<commit_before>var themeServer = process.env.THEME_SERVER || 'http://themes.jsonresume.org/theme/';
var registryServer = process.env.REGISTRY_SERVER || 'http://registry.jsonresume.org';

var request = require('superagent');
var http = require('http');
var fs = require('fs');
var read = require('read');
var spinner = require("char-spinner");

function exportResume(resumeJson, fileName, program, callback) {
    var theme = program.theme;

    if (!fileName) {
        read({
            prompt: "Provide a file name: ",
            default: 'resume'
        }, function(er, fileName) {
            if (er) return console.log();
            var fileName = fileName;

            formatSelectMenu(program.format, function(format) {
                if (format === '.html') {
                    sendExportRequest(resumeJson, fileName, theme, format, function() {
                        callback(null, fileName, format);
                    });
                } else if (format === '.pdf') {
                    sendExportPDFRequest(resumeJson, fileName, theme, format, function() {
                        callback(null, fileName, format);
                    });
                }
            });
        });
    } else {
        formatSelectMenu(program.format, function(format) {
            if (format === '.html') {
                sendExportRequest(resumeJson, fileName, theme, format, function() {
                    callback(null, fileName, format);
                });
            } else if (format === '.pdf') {
                sendExportPDFRequest(resumeJson, fileName, theme, format, function() {
                    callback(null, fileName, format);
                });
            }
        });
    }
}

function sendExportRequest(resumeJson, fileName, theme, format, callback) {
    spinner();
    request
        .post(themeServer + theme)
        .send({
            resume: resumeJson
        })
        .set('Accept', 'application/json')
        .end(function(response) {
            fs.writeFileSync(process.cwd() + '/' + fileName + format, response.text);
            callback();
        });
    return;
}<commit_msg>Get file format from file name during export<commit_after>var themeServer = process.env.THEME_SERVER || 'http://themes.jsonresume.org/theme/';
var registryServer = process.env.REGISTRY_SERVER || 'http://registry.jsonresume.org';

var request = require('superagent');
var http = require('http');
var fs = require('fs');
var read = require('read');
var spinner = require("char-spinner");

function exportResume(resumeJson, fileName, program, callback) {
    var theme = program.theme;

    if (!fileName) {
        read({
            prompt: "Provide a file name: ",
            default: 'resume'
        }, function(er, fileName) {
            if (er) return console.log();
            var fileName = fileName;
            var fileFormatFound = extractFileFormat(fileName);
            var fileFormatToUse = program.format;

            if (program.format && fileFormatFound
                && program.format === fileFormatFound) {
                    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
            } else if (fileFormatFound) {
                    fileFormatToUse = fileFormatFound;
                    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
            }

            formatSelectMenu(fileFormatToUse, function(format) {
                if (format === '.html') {
                    sendExportRequest(resumeJson, fileName, theme, format, function() {
                        callback(null, fileName, format);
                    });
                } else if (format === '.pdf') {
                    sendExportPDFRequest(resumeJson, fileName, theme, format, function() {
                        callback(null, fileName, format);
                    });
                }
            });
        });
    } else {
        var fileFormatFound = extractFileFormat(fileName);
        var fileFormatToUse = program.format;

        if (program.format && fileFormatFound
            && program.format === fileFormatFound) {
               fileName = fileName.substring(0, fileName.lastIndexOf('.'));
        } else if (fileFormatFound) {
               fileFormatToUse = fileFormatFound;
               fileName = fileName.substring(0, fileName.lastIndexOf('.'));
        }

        formatSelectMenu(fileFormatToUse, function(format) {
            if (format === '.html') {
                sendExportRequest(resumeJson, fileName, theme, format, function() {
                    callback(null, fileName, format);
                });
            } else if (format === '.pdf') {
                sendExportPDFRequest(resumeJson, fileName, theme, format, function() {
                    callback(null, fileName, format);
                });
            }
        });
    }
}

function extractFileFormat(fileName) {
    var dotPos = fileName.lastIndexOf('.');
    if (dotPos === -1) {
        return null;
    }
    return fileName.substring(dotPos + 1).toLowerCase();
}

function sendExportRequest(resumeJson, fileName, theme, format, callback) {
    spinner();
    request
        .post(themeServer + theme)
        .send({
            resume: resumeJson
        })
        .set('Accept', 'application/json')
        .end(function(response) {
            fs.writeFileSync(process.cwd() + '/' + fileName + format, response.text);
            callback();
        });
    return;
}
{'fraction_non_alphanumeric': 0.12770245511176256, 'fraction_numerical': 0.0010993037742762918, 'mean_word_length': 1.8944856839872746, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5961140', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1404, 'n_words': 310}