JSFiddle - React, Tailwind, and code Playground

by individual11

HTML

Name: <input type="text" id="name" /><br />
<textarea id="input"></textarea>
<input type="button" value="Convert" />
<textarea id="output"></textarea>

CSS

body{
    background-color:#ddd;
    font-family:"Helvetica", Arial, sans;
    font-size: 12px;
}

textarea{
 width:500px;
  height:200px;  
}

JavaScript

$('input[type="button"]').click(function(e){
    if(!$('#name').val().length){
        alert("You forgot to fill in the name");
    }else{
        var ranges = [];
         var copy = $('#input').val();
        var copy_array = copy.split('\n');
        $.each(copy_array, function(i, el){
            var el_array = el.split(" - ");
            ranges.push({min:jQuery.trim(el_array[0]), max: jQuery.trim(el_array[1])});
        });
        //console.log(ranges);
        $('#output').val($('#name').val() + "=" + JSON.stringify({name:$('#name').val(), ranges:ranges}) + ";");
    }
});