dist/carrot.js
/**
     * Converts CSV into JSON. The CSV file / string is being processed vertically, having the first line defining the properties and every following line defining a new entry.
     *
     * @method Carrot.Debug#sprite
     * @param {string} file - The CSV file to convert. Must be a string.
     * @return {object}
     */
Converts CSV into JSON. The CSV file / string is being processed vertically, having the first line defining the properties and every following line defining a new entry.
@method Carrot.Debug#sprite
@param {string} file - The CSV file to convert. Must be a string.
@return {object}
Converts CSV into JSON . The CSV file / string is being processed vertically having the first line defining the properties and every following line defining a new entry . @method Carrot . Debug#sprite @param { string } file - The CSV file to convert . Must be a string . @return { object }
csvToJson(file)
    {
        let csv = {};
        let rows = file.split(/\n|\r/);
        let properties = rows[0].replace(/['"]+/g, ''); 
        properties     = properties.replace(/\s/g,''); 
        properties     = properties.split(",");
        for (let i = 1; i < rows.length; i++)
        {
            let columns = rows[i].split(",");
            let object = columns[0];
            object = object.trim(); 
            if (object !== "")
            {
                csv[object] = {};
                for (let j = 1; j < properties.length; j++)
                {
                    let property = properties[j];
                    let value = parseInt(columns[j]);
                    if (isNaN(value))
                    {
                        value = columns[j].replace(/['"]+/g, '');
                    }
                    csv[object][property] = value;
                }
            }
        }
        return csv;
    }
csvToJson ( file ) { let csv = { } ; let rows = file . split ( / \n|\r / ) ; let properties = rows [ 0 ] . replace ( / ['"]+ / g , '' ) ; properties = properties . replace ( / \s / g , '' ) ; properties = properties . split ( "," ) ; for ( let i = 1 ; i < rows . length ; i ++ ) { let columns = rows [ i ] . split ( "," ) ; let object = columns [ 0 ] ; object = object . trim ( ) ; if ( object !== "" ) { csv [ object ] = { } ; for ( let j = 1 ; j < properties . length ; j ++ ) { let property = properties [ j ] ; let value = parseInt ( columns [ j ] ) ; if ( isNaN ( value ) ) { value = columns [ j ] . replace ( / ['"]+ / g , '' ) ; } csv [ object ] [ property ] = value ; } } } return csv ; }
Converts CSV into JSON.
Converts CSV into JSON .
// Split up at line breaks // Save properties defined in the first line of the CSV file. // Remove "s if existing. // Remove all white spaces // Get the values of the lines after the first one. // Remove spaces at begin and end. // Check for empty line (the last one mostly) // Create property in object. // If value is a string // Remove its "s // Store value