goods-exporter 0.4.7 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,6 +17,7 @@ export tasks with ease.
17
17
  - Easily integrate into your JavaScript projects.
18
18
  - Compatible with Node.js version 16 and above.
19
19
  - Comprehensive TypeScript type definitions included.
20
+ - Supports streams.
20
21
 
21
22
  ## Supported formats
22
23
 
@@ -41,7 +42,8 @@ yarn add goods-exporter
41
42
  ## Quick start
42
43
 
43
44
  ```typescript
44
- import { GoodsExporter, Product, Category, Formatters } from '../src'
45
+ import { GoodsExporter, Product, Category, Formatters } from '../src';
46
+ import { PassThrough } from "stream";
45
47
 
46
48
  // Create an instance of the GoodsExporter class.
47
49
  const exporter = new GoodsExporter()
@@ -50,7 +52,19 @@ const products: Product[] = [] // Put your products;
50
52
  const categories: Category[] = [{ id: 1, name: 'Обувь' }]
51
53
 
52
54
  // Call the data export method.
53
- exporter.export(products, categories)
55
+ const stream = new PassThrough();
56
+ exporter.setExporter(() => stream);
57
+ exporter.setFormatter(new Formatters.YMLFormatter());
58
+ exporter.setTransformers([
59
+ (products) => {
60
+ return products.map((product) => ({
61
+ ...product,
62
+ price: product.price + 10000,
63
+ images: product.images?.map((image) => image.replace("image", "pic")),
64
+ }));
65
+ },
66
+ ]);
67
+ await exporter.export(products, categories);
54
68
  ```
55
69
 
56
70
  ## Example
@@ -80,16 +94,8 @@ exporter.setFormatter(new Formatters.YMLFormatter()) // or your own Formatter;
80
94
  exporter.setTransformers(transformers);
81
95
 
82
96
  // Set an exporter that saves the data to the "output.yml" file.
83
- exporter.setExporter((data: Buffer) => {
84
- fs.writeFileSync("output.yml", data); // Write data to the "output.yml" file.
85
- return data; // Return the data (you can return any type).
86
- });
87
-
88
- // Call the data export method specifying the data type (Buffer) and expect the result as a promise.
89
- exporter.export<Buffer>(products, categories)
90
- .then(data => {
91
- // Here, you can add additional handling for the export result if needed.
92
- });
97
+ exporter.setExporter(fs.createWriteStream("output.yml"));
98
+ await exporter.export(products, categories);
93
99
  ```
94
100
 
95
101
  # Supported by [PoizonAPI](https://t.me/PoizonAPI)
package/dist/bundle.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Stream, Writable } from 'stream';
2
+
1
3
  interface Product {
2
4
  /**
3
5
  * **ID товара**
@@ -582,7 +584,7 @@ interface Brand {
582
584
  declare abstract class FormatterAbstract {
583
585
  abstract formatterName: string;
584
586
  abstract fileExtension: Extension;
585
- abstract format(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<Buffer | string>;
587
+ abstract format(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<Stream>;
586
588
  }
587
589
  interface FormatterOptions {
588
590
  shopName?: string;
@@ -599,44 +601,43 @@ declare enum Extension {
599
601
  declare class CSVFormatter implements FormatterAbstract {
600
602
  formatterName: string;
601
603
  fileExtension: Extension;
602
- format(products: Product[], categories?: Category[], _?: Brand[], options?: FormatterOptions): Promise<string>;
604
+ format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
603
605
  }
604
606
 
605
607
  declare class ExcelFormatter implements FormatterAbstract {
606
608
  formatterName: string;
607
609
  fileExtension: Extension;
608
- format(products: Product[], categories?: Category[], _?: Brand[], options?: FormatterOptions): Promise<Buffer>;
610
+ format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
609
611
  }
610
612
 
611
613
  declare class InsalesFormatter implements FormatterAbstract {
612
614
  formatterName: string;
613
615
  fileExtension: Extension;
614
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Buffer>;
616
+ format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
615
617
  }
616
618
 
617
619
  declare class JSONFormatter implements FormatterAbstract {
618
620
  formatterName: string;
619
621
  fileExtension: Extension;
620
- format(products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<string>;
622
+ format(products: Product[], categories?: Category[], brands?: Brand[], _?: FormatterOptions): Promise<Stream>;
621
623
  }
622
624
 
623
625
  declare class TgShopFormatter implements FormatterAbstract {
624
626
  formatterName: string;
625
627
  fileExtension: Extension;
626
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Buffer>;
628
+ format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
627
629
  }
628
630
 
629
631
  declare class TildaFormatter implements FormatterAbstract {
630
632
  formatterName: string;
631
633
  fileExtension: Extension;
632
- format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<string>;
634
+ format(products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<Stream>;
633
635
  }
634
636
 
635
637
  declare class YMLFormatter implements FormatterAbstract {
636
638
  formatterName: string;
637
639
  fileExtension: Extension;
638
- private readonly builder;
639
- format(products: Product[], categories?: Category[], brands?: Brand[], options?: FormatterOptions): Promise<string>;
640
+ format(products: Product[], categories?: Category[], brands?: Brand[], options?: FormatterOptions): Promise<Stream>;
640
641
  private getBrands;
641
642
  private getCategories;
642
643
  private getOffers;
@@ -653,7 +654,7 @@ declare const Formatters: {
653
654
  };
654
655
 
655
656
  type Transformer = (products: Product[]) => Product[] | Promise<Product[]>;
656
- type Exporter = (data: Buffer) => Buffer | Promise<Buffer>;
657
+ type Exporter = () => Writable;
657
658
 
658
659
  declare class GoodsExporter {
659
660
  private formatter;
@@ -662,7 +663,7 @@ declare class GoodsExporter {
662
663
  setTransformers(transformers: Transformer[]): void;
663
664
  setFormatter(formatter: FormatterAbstract): void;
664
665
  setExporter(exporter: Exporter): void;
665
- export(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<Buffer>;
666
+ export(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<void>;
666
667
  }
667
668
 
668
669
  export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat };