Gathering detailed insights and metrics for web-csv-toolbox
Gathering detailed insights and metrics for web-csv-toolbox
Gathering detailed insights and metrics for web-csv-toolbox
Gathering detailed insights and metrics for web-csv-toolbox
npm install web-csv-toolbox
Typescript
Module System
Min. Node Version
Node Version
NPM Version
75.8
Supply Chain
93.1
Quality
86.2
Maintenance
100
Vulnerability
100
License
web-csv-toolbox@0.11.0
Published on 21 Aug 2024
web-csv-toolbox@0.10.2
Published on 08 Jul 2024
web-csv-toolbox@0.10.1
Published on 14 Jun 2024
web-csv-toolbox@0.10.0
Published on 10 Jun 2024
web-csv-toolbox@0.9.0
Published on 04 Jun 2024
web-csv-toolbox@0.8.0
Published on 27 Mar 2024
TypeScript (99.45%)
Rust (0.34%)
HTML (0.21%)
Total Downloads
18,882
Last Day
96
Last Week
145
Last Month
527
Last Year
14,204
9 Stars
371 Commits
4 Forks
2 Watching
27 Branches
4 Contributors
Minified
Minified + Gzipped
Latest Version
0.11.0
Package Id
web-csv-toolbox@0.11.0
Unpacked Size
825.56 kB
Size
278.37 kB
File Count
212
NPM Version
10.8.1
Node Version
20.16.0
Publised On
21 Aug 2024
Cumulative downloads
Total Downloads
Last day
1,500%
96
Compared to previous day
Last week
-7.1%
145
Compared to previous week
Last month
12.6%
527
Compared to previous month
Last year
203.6%
14,204
Compared to previous year
20
AbortController
to manually cancel operations as needed.AbortSignal.timeout
to automatically cancel operations that exceed a specified time limit.string
s, ReadableStream
s, or Response
objects.,
and "
respectively.This package can then be installed using a package manager.
1# Install with npm 2$ npm install web-csv-toolbox 3# Or Yarn 4$ yarn add web-csv-toolbox 5# Or pnpm 6$ pnpm add web-csv-toolbox
1<script src="https://unpkg.com/web-csv-toolbox"></script> 2<script> 3const csv = `name,age 4Alice,42 5Bob,69`; 6 7(async function () { 8 for await (const record of CSV.parse(csv)) { 9 console.log(record); 10 } 11})(); 12</script>
1<script type="module"> 2import { parse } from 'https://unpkg.com/web-csv-toolbox?module'; 3 4const csv = `name,age 5Alice,42 6Bob,69`; 7 8for await (const record of parse(csv)) { 9 console.log(record); 10} 11</script>
You can install and use the package by specifying the following:
1import { parse } from "npm:web-csv-toolbox";
1import { parse } from 'web-csv-toolbox'; 2 3const csv = `name,age 4Alice,42 5Bob,69`; 6 7for await (const record of parse(csv)) { 8 console.log(record); 9} 10// Prints: 11// { name: 'Alice', age: '42' } 12// { name: 'Bob', age: '69' }
ReadableStream
s1import { parse } from 'web-csv-toolbox'; 2 3const csv = `name,age 4Alice,42 5Bob,69`; 6 7const stream = new ReadableStream({ 8 start(controller) { 9 controller.enqueue(csv); 10 controller.close(); 11 }, 12}); 13 14for await (const record of parse(stream)) { 15 console.log(record); 16} 17// Prints: 18// { name: 'Alice', age: '42' } 19// { name: 'Bob', age: '69' }
Response
objects1import { parse } from 'web-csv-toolbox'; 2 3const response = await fetch('https://example.com/data.csv'); 4 5for await (const record of parse(response)) { 6 console.log(record); 7} 8// Prints: 9// { name: 'Alice', age: '42' } 10// { name: 'Bob', age: '69' }
1import { parse } from 'web-csv-toolbox'; 2 3const csv = `name\tage 4Alice\t42 5Bob\t69`; 6 7for await (const record of parse(csv, { delimiter: '\t' })) { 8 console.log(record); 9} 10// Prints: 11// { name: 'Alice', age: '42' } 12// { name: 'Bob', age: '69' }
1import { parse } from 'web-csv-toolbox'; 2 3const csv = `Alice,42 4Bob,69`; 5 6for await (const record of parse(csv, { headers: ['name', 'age'] })) { 7 console.log(record); 8} 9// Prints: 10// { name: 'Alice', age: '42' } 11// { name: 'Bob', age: '69' }
AbortSignal
/ AbortController
SupportSupport for AbortSignal
/ AbortController
, enabling you to cancel ongoing asynchronous CSV processing tasks.
This feature is useful for scenarios where processing needs to be halted, such as when a user navigates away from the page or other conditions that require stopping the task early.
1import { parse } from 'web-csv-toolbox'; 2 3const controller = new AbortController(); 4const csv = "name,age\nAlice,30\nBob,25"; 5 6try { 7 // Parse the CSV data then pass the AbortSignal to the parse function 8 for await (const record of parse(csv, { signal: controller.signal })) { 9 console.log(record); 10 } 11} catch (error) { 12 if (error instanceof DOMException && error.name === 'AbortError') { 13 // The CSV processing was aborted by the user 14 console.log('CSV processing was aborted by the user.'); 15 } else { 16 // An error occurred during CSV processing 17 console.error('An error occurred:', error); 18 } 19} 20 21// Some abort logic, like a cancel button 22document.getElementById('cancel-button') 23 .addEventListener('click', () => { 24 controller.abort(); 25 });
1import { parse } from 'web-csv-toolbox'; 2 3// Set up a timeout of 5 seconds (5000 milliseconds) 4const signal = AbortSignal.timeout(5000); 5 6const csv = "name,age\nAlice,30\nBob,25"; 7 8try { 9 // Pass the AbortSignal to the parse function 10 const result = await parse.toArray(csv, { signal }); 11 console.log(result); 12} catch (error) { 13 if (error instanceof DOMException && error.name === 'TimeoutError') { 14 // Handle the case where the processing was aborted due to timeout 15 console.log('CSV processing was aborted due to timeout.'); 16 } else { 17 // Handle other errors 18 console.error('An error occurred during CSV processing:', error); 19 } 20}
Versions | Status |
---|---|
20.x | โ |
18.x | โ |
OS | Chrome | FireFox | Default |
---|---|---|---|
Windows | โ | โ | โ (Edge) |
macos | โ | โ | โฌ (Safari *) |
Linux | โ | โ | - |
* To Be Tested: I couldn't launch Safari in headless mode on GitHub Actions, so I couldn't verify it, but it probably works.
These APIs are designed for Simplicity and Ease of Use, providing an intuitive and straightforward experience for users.
function parse(input[, options]): AsyncIterableIterator<CSVRecord>
: ๐
function parse.toArray(input[, options]): Promise<CSVRecord[]>
: ๐
The input
paramater can be a string
, a ReadableStream
of string
s or Uint8Arrays,
or a Uint8Array object,
or a ArrayBuffer object,
or a Response object.
These APIs are optimized for Enhanced Performance and Control, catering to users who need more detailed and fine-tuned functionality.
function parseString(string[, options])
: ๐
function parseBinary(buffer[, options])
: ๐
function parseResponse(response[, options])
: ๐
Response
objects.function parseStream(stream[, options])
: ๐
function parseStringStream(stream[, options])
: ๐
function parseUint8ArrayStream(stream[, options])
: ๐
These APIs are built for Advanced Customization and Pipeline Design, ideal for developers looking for in-depth control and flexibility.
class LexerTransformer
: ๐
class RecordAssemblerTransformer
: ๐
These APIs are experimental and may change in the future.
You can use WebAssembly to parse CSV data for high performance.
"
. (Double quotation mark)
1import { loadWASM, parseStringWASM } from "web-csv-toolbox"; 2 3// load WebAssembly module 4await loadWASM(); 5 6const csv = "a,b,c\n1,2,3"; 7 8// parse CSV string 9const result = parseStringToArraySyncWASM(csv); 10console.log(result); 11// Prints: 12// [{ a: "1", b: "2", c: "3" }]
function loadWASM(): Promise<void>
: ๐
function parseStringToArraySyncWASM(string[, options]): CSVRecord[]
: ๐
Option | Description | Default | Notes |
---|---|---|---|
delimiter | Character to separate fields | , | |
quotation | Character used for quoting fields | " | |
headers | Custom headers for the parsed records | First row | If not provided, the first row is used as headers |
signal | AbortSignal to cancel processing | undefined | Allows aborting of long-running operations |
Option | Description | Default | Notes |
---|---|---|---|
charset | Character encoding for binary CSV inputs | utf-8 | See Encoding API Compatibility for the encoding formats that can be specified. |
decompression | Decompression algorithm for compressed CSV inputs | See DecompressionStream Compatibility. | |
ignoreBOM | Whether to ignore Byte Order Mark (BOM) | false | See TextDecoderOptions.ignoreBOM for more information about the BOM. |
fatal | Throw an error on invalid characters | false | See TextDecoderOptions.fatal for more information. |
The easiest way to contribute is to use the library and star repository.
Feel free to ask questions on GitHub Discussions.
Please register at GitHub Issues.
Please support kamiazya.
Even just a dollar is enough motivation to develop ๐
This software is released under the MIT License, see LICENSE.
No vulnerabilities found.
No security vulnerabilities found.