web-csv-toolbox - v0.14.0
    Preparing search index...

    Function parseFile

    • Parse CSV from a File to records.

      Type Parameters

      • Header extends readonly string[]

      Parameters

      Returns AsyncIterableIterator<CSVObjectRecord<Header>>

      Async iterable iterator of records.

      If you want array of records, use parseFile.toArray function.

      This function can parse CSV data from File objects (from file inputs or drag-and-drop). If the File has a type with charset parameter, it will be used for decoding.

      Unlike parseBlob, this function automatically sets the file name as the error source for better error reporting (unless explicitly overridden via options).

      import { parseFile } from 'web-csv-toolbox';

      const input = document.querySelector('input[type="file"]');
      input.addEventListener('change', async (event) => {
      const file = event.target.files[0];
      for await (const record of parseFile(file)) {
      console.log(record);
      }
      });
      import { parseFile } from 'web-csv-toolbox';

      dropZone.addEventListener('drop', async (event) => {
      event.preventDefault();
      const file = event.dataTransfer.files[0];
      for await (const record of parseFile(file)) {
      console.log(record);
      }
      });