1.0.7 β’ Published 8 months ago
sheet-parser v1.0.7
Sheet-Parser
A lightweight Node.js library for parsing CSV, XLSX, and other structured data formats into usable JavaScript objects. Designed for performance and scalability, it handles large files efficiently and supports various encodings.
Features
- π Parse CSV files into structured JavaScript objects.
- π Scalable: Handles small files (KBs) to large datasets (GBs) seamlessly.
- π€ Encoding Support: Decode files with encodings like UTF-8, ISO-8859-1, and Windows-1252.
- βοΈ Stream-Based: Efficient parsing for memory-intensive operations.
- π οΈ Extensible: Designed to support future additions like XLSX parsing.
Installation
To install the library, run:
npm install sheet-parser
Usage
Basic Example
Hereβs how to parse a simple CSV file:
const { parseCSV } = require('sheet-parser');
const path = require('path');
(async () => {
const filePath = path.resolve(__dirname, './sample.csv');
const data = await parseCSV(filePath); // Default delimiter: ','; Default encoding: 'utf8'
console.log(data);
})();
Input sample.csv
:
name,age,city
John,30,New York
Jane,25,Los Angeles
Output:
[
{ "name": "John", "age": "30", "city": "New York" },
{ "name": "Jane", "age": "25", "city": "Los Angeles" }
]
API Reference
parseCSV
- Description: Parses a CSV file into an array of objects.
- Parameters:
filePath
(string, required): Path to the input CSV file.delimiter
(string, optional): Character used to separate fields (default:,
).encoding
(string, optional): File encoding (default:utf8
).
- Returns: A
Promise
that resolves to an array of objects.
Example:
const data = await parseCSV('./data.csv', ',', 'utf8');
Supported Features
- β Multi-line fields
- β Fields with embedded delimiters
- β Custom delimiters
- β Support for various encodings
- β Robust handling of missing or null values
Contributing
We welcome contributions to improve this library! Here's how you can help:
- Fork the repository.
- Create a new branch for your feature/bug fix.
- Submit a pull request with a clear description of the change.
If you encounter any issues or have feature requests, please create an issue by following these steps:
- Go to the Issues page of the GitHub repository.
- Click on New Issue.
- Provide a clear title and detailed description of the problem or feature request.
Changelog
v1.0.0
- Initial release with support for CSV parsing.
- Features:
- Handle large files using streams.
- Multi-encoding support.
- Output CSV as JavaScript objects.
License
This project is licensed under the MIT License. See the LICENSE file for details.