项目作者: pozil

项目描述 :
A visualizer that parses CSV data and renders it in a table in Postman or in a browser.
高级语言: JavaScript
项目地址: git://github.com/pozil/csv-visualizer.git
创建时间: 2021-09-06T17:51:24Z
项目社区:https://github.com/pozil/csv-visualizer

开源协议:Creative Commons Zero v1.0 Universal

下载


npm

Postman CSV Visualizer

A visualizer that parses CSV data and renders it in a table in Postman or in a browser.

  1. Example
  2. Using the Visualizer in Postman
  3. Reference

Example

The following code…

  1. <script src="https://unpkg.com/csv-visualizer@1.0.0/dist/csv-vizualizer.min.js"></script>
  2. <script>
  3. const CSV = '"h1","h2","h3"\n"r1c1","r1c2","r1c3"\n"r2c1","r2c2","r2c3"';
  4. CsvVisualizer.visualize(CSV);
  5. </script>

…generates a table like this:

Standalone HTML table

Complete example available in example.html.

Using the Visualizer in Postman

  1. Pick a request that returns CSV data
  2. Copy the following code in the Tests tab:

    1. const template = `<script src="https://unpkg.com/csv-visualizer@latest/dist/csv-visualizer.min.js"></script>
    2. <script>
    3. pm.getData((err, data) => {
    4. CsvVisualizer.visualize(data.csvString);
    5. });
    6. </script>`;
    7. const csvString = pm.response.text();
    8. pm.visualizer.set(template, { csvString });
  3. Run the request and open the response’s Visualize tab

Postman visualizer

Reference

  1. CsvVisualizer.visualize(
  2. csvString,
  3. (rootElement = document.body),
  4. (options = {})
  5. );

csvString - the CSV string that holds the table data

rootElement - optional, the root DOM element to witch the content is appended. If not specified, document.body is used.

options - optional, an object that contains the table and parser options:

Property Type Default Description
showHeader boolean true Whether the table should have a header that indicates the number of rows.
parserOptions Object {} CSV parser options. See Papa Parse Config.

Credits/Licenses

This project uses Papa Parse (MIT License) for CSV parsing.