Skip to content

Commit 92c7e67

Browse files
CopilotTechQuery
andauthored
[add] Streaming CSV Parser based on Async Generator (#32)
Co-authored-by: TechQuery <[email protected]>
1 parent 0f03daa commit 92c7e67

File tree

6 files changed

+611
-358
lines changed

6 files changed

+611
-358
lines changed

ReadMe.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ npm install web-utility
1919

2020
```html
2121
<head>
22+
<script src="https://polyfill.web-cell.dev/feature/ECMAScript.js"></script>
2223
<script src="https://polyfill.web-cell.dev/feature/Regenerator.js"></script>
2324
<script src="https://polyfill.web-cell.dev/feature/TextEncoder.js"></script>
2425
<script src="https://polyfill.web-cell.dev/feature/URL.js"></script>
@@ -196,6 +197,30 @@ describe('My module', async () => {
196197
});
197198
```
198199
200+
### CSV/TSV Parser
201+
202+
```typescript
203+
import { FileHandle, open } from 'fs/promises';
204+
import { readTextTable } from 'web-utility';
205+
206+
interface Article {
207+
id: number;
208+
title: string;
209+
}
210+
let fileHandle: FileHandle | undefined;
211+
212+
try {
213+
fileHandle = await open('path/to/your-article.csv');
214+
215+
for await (const row of readTextTable<Article>(
216+
fileHandle.createReadStream()
217+
))
218+
console.table(row);
219+
} finally {
220+
await fileHandle?.close();
221+
}
222+
```
223+
199224
[1]: https://www.typescriptlang.org/
200225
[2]: https://libraries.io/npm/web-utility
201226
[3]: https://github.com/EasyWebApp/web-utility/actions/workflows/main.yml

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-utility",
3-
"version": "4.5.3",
3+
"version": "4.6.0",
44
"license": "LGPL-3.0",
55
"author": "[email protected]",
66
"description": "Web front-end toolkit based on TypeScript",
@@ -36,19 +36,19 @@
3636
"@parcel/transformer-typescript-types": "~2.15.4",
3737
"@peculiar/webcrypto": "^1.5.0",
3838
"@types/jest": "^29.5.14",
39-
"@types/node": "^22.18.0",
39+
"@types/node": "^22.18.3",
4040
"@webcomponents/webcomponentsjs": "^2.8.0",
4141
"core-js": "^3.45.1",
4242
"husky": "^9.1.7",
4343
"intersection-observer": "^0.12.2",
4444
"jest": "^29.7.0",
4545
"jest-environment-jsdom": "^29.7.0",
46-
"lint-staged": "^16.1.5",
46+
"lint-staged": "^16.1.6",
4747
"open-cli": "^8.0.0",
4848
"parcel": "~2.15.4",
4949
"prettier": "^3.6.2",
5050
"ts-jest": "^29.4.1",
51-
"typedoc": "^0.28.11",
51+
"typedoc": "^0.28.12",
5252
"typedoc-plugin-mdn-links": "^5.0.9",
5353
"typescript": "~5.9.2"
5454
},

0 commit comments

Comments
 (0)