Windows and linux formatting difference?

Viewed 34

So I made a little script at work where we use Linux, I had no issues there and anything was working as it should. When I came home to my Windows PC and tried the script out there was some formatting issue with the Output file.

The Input file is just a normal .txt file where each line has a different entry, as example BP_Random1 BP_Random2 BP_Random3

If I upload a file on Linux it looks like this: {"tradeable-code": "BPC_Military_Backpack_01_02","base-purchase-price": "-1","base-sell-price": "-1","delta-price": "1.5","can-be-purchased": "false"},

However, on Windows it looks like this, so there is a line break after the 01_02

{"tradeable-code": "BPC_Military_Backpack_01_02
","base-purchase-price": "-1","base-sell-price": "-1","delta-price": "1.5","can-be-purchased": "false"},

Would be cool if someone knows how to fix this?

Here is the Script:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Schmutz</title>
</head>
<body>
    <input type="file" name="schmutz" id="schmutz">
</body>
<script>
    document.getElementById('schmutz').onchange = function(){
    var file = this.files[0];

    var reader = new FileReader();
    reader.onload = function(progressEvent){
    console.log(this.result);

    var text = "";
    var lines = this.result.split('\n');
    for(var line = 0; line < lines.length; line++){
      if(line != 0){
          text += "\n";
      }
        text += "{\"tradeable-code\": \""+lines[line].replace("#spawnitem ","")+"\",\"base-purchase-price\": \"-1\",\"base-sell-price\": \"-1\",\"delta-price\": \"-1.0\",\"can-be-purchased\": \"false\"},";
    }

    text = text.replace(/,*$/, '');
    console.log(text);
    download(text);
    };
    reader.readAsText(file);

    };

    function download(data, filename = "schmutz.json", type = "json") {
        var file = new Blob([data], {type: type});
        if (window.navigator.msSaveOrOpenBlob) // IE10+
            window.navigator.msSaveOrOpenBlob(file, filename);
        else { // Others
            var a = document.createElement("a"),
                    url = URL.createObjectURL(file);
            a.href = url;
            a.download = filename;
            document.body.appendChild(a);
            a.click();
            setTimeout(function() {
                document.body.removeChild(a);
                window.URL.revokeObjectURL(url);  
            }, 0);
        }
    }


</script>
</html>
0 Answers
Related