JSPM

  • Created
  • Published
  • Downloads 471
  • Score
    100M100P100Q76983F
  • License MIT

A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data export tasks with ease.

Package Exports

  • goods-exporter

Readme

goods-exporter

npm version License

A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data export tasks with ease.

Telegram

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
# or
yarn add goods-exporter

Usage

import {GoodsExporter, Formatters, Transformer, Category, Currency, Product, Vat} from "goods-exporter";
import fs from "fs"; // Import the 'fs' module for file writing.

// Create an instance of the GoodsExporter class.
const exporter = new GoodsExporter();

// Define an object 'transformers' that contains data transformation functions.
const transformers: Record<string, Transformer> = {
    PRICE: (product) => ({
        ...product,
        price: product.price + 10000
    }),
    IMAGE: (product) => ({
        ...product,
        images: product.images?.map(image => image.replace("image", "pic"))
    })
}

// Define an array 'keys' that contains the transformation keys you want to apply.
const keys = ["PRICE"];

// Set the formatter for exporting data to YML.
exporter.setFormatter(Formatters.YML);

// Set transformers based on the specified keys.
exporter.setTransformers(keys.map(key => transformers[key]));

// Set an exporter that saves the data to the "output.yml" file.
exporter.setExporter((data: Buffer) => {
    fs.writeFileSync("output.yml", data); // Write data to the "output.yml" file.
    return data; // Return the data (you can return any type).
});

// Call the data export method specifying the data type (Buffer) and expect the result as a promise.
exporter.export<Buffer>(products, categories)
    .then(data => {
        // Here, you can add additional handling for the export result if needed.
    });

Supported by PoizonAPI

PoizonAPI