goods-exporter
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -533,11 +533,14 @@ import { XMLBuilder } from 'fast-xml-parser'; | ||
type Transformer = (product: Product) => Product; | ||
type Exporter = (data: Buffer) => any | Promise<any>; | ||
declare class Exporter { | ||
declare class GoodsExporter { | ||
private formatter; | ||
private exporter; | ||
private transformers; | ||
setTransformers(transformers: Transformer[]): void; | ||
setFormatter(formatter: Formatter): void; | ||
export(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<string>; | ||
setExporter(exporter: Exporter): void; | ||
export<T>(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<T>; | ||
} | ||
export { CSVFormatter, type Category, Currency, Exporter, type Formatter, type FormatterOptions, Formatters, type IParam, type Product, type Transformer, Vat, YMLFormatter }; | ||
export { CSVFormatter, type Category, Currency, type Exporter, type Formatter, type FormatterOptions, Formatters, GoodsExporter, type IParam, type Product, type Transformer, Vat, YMLFormatter }; |
@@ -14,3 +14,3 @@ { | ||
"name": "goods-exporter", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data export tasks with ease.", | ||
@@ -28,5 +28,6 @@ "main": "./dist/cjs/index.cjs", | ||
"scripts": { | ||
"start": "ts-node main.ts", | ||
"build": "rollup -c", | ||
"test": "ts-mocha test/*.test.ts" | ||
"test": "vitest", | ||
"test-ui": "vitest --ui", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
@@ -66,3 +67,5 @@ "keywords": [ | ||
"ts-mocha": "^10.0.0", | ||
"typescript": "^5.2.2" | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6" | ||
}, | ||
@@ -69,0 +72,0 @@ "engines": { |
# goods-exporter | ||
![Version](https://img.shields.io/badge/version-0.2.2-blue) | ||
[![npm version](https://badge.fury.io/js/goods-exporter.svg)](https://badge.fury.io/js/goods-exporter) | ||
![License](https://img.shields.io/badge/license-MIT-green) | ||
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data export tasks with ease. | ||
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data | ||
export tasks with ease. | ||
[![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/goods_exporter) | ||
## Features | ||
@@ -30,1 +33,47 @@ | ||
``` | ||
## Usage | ||
```typescript | ||
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](https://t.me/PoizonAPI) | ||
[![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
118221
940
79
19
2