web-csv-toolbox 0.13.1-next-afac98bd3a41b6e902268ac4ca6a99a8da883c81 → 0.14.0-next-fe8f8c27b5fcf2744b32ad7dca0a70ed7f47c915
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -9
- package/dist/_virtual/web_csv_toolbox_wasm_bg.wasm.js +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/getOptionsFromBlob.d.ts +10 -0
- package/dist/getOptionsFromBlob.js +18 -0
- package/dist/getOptionsFromBlob.js.map +1 -0
- package/dist/getOptionsFromRequest.d.ts +11 -0
- package/dist/getOptionsFromRequest.js +41 -0
- package/dist/getOptionsFromRequest.js.map +1 -0
- package/dist/parse.d.ts +4 -2
- package/dist/parse.js +11 -29
- package/dist/parse.js.map +1 -1
- package/dist/parseBlob.d.ts +102 -0
- package/dist/parseBlob.js +31 -0
- package/dist/parseBlob.js.map +1 -0
- package/dist/parseBlobToStream.d.ts +11 -0
- package/dist/parseBlobToStream.js +10 -0
- package/dist/parseBlobToStream.js.map +1 -0
- package/dist/parseFile.d.ts +93 -0
- package/dist/parseFile.js +20 -0
- package/dist/parseFile.js.map +1 -0
- package/dist/parseRequest.d.ts +120 -0
- package/dist/parseRequest.js +37 -0
- package/dist/parseRequest.js.map +1 -0
- package/dist/parseRequestToStream.d.ts +11 -0
- package/dist/parseRequestToStream.js +16 -0
- package/dist/parseRequestToStream.js.map +1 -0
- package/dist/parseResponse.js +1 -6
- package/dist/parseResponse.js.map +1 -1
- package/dist/web-csv-toolbox.d.ts +3 -0
- package/dist/web-csv-toolbox.js +3 -0
- package/dist/web-csv-toolbox.js.map +1 -1
- package/dist/web_csv_toolbox_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,13 +56,13 @@ A CSV Toolbox utilizing Web Standard APIs.
|
|
|
56
56
|
- ⏳ Use [`AbortSignal.timeout`](https://developer.mozilla.org/docs/Web/API/AbortSignal/timeout_static) to automatically cancel operations that exceed a specified time limit.
|
|
57
57
|
- 🛡️ **Memory Safety Protection**: Built-in limits prevent memory exhaustion attacks.
|
|
58
58
|
- 🔒 Configurable maximum buffer size (default: 10M characters) to prevent DoS attacks via unbounded input.
|
|
59
|
-
|
|
59
|
+
- 🚨 Throws `RangeError` when buffer exceeds the limit.
|
|
60
60
|
- 📊 Configurable maximum field count (default: 100,000 fields/record) to prevent excessive column attacks.
|
|
61
|
-
|
|
61
|
+
- ⚠️ Throws `RangeError` when field count exceeds the limit.
|
|
62
62
|
- 💾 Configurable maximum binary size (default: 100MB bytes) for ArrayBuffer/Uint8Array inputs.
|
|
63
|
-
|
|
63
|
+
- 🛑 Throws `RangeError` when binary size exceeds the limit.
|
|
64
64
|
- 🎨 **Flexible Source Support**
|
|
65
|
-
- 🧩 Parse CSVs directly from `string`s, `ReadableStream`s, or `
|
|
65
|
+
- 🧩 Parse CSVs directly from `string`s, `ReadableStream`s, `Response` objects, `Blob`/`File` objects, or `Request` objects.
|
|
66
66
|
- ⚙️ **Advanced Parsing Options**: Customize your experience with various delimiters and quotation marks.
|
|
67
67
|
- 🔄 Defaults to `,` and `"` respectively.
|
|
68
68
|
- 💾 **Specialized Binary CSV Parsing**: Leverage Stream-based processing for versatility and strength.
|
|
@@ -173,6 +173,47 @@ for await (const record of parse(response)) {
|
|
|
173
173
|
// { name: 'Bob', age: '69' }
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
+
### Parsing CSV files from `Blob` or `File` objects
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
import { parse } from 'web-csv-toolbox';
|
|
180
|
+
|
|
181
|
+
// From file input
|
|
182
|
+
const fileInput = document.querySelector('input[type="file"]');
|
|
183
|
+
fileInput.addEventListener('change', async (e) => {
|
|
184
|
+
const file = e.target.files[0];
|
|
185
|
+
|
|
186
|
+
for await (const record of parse(file)) {
|
|
187
|
+
console.log(record);
|
|
188
|
+
}
|
|
189
|
+
// Prints:
|
|
190
|
+
// { name: 'Alice', age: '42' }
|
|
191
|
+
// { name: 'Bob', age: '69' }
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Parsing CSV files from `Request` objects (Server-side)
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import { parse } from 'web-csv-toolbox';
|
|
199
|
+
|
|
200
|
+
// Cloudflare Workers / Service Workers
|
|
201
|
+
export default {
|
|
202
|
+
async fetch(request) {
|
|
203
|
+
if (request.method === 'POST') {
|
|
204
|
+
for await (const record of parse(request)) {
|
|
205
|
+
console.log(record);
|
|
206
|
+
}
|
|
207
|
+
// Prints:
|
|
208
|
+
// { name: 'Alice', age: '42' }
|
|
209
|
+
// { name: 'Bob', age: '69' }
|
|
210
|
+
|
|
211
|
+
return new Response('OK', { status: 200 });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
```
|
|
216
|
+
|
|
176
217
|
### Parsing CSV files with different delimiters and quotation characters
|
|
177
218
|
|
|
178
219
|
```js
|
|
@@ -316,6 +357,19 @@ try {
|
|
|
316
357
|
|
|
317
358
|
- Verify that JavaScript is executable on the Deno. [](https://github.com/kamiazya/web-csv-toolbox/actions/workflows/deno.yaml)
|
|
318
359
|
|
|
360
|
+
### Platform-Specific Usage Guide 📚
|
|
361
|
+
|
|
362
|
+
For detailed examples and best practices for your specific runtime environment, see:
|
|
363
|
+
|
|
364
|
+
**[Platform-Specific Usage Guide](./docs/how-to-guides/platform-usage/)**
|
|
365
|
+
|
|
366
|
+
This guide covers:
|
|
367
|
+
- 🌐 **Browser**: File input, drag-and-drop, Clipboard API, FormData, Fetch API
|
|
368
|
+
- 🟢 **Node.js**: Buffer, fs.ReadStream, HTTP requests, stdin/stdout
|
|
369
|
+
- 🦕 **Deno**: Deno.readFile, Deno.open, fetch API
|
|
370
|
+
- ⚡ **Edge**: Cloudflare Workers, Deno Deploy, Vercel Edge Functions
|
|
371
|
+
- 🐰 **Bun**: File API, HTTP server
|
|
372
|
+
|
|
319
373
|
## APIs 🧑💻
|
|
320
374
|
|
|
321
375
|
### High-level APIs 🚀
|
|
@@ -328,11 +382,14 @@ providing an intuitive and straightforward experience for users.
|
|
|
328
382
|
- **`function parse.toArray(input[, options]): Promise<CSVRecord[]>`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parse.toArray.html)
|
|
329
383
|
- Parses CSV input into an array of records, ideal for smaller data sets.
|
|
330
384
|
|
|
331
|
-
The `input` paramater can be
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
385
|
+
The `input` paramater can be:
|
|
386
|
+
- a `string`
|
|
387
|
+
- a [ReadableStream](https://developer.mozilla.org/docs/Web/API/ReadableStream) of `string`s or [Uint8Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)s
|
|
388
|
+
- a [Uint8Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) object
|
|
389
|
+
- an [ArrayBuffer](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) object
|
|
390
|
+
- a [Response](https://developer.mozilla.org/docs/Web/API/Response) object
|
|
391
|
+
- a [Blob](https://developer.mozilla.org/docs/Web/API/Blob) or [File](https://developer.mozilla.org/docs/Web/API/File) object
|
|
392
|
+
- a [Request](https://developer.mozilla.org/docs/Web/API/Request) object (server-side)
|
|
336
393
|
|
|
337
394
|
### Middle-level APIs 🧱
|
|
338
395
|
|
|
@@ -345,6 +402,12 @@ catering to users who need more detailed and fine-tuned functionality.
|
|
|
345
402
|
- Parse CSV Binary of ArrayBuffer or Uint8Array.
|
|
346
403
|
- **`function parseResponse(response[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseResponse-1.html)
|
|
347
404
|
- Customized parsing directly from `Response` objects.
|
|
405
|
+
- **`function parseRequest(request[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseRequest-1.html)
|
|
406
|
+
- Server-side parsing from `Request` objects (Cloudflare Workers, Service Workers, etc.).
|
|
407
|
+
- **`function parseBlob(blob[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseBlob-1.html)
|
|
408
|
+
- Parse CSV data from `Blob` or `File` objects.
|
|
409
|
+
- **`function parseFile(file[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseFile-1.html)
|
|
410
|
+
- Alias for `parseBlob`, semantically clearer for `File` objects.
|
|
348
411
|
- **`function parseStream(stream[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseStream-1.html)
|
|
349
412
|
- Stream-based parsing for larger or continuous data.
|
|
350
413
|
- **`function parseStringStream(stream[, options])`**: [📑](https://kamiazya.github.io/web-csv-toolbox/functions/parseStringStream-1.html)
|