<commit_before>/**
 * Created by <NAME>.
 * Date: 27.02.14
 * Time: 14:23
 */

var fs = require('fs');
var xml2js = require('xml2js');
var SVGO = require('svgo');
var svgo = new SVGO(/*{ custom config object }*/);
var builder = new xml2js.Builder();
var parseString = xml2js.parseString;
var inspect = require('eyes').inspector({maxLength: false});

var INPUT_DIR = 'svg/';
var OUTPUT_DIR = 'sprite/';
var OUTPUT_SPRITE_FILENAME = 'sprite.svg';
var SVG_EXTENSION = '.svg';

// initial position of each icon in the sprite
var x = 0, y = 0;

// the resulting sprite object
var sprite = {
    svg: {
        svg: [],
        $: { xmlns: 'http://www.w3.org/2000/svg' }
    }
};

/*
* Get file extension from string in format ".ext"
* */
function getExtension(filename) {
    var i = filename.lastIndexOf('.');
    return (i < 0) ? '' : filename.substr(i);
}

// get list of files in a given directory
fs.readdir(INPUT_DIR , function(err, files){
    var filesLeft = files.length;

    files.forEach(function(filename) {

        // check if file has proper extension
        if (getExtension(filename).toLowerCase() == SVG_EXTENSION) {
            fs.readFile(INPUT_DIR + filename, 'utf8', function (err, fileContent) {
                if (err) {
                    return console.log(err);
                }

                filesLeft--;

                parseString(fileContent, function (err, parsedFileContent) {
                    var iconHeight = parseInt(parsedFileContent.svg.$.height);

                    // add icon under the previous
                    parsedFileContent.svg.$.y = y;
                    y += iconHeight;

                    // add current icon object to resulting sprite object
                    sprite.svg.svg.push(parsedFileContent);

                    // when all files have been processed<commit_msg>svg sprite<commit_after>/**
 * Created by <NAME>.
 * Date: 27.02.14
 * Time: 14:23
 */

var fs = require('fs');
var xml2js = require('xml2js');
var SVGO = require('svgo');
var svgo = new SVGO(/*{ custom config object }*/);
var builder = new xml2js.Builder();
var parseString = xml2js.parseString;
var inspect = require('eyes').inspector({maxLength: false});

var INPUT_DIR = 'svg/';
var OUTPUT_DIR = 'sprite/';
var OUTPUT_SPRITE_FILENAME = 'sprite.svg';
var SVG_EXTENSION = '.svg';

// initial position of each icon in the sprite
var x = 0, y = 0, width = 0, height = 0;

// the resulting sprite object
var sprite = {
    svg: {
        svg: [],
        $: { xmlns: 'http://www.w3.org/2000/svg' }
    }
};

/*
* Get file extension from string in format ".ext"
* */
function getExtension(filename) {
    var i = filename.lastIndexOf('.');
    return (i < 0) ? '' : filename.substr(i);
}

// get list of files in a given directory
fs.readdir(INPUT_DIR , function(err, files){
    var filesLeft = files.length;

    files.forEach(function(filename) {

        // check if file has proper extension
        if (getExtension(filename).toLowerCase() == SVG_EXTENSION) {
            fs.readFile(INPUT_DIR + filename, 'utf8', function (err, fileContent) {
                if (err) {
                    return console.log(err);
                }

                filesLeft--;

                parseString(fileContent, function (err, parsedFileContent) {
                    var iconHeight = parseInt(parsedFileContent.svg.$.height);
                    var iconWidth = parseInt(parsedFileContent.svg.$.width);

                    // increase resulting sprite height
                    height += iconHeight;
                    sprite.svg.$.height = height;

                    // set sprite width to widest icon's width
                    if (width < iconWidth) {
                        width = iconWidth;
                        sprite.svg.$.width = width;
                    }

                    // add icon under the previous
                    parsedFileContent.svg.$.y = y;
                    y += iconHeight;

                    // sprite is vertical
                    parsedFileContent.svg.$.x = 0;

                    // add current icon object to resulting sprite object
                    sprite.svg.svg.push(parsedFileContent);

                    // when all files have been processed
{'fraction_non_alphanumeric': 0.12329090051862329, 'fraction_numerical': 0.01155115511551155, 'mean_word_length': 1.9241902136457616, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '7078452', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1182, 'n_words': 340}