UNPKG

node-red-contrib-fast-csv

Version:
224 lines (213 loc) 11.4 kB
<!-- Copyright (c) 2017 Kim McKinley --> <!-- License: MIT --> <!-- Node-RED fastcsv html file --> <script type="text/x-red" data-template-name="fastcsv"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="fastcsv"> </div> <div class="form-row"> <ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-fastcsv-tabs"></ul> </div> <div id="node-fastcsv-tabs-content"> <div id="node-fastcsv-tabs-headers" style="display:none"> <div class="form-row"> <input id="node-input-headers" type="checkbox" checked style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-headers" style="width: auto"> Add (format) or expect (parse) the first line as the header</label> </div> <div class="form-row"> <input id="node-input-discardUnmappedColumns" type="checkbox" checked style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-discardUnmappedColumns" style="width: auto"> Discard columns that do not map to a header</label> </div> <div class="form-row"> <hr> Alternately you can specify a comma separated list of column names<br> <label for="node-input-headerstr" style="width: auto"><i class="fa fa-tag"></i> Header</label> <input type="text" id="node-input-headerstr" value="," placeholder="Comma delimited list of column names"> <br>(must match the order of each column in the CSV, otherwise the data columns will not match) <br> ex: <code>firstName, lastName, address</code>. Skip a column <code>firstName, , address</code>. <hr> </div> </div> <div id="node-fastcsv-tabs-delimiters" style="display:none"> <div class="form-row"> <label for="node-input-delimiter" style="width: auto"><i class="fa fa-tag"></i></label> <input type="text" id="node-input-delimiter" value="," style="width: 40px"> Use an alternate delimiter such as ; or \t<br>All delimiters must be a single character </div> <div class="form-row"> <label for="node-input-quote" style="width: auto"><i class="fa fa-tag"></i></label> <input type="text" id="node-input-quote" value='"' style="width: 40px"> Character to use to escape values that contain a delimiter<br> <!-- If <i>blank</i> then all quoting will be ignored --> </div> <div class="form-row"> <label for="node-input-escape" style="width: auto"><i class="fa fa-tag"></i></label> <input type="text" id="node-input-escape" value='"' style="width: 40px"> Character when escaping a value that is quoted and contains a quote character<br> ie: 'First,"Name"' =&gt; '"First,""name"""' </div> </div> <div id="node-fastcsv-tabs-empty" style="display:none"> <div class="form-row"> <input id="node-input-ignoreEmpty" type="checkbox" checked style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-ignoreEmpty" style="width: auto"> Ignore empty rows</label> </div> <div class="form-row"> <input id="node-input-strictColumnHandling" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-strictColumnHandling" style="width: auto"> Consider empty rows/objects with too few fields as errors</label> </div> </div> <div id="node-fastcsv-tabs-parser" style="display:none"> <div class="form-row"> Ignore lines that begin with the specified character (e.g. #)<br> <label for="node-input-comment" style="width: auto"><i class="fa fa-tag"></i> Comments</label> <input type="text" id="node-input-comment" value="#" placeholder="#" style="width: 40px"> </div> <div class="form-row"> <input id="node-input-ltrim" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-ltrim" style="width: auto"> Trim left whitespace from all values parsed</label> </div> <div class="form-row"> <input id="node-input-rtrim" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-rtrim" style="width: auto"> Trim right whitespace from all values parsed</label> </div> </div> <div id="node-fastcsv-tabs-formatter" style="display:none"> <div class="form-row"> Specify an alternate row delimiter (i.e \r\n)<br> <label for="node-input-rowDelimiter" style="width: auto"><i class="fa fa-tag"></i> Row Delimiter</label> <input type="text" id="node-input-rowDelimiter" value="&#92;n" placeholder="&#92;n" style="width: 40px"> </div> <div class="form-row"> <input id="node-input-includeEndRowDelimiter" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-includeEndRowDelimiter" style="width: auto"> Include a row delimiter at the end of the csv</label> </div> <div class="form-row"> <input id="node-input-quoteHeaders" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-quoteHeaders" style="width: auto"> All headers will be quoted</label> </div> <div class="form-row"> <input id="node-input-quoteColumns" type="checkbox" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-input-quoteColumns" style="width: auto"> Columns and headers will be quoted</label> </div> </div> </div> </script> <script type="text/x-red" data-help-name="fastcsv"> <p>Fastcsv is a plug-in replacement for the default node-red <strong><i>csv</i></strong> node but with additional configuration settings which handle common CSV format variations.</p> <h3>Details</h3> <p>When <code>msg.payload</code> is a JavaScript Object, <i>fastcsv</i> will <strong>format</strong> it into a CSV string.<br> When <code>msg.payload</code> is a string, <i>fastcsv</i> will <strong>parse</strong> it into a JavaScript Object.</p> <p>Most of the options in the node configuration apply to both parsing and formatting.</p> <h3>Inputs</h3> <ol class="node-ports"> <li>Standard input <dl class="message-properties"> <dt>msg.payload <span class="property-type">string</span> </dt> <dd> CSV string to parse into a JS Object. </dd> <dt>msg.payload <span class="property-type">JS Object</span> </dt> <dd> JS Object to format into CSV string.</dd> </dl> </li> </ol> <h3>Outputs</h3> <ol class="node-ports"> <li>Standard output <dl class="message-properties"> <dt>msg.payload <span class="property-type">string</span></dt> <dd>the resulting JS Object of the payload CSV string.</dd> <dt>msg.payload <span class="property-type">JS Object</span></dt> <dd>the resulting CSV string of the payload JS Object.</dd> </dl> </li> <li>Standard error <dl class="message-properties"> <dt>msg.payload <span class="property-type">string/JS Object</span></dt> <dd>errors are displayed under the node as a status message.</dd> <dd>depending on the severity of the error, the processing will skip the row in error and continue parsing/formating.<br> A critical error results in the payload being sent to the next node unmodified.</dd> </dl> </li> </ol> <h3>References</h3> <ul> <li><a href="https://github.com/PotOfCoffee2Go/node-red-contrib-fast-csv">github PotOfCoffee2Go fast-csv node</a> - Node-red fastcsv node</li> <li><a href="https://github.com/C2FO/fast-csv">github C2FO fast-csv</a> - full description of fast CSV parser/formatter</li> <li><a href="https://pixabay.com/en/users/raphaelsilva-4702998/">pixabay raphaelsilva</a> - the fastcsv node icon</li> </ul> </script> <script type="text/javascript">/* global $ RED */ RED.nodes.registerType('fastcsv',{ category: 'function', // the palette category color: '#8BBDD9', defaults: { name: {value:'fastcsv'}, headers: {value: true}, headerstr: {value: ''}, ignoreEmpty: {value: true}, discardUnmappedColumns: {value: true}, strictColumnHandling: {value: false}, delimiter: {value: ','}, quote: {value: '"'}, escape: {value: '"'}, comment: {value: '#'}, ltrim: {value: false}, rtrim: {value: false}, rowDelimiter: {value: '\\n'}, includeEndRowDelimiter: {value: false}, quoteHeaders: {value: false}, quoteColumns: {value: false}, }, inputs:1, // set the number of inputs - only 0 or 1 outputs:1, // set the number of outputs - 0 to n // set the icon (held in icons dir below where you save the node) icon: 'fastcsv.png', // saved in icons/myicon.png label: function() { // sets the default label contents return this.name || 'fastcsv'; }, labelStyle: function() { // sets the class to apply to the label return this.name ? 'node_label_italic' : ''; }, oneditprepare: function() { var tabs = RED.tabs.create({ id: 'node-fastcsv-tabs', onchange: function(tab) { $("#node-fastcsv-tabs-content").children().hide(); $("#" + tab.id).show(); } }); tabs.addTab({ id: 'node-fastcsv-tabs-headers', label: 'Header' }); tabs.addTab({ id: 'node-fastcsv-tabs-delimiters', label: 'Delimiters' }); tabs.addTab({ id: 'node-fastcsv-tabs-empty', label: 'Empty' }); tabs.addTab({ id: 'node-fastcsv-tabs-parser', label: 'Parse' }); tabs.addTab({ id: 'node-fastcsv-tabs-formatter', label: 'Format' }); setTimeout(function() { tabs.resize(); },0); } }); </script>