goods-exporter 1.4.8 → 1.4.9

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/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2023 German Bagdasaryan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- “Software”), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2023 German Bagdasaryan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ “Software”), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,106 +1,106 @@
1
- # goods-exporter
2
-
3
- [![npm version](https://img.shields.io/npm/v/goods-exporter)](https://www.npmjs.com/package/goods-exporter)
4
- ![npm](https://img.shields.io/npm/dm/goods-exporter)
5
- ![GitHub issues](https://img.shields.io/github/issues/Bagi4-source/goods-converter)
6
- [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
7
-
8
- A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
9
- export tasks with ease.
10
-
11
- [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
12
-
13
- ## Features
14
-
15
- - Export goods data to JSON, YML, CSV, and Excel formats.
16
- - Easily integrate into your JavaScript projects.
17
- - Compatible with Node.js version 16 and above.
18
- - Comprehensive TypeScript type definitions included.
19
- - Supports streams.
20
-
21
- ## Supported formats
22
-
23
- - YML (Yandex Market Language)
24
- - JSON
25
- - SimpleJSON (grouped)
26
- - CSV
27
- - Excel
28
- - TgShop
29
- - Insales
30
- - Tilda
31
- - WooCommerce
32
-
33
- ## Installation
34
-
35
- To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
36
-
37
- ```bash
38
- npm install goods-exporter --save
39
- # or
40
- yarn add goods-exporter
41
- ```
42
-
43
- ## Quick start
44
-
45
- ```typescript
46
- import { GoodsExporter, Product, Category, Formatters } from "../src";
47
- import { PassThrough } from "stream";
48
-
49
- // Create an instance of the GoodsExporter class.
50
- const exporter = new GoodsExporter();
51
-
52
- const products: Product[] = []; // Put your products;
53
- const categories: Category[] = [{ id: 1, name: "Обувь" }];
54
-
55
- // Call the data export method.
56
- const stream = new PassThrough();
57
- exporter.setExporter(() => stream);
58
- exporter.setFormatter(new Formatters.YMLFormatter());
59
- exporter.setTransformers([
60
- (products) => {
61
- return products.map((product) => ({
62
- ...product,
63
- price: product.price + 10000,
64
- images: product.images?.map((image) => image.replace("image", "pic")),
65
- }));
66
- },
67
- ]);
68
- await exporter.export(products, categories);
69
- ```
70
-
71
- ## Example
72
-
73
- ```typescript
74
- import fs from "fs"; // Import the 'fs' module for file writing.
75
-
76
- // Create an instance of the GoodsExporter class.
77
- const exporter = new GoodsExporter();
78
-
79
- // Define an object 'transformers' that contains data transformation functions.
80
- const transformers: Transformer[] = [
81
- (products) =>
82
- products.map((product) => ({
83
- ...product,
84
- price: product.price + 10000,
85
- })),
86
- (products) =>
87
- products.map((product) => ({
88
- ...product,
89
- images: product.images?.map((image) => image.replace("image", "pic")),
90
- })),
91
- ];
92
-
93
- // Set the formatter for exporting data to YML.
94
- exporter.setFormatter(new Formatters.YMLFormatter()); // or your own Formatter;
95
-
96
- // Set transformers based on the specified keys.
97
- exporter.setTransformers(transformers);
98
-
99
- // Set an exporter that saves the data to the "output.yml" file.
100
- exporter.setExporter(fs.createWriteStream("output.yml"));
101
- await exporter.export(products, categories);
102
- ```
103
-
104
- # Supported by [PoizonAPI](https://t.me/PoizonAPI)
105
-
106
- [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI)
1
+ # goods-exporter
2
+
3
+ [![npm version](https://img.shields.io/npm/v/goods-exporter)](https://www.npmjs.com/package/goods-exporter)
4
+ ![npm](https://img.shields.io/npm/dm/goods-exporter)
5
+ ![GitHub issues](https://img.shields.io/github/issues/Bagi4-source/goods-converter)
6
+ [![License](https://img.shields.io/badge/license-MIT-green)](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
7
+
8
+ A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
9
+ export tasks with ease.
10
+
11
+ [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
12
+
13
+ ## Features
14
+
15
+ - Export goods data to JSON, YML, CSV, and Excel formats.
16
+ - Easily integrate into your JavaScript projects.
17
+ - Compatible with Node.js version 16 and above.
18
+ - Comprehensive TypeScript type definitions included.
19
+ - Supports streams.
20
+
21
+ ## Supported formats
22
+
23
+ - YML (Yandex Market Language)
24
+ - JSON
25
+ - SimpleJSON (grouped)
26
+ - CSV
27
+ - Excel
28
+ - TgShop
29
+ - Insales
30
+ - Tilda
31
+ - WooCommerce
32
+
33
+ ## Installation
34
+
35
+ To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
36
+
37
+ ```bash
38
+ npm install goods-exporter --save
39
+ # or
40
+ yarn add goods-exporter
41
+ ```
42
+
43
+ ## Quick start
44
+
45
+ ```typescript
46
+ import { GoodsExporter, Product, Category, Formatters } from "../src";
47
+ import { PassThrough } from "stream";
48
+
49
+ // Create an instance of the GoodsExporter class.
50
+ const exporter = new GoodsExporter();
51
+
52
+ const products: Product[] = []; // Put your products;
53
+ const categories: Category[] = [{ id: 1, name: "Обувь" }];
54
+
55
+ // Call the data export method.
56
+ const stream = new PassThrough();
57
+ exporter.setExporter(() => stream);
58
+ exporter.setFormatter(new Formatters.YMLFormatter());
59
+ exporter.setTransformers([
60
+ (products) => {
61
+ return products.map((product) => ({
62
+ ...product,
63
+ price: product.price + 10000,
64
+ images: product.images?.map((image) => image.replace("image", "pic")),
65
+ }));
66
+ },
67
+ ]);
68
+ await exporter.export(products, categories);
69
+ ```
70
+
71
+ ## Example
72
+
73
+ ```typescript
74
+ import fs from "fs"; // Import the 'fs' module for file writing.
75
+
76
+ // Create an instance of the GoodsExporter class.
77
+ const exporter = new GoodsExporter();
78
+
79
+ // Define an object 'transformers' that contains data transformation functions.
80
+ const transformers: Transformer[] = [
81
+ (products) =>
82
+ products.map((product) => ({
83
+ ...product,
84
+ price: product.price + 10000,
85
+ })),
86
+ (products) =>
87
+ products.map((product) => ({
88
+ ...product,
89
+ images: product.images?.map((image) => image.replace("image", "pic")),
90
+ })),
91
+ ];
92
+
93
+ // Set the formatter for exporting data to YML.
94
+ exporter.setFormatter(new Formatters.YMLFormatter()); // or your own Formatter;
95
+
96
+ // Set transformers based on the specified keys.
97
+ exporter.setTransformers(transformers);
98
+
99
+ // Set an exporter that saves the data to the "output.yml" file.
100
+ exporter.setExporter(fs.createWriteStream("output.yml"));
101
+ await exporter.export(products, categories);
102
+ ```
103
+
104
+ # Supported by [PoizonAPI](https://t.me/PoizonAPI)
105
+
106
+ [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI)
package/dist/bundle.d.ts CHANGED
@@ -639,7 +639,7 @@ declare class ExcelFormatter implements FormatterAbstract {
639
639
  declare class InsalesFormatter implements FormatterAbstract {
640
640
  formatterName: string;
641
641
  fileExtension: Extension;
642
- format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
642
+ format(writableStream: Writable, products: Product[], categories?: Category[], brands?: Brand[], __?: FormatterOptions): Promise<void>;
643
643
  }
644
644
 
645
645
  declare class JSONFormatter implements FormatterAbstract {
@@ -267,11 +267,13 @@ class InsalesFormatter {
267
267
  __publicField$9(this, "formatterName", "Insales");
268
268
  __publicField$9(this, "fileExtension", Extension.XLSX);
269
269
  }
270
- async format(writableStream, products, categories, _, __) {
270
+ async format(writableStream, products, categories, brands, __) {
271
271
  const mappedCategories = {};
272
272
  categories?.forEach(
273
273
  (category) => mappedCategories[category.id] = category
274
274
  );
275
+ const mappedBrands = {};
276
+ brands?.forEach((brand) => mappedBrands[brand.id] = brand);
275
277
  const getParams = (product) => {
276
278
  const properties = {};
277
279
  product.params?.forEach(
@@ -338,6 +340,7 @@ class InsalesFormatter {
338
340
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0410\u0440\u0442\u0438\u043A\u0443\u043B",
339
341
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)",
340
342
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)",
343
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041B\u043E\u0433\u043E\u0442\u0438\u043F \u0431\u0440\u0435\u043D\u0434\u0430 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)",
341
344
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0421\u0435\u0440\u0438\u044F (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)",
342
345
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0440\u0435\u043B\u0438\u0437\u0430 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)",
343
346
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B",
@@ -388,6 +391,7 @@ class InsalesFormatter {
388
391
  // TODO: брать из обычных параметров,
389
392
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041F\u043E\u043B (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)": product.gender,
390
393
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)": product.vendor,
394
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u041B\u043E\u0433\u043E\u0442\u0438\u043F \u0431\u0440\u0435\u043D\u0434\u0430 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)": product.vendorId === void 0 ? void 0 : mappedBrands[product.vendorId]?.logoUrl,
391
395
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0421\u0435\u0440\u0438\u044F (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)": product.seriesName,
392
396
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0414\u0430\u0442\u0430 \u0440\u0435\u043B\u0438\u0437\u0430 (\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u044B\u0439)": product.saleDate,
393
397
  ...getParams(product),