goods-exporter
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
export tasks with ease.
Features
- Export goods data to YML, CSV, and Excel formats.
- Easily integrate into your JavaScript projects.
- Compatible with Node.js version 16 and above.
- Comprehensive TypeScript type definitions included.
Supported formats
- YML (Yandex Market Language)
- CSV
- Excel
Installation
To use goods-exporter
in your project, simply add it to your dependencies using npm or yarn:
npm install goods-exporter --save
yarn add goods-exporter
Usage
import {GoodsExporter, Formatters, Transformer, Category, Currency, Product, Vat} from "goods-exporter";
import fs from "fs";
const exporter = new GoodsExporter();
const transformers: Record<string, Transformer> = {
PRICE: (product) => ({
...product,
price: product.price + 10000
}),
IMAGE: (product) => ({
...product,
images: product.images?.map(image => image.replace("image", "pic"))
})
}
const keys = ["PRICE"];
exporter.setFormatter(Formatters.YML);
exporter.setTransformers(keys.map(key => transformers[key]));
exporter.setExporter((data: Buffer) => {
fs.writeFileSync("output.yml", data);
return data;
});
exporter.export<Buffer>(products, categories)
.then(data => {
});