2014-09-12 17:50:01 +02:00
|
|
|
|
2014-04-29 18:01:30 +02:00
|
|
|
<script type="text/x-red" data-template-name="csv">
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-temp"><i class="fa fa-list"></i> <span data-i18n="csv.label.columns"></span></label>
|
2015-05-28 00:07:31 +02:00
|
|
|
<input type="text" id="node-input-temp" data-i18n="[placeholder]csv.placeholder.columns">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-select-sep"><i class="fa fa-text-width"></i> <span data-i18n="csv.label.separator"></span></label>
|
2017-05-23 10:35:37 +02:00
|
|
|
<select style="width:150px" id="node-input-select-sep">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="," data-i18n="csv.separator.comma"></option>
|
|
|
|
<option value="\t" data-i18n="csv.separator.tab"></option>
|
|
|
|
<option value=" " data-i18n="csv.separator.space"></option>
|
|
|
|
<option value=";" data-i18n="csv.separator.semicolon"></option>
|
|
|
|
<option value=":" data-i18n="csv.separator.colon"></option>
|
|
|
|
<option value="#" data-i18n="csv.separator.hashtag"></option>
|
|
|
|
<option value="" data-i18n="csv.separator.other"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
2017-05-23 10:35:37 +02:00
|
|
|
<input style="width:40px;" type="text" id="node-input-sep" pattern=".">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
2014-09-12 17:50:01 +02:00
|
|
|
|
2014-04-29 18:01:30 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2014-04-29 18:01:30 +02:00
|
|
|
</div>
|
2014-09-12 17:50:01 +02:00
|
|
|
<hr align="middle"/>
|
|
|
|
<div class="form-row">
|
2018-01-11 23:02:58 +01:00
|
|
|
<label style="width:100%; border-bottom:1px solid #eee;"><span data-i18n="csv.label.c2o"></span></label>
|
2014-09-12 17:50:01 +02:00
|
|
|
</div>
|
2018-01-11 23:02:58 +01:00
|
|
|
<div class="form-row" style="padding-left:20px;">
|
2017-05-23 15:18:09 +02:00
|
|
|
<label><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.input"></span></label>
|
2018-01-11 23:02:58 +01:00
|
|
|
<span data-i18n="csv.label.skip-s"></span> <input type="text" id="node-input-skip" style="width:30px; height:25px;"/> <span data-i18n="csv.label.skip-e"></span><br/>
|
|
|
|
<label> </label>
|
|
|
|
<input style="width:20px; vertical-align:baseline; margin-right:5px;" type="checkbox" id="node-input-hdrin"><label style="width:auto; margin-top:7px;" for="node-input-hdrin"><span data-i18n="csv.label.firstrow"></span>
|
2017-05-23 15:18:09 +02:00
|
|
|
</div>
|
2018-01-11 23:02:58 +01:00
|
|
|
<div class="form-row" style="padding-left:20px;">
|
2017-05-23 15:18:09 +02:00
|
|
|
<label><i class="fa fa-sign-out"></i> <span data-i18n="csv.label.output"></span></label>
|
2018-01-11 23:02:58 +01:00
|
|
|
<select type="text" id="node-input-multi" style="width:250px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="one" data-i18n="csv.output.row"></option>
|
|
|
|
<option value="mult" data-i18n="csv.output.array"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2018-01-11 23:02:58 +01:00
|
|
|
<div class="form-row" style="margin-top:20px">
|
|
|
|
<label style="width:100%; border-bottom:1px solid #eee;"><span data-i18n="csv.label.o2c"></span></label>
|
2014-09-12 17:50:01 +02:00
|
|
|
</div>
|
2018-01-11 23:02:58 +01:00
|
|
|
<div class="form-row" style="padding-left:20px;">
|
2017-05-23 15:18:09 +02:00
|
|
|
<label><i class="fa fa-sign-in"></i> <span data-i18n="csv.label.output"></span></label>
|
2018-01-11 23:02:58 +01:00
|
|
|
<input style="width:20px; vertical-align:top; margin-right:5px;" type="checkbox" id="node-input-hdrout"><label style="width:auto;" for="node-input-hdrout"><span data-i18n="csv.label.includerow"></span></span>
|
2017-05-23 15:18:09 +02:00
|
|
|
</div>
|
2018-01-11 23:02:58 +01:00
|
|
|
<div class="form-row" style="padding-left:20px;">
|
2017-05-23 15:18:09 +02:00
|
|
|
<label></label>
|
2018-01-11 23:02:58 +01:00
|
|
|
<label style="width:auto; margin-right:10px;" for="node-input-ret"><span data-i18n="csv.label.newline"></span></label>
|
2017-05-23 15:18:09 +02:00
|
|
|
<select style="width:150px;" id="node-input-ret">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value='\n' data-i18n="csv.newline.linux"></option>
|
|
|
|
<option value='\r' data-i18n="csv.newline.mac"></option>
|
|
|
|
<option value='\r\n' data-i18n="csv.newline.windows"></option>
|
2014-09-12 17:50:01 +02:00
|
|
|
</select>
|
|
|
|
</div>
|
2014-04-29 18:01:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="csv">
|
2017-05-23 15:18:09 +02:00
|
|
|
<p>Converts between a CSV formatted string and its JavaScript object representation, in either direction.</p>
|
2017-04-25 22:47:58 +02:00
|
|
|
<h3>Inputs</h3>
|
2017-05-23 15:18:09 +02:00
|
|
|
<dl class="message-properties">
|
|
|
|
<dt>payload<span class="property-type">object | array | string</span></dt>
|
|
|
|
<dd>A JavaScript object, array or CSV string.</dd>
|
|
|
|
</dl>
|
|
|
|
<h3>Outputs</h3>
|
|
|
|
<dl class="message-properties">
|
|
|
|
<dt>payload<span class="property-type">object | array | string</span></dt>
|
|
|
|
<dd>
|
|
|
|
<ul>
|
|
|
|
<li>If the input is a string it tries to parse it as CSV and creates a JavaScript object of key/value pairs for each line.
|
|
|
|
The node will then either send a message for each line, or a single message containing an array of objects.</li>
|
|
|
|
<li>If the input is a JavaScript object it tries to build a CSV string.</li>
|
|
|
|
<li>If the input is an array of simple values, it builds a single line CSV string.</li>
|
|
|
|
<li>If the input is an array of arrays, or an array of objects, a multiple-line CSV string is created.</li>
|
|
|
|
</ul>
|
|
|
|
</dd>
|
|
|
|
</dl>
|
2017-04-25 22:47:58 +02:00
|
|
|
<h3>Details</h3>
|
2017-05-23 15:18:09 +02:00
|
|
|
<p>The column template can contain an ordered list of column names. When converting CSV to an object, the column names
|
|
|
|
will be used as the property names. Alternatively, the column names can be taken from the first row of the CSV.</p>
|
|
|
|
<p>When converting to CSV, the column template is used to identify which properties to extract from the object and in what order.</p>
|
|
|
|
<p>If the input is an array then the columns template is only used to optionally generate a row of column titles.</p>
|
2018-01-30 17:09:45 +01:00
|
|
|
<p>The node can accept a multi-part input as long as the <code>parts</code> property is set correctly.</p>
|
|
|
|
<p>If outputting multiple messages they will aslo have their <code>parts</code> property set.</p>
|
2017-05-23 15:18:09 +02:00
|
|
|
<p><b>Note:</b> the column template must be comma separated - even if a different separator is chosen for the data.</p>
|
2014-04-29 18:01:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('csv',{
|
|
|
|
category: 'function',
|
|
|
|
color:"#DEBD5C",
|
|
|
|
defaults: {
|
|
|
|
name: {value:""},
|
2014-09-12 17:50:01 +02:00
|
|
|
sep: {value:',',required:true,validate:RED.validators.regex(/^.{1,2}$/)},
|
2014-04-29 18:01:30 +02:00
|
|
|
//quo: {value:'"',required:true},
|
2014-09-12 17:50:01 +02:00
|
|
|
hdrin: {value:""},
|
|
|
|
hdrout: {value:""},
|
|
|
|
multi: {value:"one",required:true},
|
|
|
|
ret: {value:'\\n'},
|
2018-01-11 23:02:58 +01:00
|
|
|
temp: {value:""},
|
|
|
|
skip: {value:"0"}
|
2014-04-29 18:01:30 +02:00
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:1,
|
2016-06-12 23:37:38 +02:00
|
|
|
icon: "parser-csv.png",
|
2014-04-29 18:01:30 +02:00
|
|
|
label: function() {
|
|
|
|
return this.name||"csv";
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2014-09-12 17:50:01 +02:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
2018-01-11 23:02:58 +01:00
|
|
|
console.log(this.skip,$("#node-input-skip").val());
|
|
|
|
if (this.skip === undefined) { this.skip = 0; $("#node-input-skip").val("0");}
|
|
|
|
$("#node-input-skip").spinner({ min:0 });
|
2015-01-09 21:32:05 +01:00
|
|
|
if (this.sep == "," || this.sep == "\\t" || this.sep == ";" || this.sep == ":" || this.sep == " " || this.sep == "#") {
|
2014-09-12 17:50:01 +02:00
|
|
|
$("#node-input-select-sep").val(this.sep);
|
|
|
|
$("#node-input-sep").hide();
|
|
|
|
} else {
|
|
|
|
$("#node-input-select-sep").val("");
|
|
|
|
$("#node-input-sep").val(this.sep);
|
|
|
|
$("#node-input-sep").show();
|
|
|
|
}
|
|
|
|
$("#node-input-select-sep").change(function() {
|
2016-07-04 12:21:58 +02:00
|
|
|
var v = $("#node-input-select-sep").val();
|
2014-09-12 17:50:01 +02:00
|
|
|
$("#node-input-sep").val(v);
|
|
|
|
if (v == "") {
|
|
|
|
$("#node-input-sep").val("");
|
|
|
|
$("#node-input-sep").show().focus();
|
|
|
|
} else {
|
|
|
|
$("#node-input-sep").hide();
|
|
|
|
}
|
|
|
|
});
|
2014-04-29 18:01:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|