goods-exporter
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -14,3 +14,3 @@ { | ||
"name": "goods-exporter", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data export tasks with ease.", | ||
@@ -17,0 +17,0 @@ "main": "./dist/cjs/index.cjs", |
@@ -23,2 +23,5 @@ # goods-exporter | ||
- Excel | ||
- TgShop | ||
- Insales | ||
- Tilda | ||
@@ -35,31 +38,42 @@ ## Installation | ||
## Usage | ||
## Quick start | ||
```typescript | ||
import {GoodsExporter, Formatters, Transformer, Category, Currency, Product, Vat} from "goods-exporter"; | ||
import { GoodsExporter, Product, Category, YMLFormatter } from '../src' | ||
// Create an instance of the GoodsExporter class. | ||
const exporter = new GoodsExporter() | ||
const products: Product[] = [] // Put your products; | ||
const categories: Category[] = [{ id: 1, name: 'Обувь' }] | ||
// Call the data export method. | ||
exporter.export(products, categories) | ||
``` | ||
## Example | ||
```typescript | ||
import fs from "fs"; // Import the 'fs' module for file writing. | ||
// Create an instance of the GoodsExporter class. | ||
const exporter = new GoodsExporter(); | ||
const exporter = new GoodsExporter() | ||
// Define an object 'transformers' that contains data transformation functions. | ||
const transformers: Record<string, Transformer> = { | ||
PRICE: (product) => ({ | ||
const transformers: Transformer[] = [ | ||
(product) => ({ | ||
...product, | ||
price: product.price + 10000 | ||
}), | ||
IMAGE: (product) => ({ | ||
(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); | ||
exporter.setFormatter(new YMLFormatter()) // or your own Formatter; | ||
// Set transformers based on the specified keys. | ||
exporter.setTransformers(keys.map(key => transformers[key])); | ||
exporter.setTransformers(transformers); | ||
@@ -66,0 +80,0 @@ // Set an exporter that saves the data to the "output.yml" file. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118599
93