goods-exporter 0.3.10 → 0.3.12

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,95 +1,95 @@
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
-
9
- A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
10
- export tasks with ease.
11
-
12
- [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
13
-
14
- ## Features
15
-
16
- - Export goods data to YML, CSV, and Excel formats.
17
- - Easily integrate into your JavaScript projects.
18
- - Compatible with Node.js version 16 and above.
19
- - Comprehensive TypeScript type definitions included.
20
-
21
- ## Supported formats
22
-
23
- - YML (Yandex Market Language)
24
- - CSV
25
- - Excel
26
- - TgShop
27
- - Insales
28
- - Tilda
29
-
30
- ## Installation
31
-
32
- To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
33
-
34
- ```bash
35
- npm install goods-exporter --save
36
- # or
37
- yarn add goods-exporter
38
- ```
39
-
40
- ## Quick start
41
-
42
- ```typescript
43
- import { GoodsExporter, Product, Category, Formatters } from '../src'
44
-
45
- // Create an instance of the GoodsExporter class.
46
- const exporter = new GoodsExporter()
47
-
48
- const products: Product[] = [] // Put your products;
49
- const categories: Category[] = [{ id: 1, name: 'Обувь' }]
50
-
51
- // Call the data export method.
52
- exporter.export(products, categories)
53
- ```
54
-
55
- ## Example
56
-
57
- ```typescript
58
- import fs from "fs"; // Import the 'fs' module for file writing.
59
-
60
- // Create an instance of the GoodsExporter class.
61
- const exporter = new GoodsExporter()
62
-
63
- // Define an object 'transformers' that contains data transformation functions.
64
- const transformers: Transformer[] = [
65
- (product) => ({
66
- ...product,
67
- price: product.price + 10000
68
- }),
69
- (product) => ({
70
- ...product,
71
- images: product.images?.map(image => image.replace("image", "pic"))
72
- })
73
- ]
74
-
75
- // Set the formatter for exporting data to YML.
76
- exporter.setFormatter(new Formatters.YMLFormatter()) // or your own Formatter;
77
-
78
- // Set transformers based on the specified keys.
79
- exporter.setTransformers(transformers);
80
-
81
- // Set an exporter that saves the data to the "output.yml" file.
82
- exporter.setExporter((data: Buffer) => {
83
- fs.writeFileSync("output.yml", data); // Write data to the "output.yml" file.
84
- return data; // Return the data (you can return any type).
85
- });
86
-
87
- // Call the data export method specifying the data type (Buffer) and expect the result as a promise.
88
- exporter.export<Buffer>(products, categories)
89
- .then(data => {
90
- // Here, you can add additional handling for the export result if needed.
91
- });
92
- ```
93
-
94
- # Supported by [PoizonAPI](https://t.me/PoizonAPI)
95
- [![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
+
9
+ A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
10
+ export tasks with ease.
11
+
12
+ [![Telegram](https://img.shields.io/badge/Telegram-%40goods_exporter-blue?logo=telegram)](https://t.me/+gGHmBC8VZ4BjYjZi)
13
+
14
+ ## Features
15
+
16
+ - Export goods data to YML, CSV, and Excel formats.
17
+ - Easily integrate into your JavaScript projects.
18
+ - Compatible with Node.js version 16 and above.
19
+ - Comprehensive TypeScript type definitions included.
20
+
21
+ ## Supported formats
22
+
23
+ - YML (Yandex Market Language)
24
+ - CSV
25
+ - Excel
26
+ - TgShop
27
+ - Insales
28
+ - Tilda
29
+
30
+ ## Installation
31
+
32
+ To use `goods-exporter` in your project, simply add it to your dependencies using npm or yarn:
33
+
34
+ ```bash
35
+ npm install goods-exporter --save
36
+ # or
37
+ yarn add goods-exporter
38
+ ```
39
+
40
+ ## Quick start
41
+
42
+ ```typescript
43
+ import { GoodsExporter, Product, Category, Formatters } from '../src'
44
+
45
+ // Create an instance of the GoodsExporter class.
46
+ const exporter = new GoodsExporter()
47
+
48
+ const products: Product[] = [] // Put your products;
49
+ const categories: Category[] = [{ id: 1, name: 'Обувь' }]
50
+
51
+ // Call the data export method.
52
+ exporter.export(products, categories)
53
+ ```
54
+
55
+ ## Example
56
+
57
+ ```typescript
58
+ import fs from "fs"; // Import the 'fs' module for file writing.
59
+
60
+ // Create an instance of the GoodsExporter class.
61
+ const exporter = new GoodsExporter()
62
+
63
+ // Define an object 'transformers' that contains data transformation functions.
64
+ const transformers: Transformer[] = [
65
+ (product) => ({
66
+ ...product,
67
+ price: product.price + 10000
68
+ }),
69
+ (product) => ({
70
+ ...product,
71
+ images: product.images?.map(image => image.replace("image", "pic"))
72
+ })
73
+ ]
74
+
75
+ // Set the formatter for exporting data to YML.
76
+ exporter.setFormatter(new Formatters.YMLFormatter()) // or your own Formatter;
77
+
78
+ // Set transformers based on the specified keys.
79
+ exporter.setTransformers(transformers);
80
+
81
+ // Set an exporter that saves the data to the "output.yml" file.
82
+ exporter.setExporter((data: Buffer) => {
83
+ fs.writeFileSync("output.yml", data); // Write data to the "output.yml" file.
84
+ return data; // Return the data (you can return any type).
85
+ });
86
+
87
+ // Call the data export method specifying the data type (Buffer) and expect the result as a promise.
88
+ exporter.export<Buffer>(products, categories)
89
+ .then(data => {
90
+ // Here, you can add additional handling for the export result if needed.
91
+ });
92
+ ```
93
+
94
+ # Supported by [PoizonAPI](https://t.me/PoizonAPI)
95
+ [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](https://t.me/PoizonAPI)
package/dist/bundle.d.ts CHANGED
@@ -471,6 +471,24 @@ interface Product {
471
471
  * Пример: 6241421
472
472
  */
473
473
  certificate?: string;
474
+ /**
475
+ * **Ключевые слова**
476
+ *
477
+ * Пример: Кроссовки, высокая подошва
478
+ */
479
+ keywords?: string[];
480
+ /**
481
+ * **Размерная сетка**
482
+ */
483
+ sizes?: ISize[];
484
+ /**
485
+ * **Связанные товары**
486
+ *
487
+ * Указываются id товаров
488
+ *
489
+ * Пример: 1234
490
+ */
491
+ relatedProducts?: number[];
474
492
  }
475
493
  declare enum Vat {
476
494
  NO_VAT = "NO_VAT",
@@ -496,6 +514,22 @@ interface IParam {
496
514
  */
497
515
  value: string;
498
516
  }
517
+ interface ISize {
518
+ /**
519
+ * **Название единицы измерения**
520
+ */
521
+ name: string;
522
+ /**
523
+ * **Разделитель**
524
+ */
525
+ delimiter: string;
526
+ /**
527
+ * **Значения размерного ряда**
528
+ *
529
+ * Размеры указываются через разделитель
530
+ */
531
+ value: string;
532
+ }
499
533
 
500
534
  interface Category {
501
535
  /**
@@ -535,13 +569,13 @@ declare enum Extension {
535
569
  declare class CSVFormatter implements FormatterAbstract {
536
570
  formatterName: string;
537
571
  fileExtension: Extension;
538
- format(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<string>;
572
+ format(products: Product[], categories?: Category[], options?: FormatterOptions): Promise<string>;
539
573
  }
540
574
 
541
575
  declare class ExcelFormatter implements FormatterAbstract {
542
576
  formatterName: string;
543
577
  fileExtension: Extension;
544
- format(products: Product[], categories?: Category[], _?: FormatterOptions): Promise<Buffer>;
578
+ format(products: Product[], categories?: Category[], options?: FormatterOptions): Promise<Buffer>;
545
579
  }
546
580
 
547
581
  declare class InsalesFormatter implements FormatterAbstract {
@@ -592,4 +626,4 @@ declare class GoodsExporter {
592
626
  export(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<Buffer>;
593
627
  }
594
628
 
595
- export { type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type Product, type Transformer, Vat };
629
+ export { type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat };
@@ -34,6 +34,39 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
34
34
  return Extension2;
35
35
  })(Extension || {});
36
36
 
37
+ const getParams = (product, option) => {
38
+ const params = {};
39
+ if (option?.splitParams === false) {
40
+ return params;
41
+ }
42
+ product.params?.forEach(
43
+ ({ key, value }) => params[`Param [${key}]`] = value
44
+ );
45
+ return params;
46
+ };
47
+ const getProperties = (product, option) => {
48
+ const properties = {};
49
+ if (option?.splitParams === false) {
50
+ return properties;
51
+ }
52
+ product.properties?.forEach(
53
+ ({ key, value }) => properties[`Property [${key}]`] = value
54
+ );
55
+ return properties;
56
+ };
57
+ const getSizes = (product, option) => {
58
+ const sizes = {};
59
+ product.sizes?.forEach(
60
+ ({ name, value }) => sizes[`Size [${name}]`] = value
61
+ );
62
+ return sizes;
63
+ };
64
+ const UTILS = {
65
+ getSizes,
66
+ getParams,
67
+ getProperties
68
+ };
69
+
37
70
  var __defProp$6 = Object.defineProperty;
38
71
  var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
72
  var __publicField$6 = (obj, key, value) => {
@@ -45,29 +78,9 @@ class CSVFormatter {
45
78
  __publicField$6(this, "formatterName", "CSV");
46
79
  __publicField$6(this, "fileExtension", Extension.CSV);
47
80
  }
48
- async format(products, categories, option) {
81
+ async format(products, categories, options) {
49
82
  const mappedCategories = {};
50
83
  categories?.forEach(({ id, name }) => mappedCategories[id] = name);
51
- const getParams = (product) => {
52
- const params = {};
53
- if (option?.splitParams === false) {
54
- return params;
55
- }
56
- product.params?.forEach(
57
- ({ key, value }) => params[`Param [${key}]`] = value
58
- );
59
- return params;
60
- };
61
- const getProperties = (product) => {
62
- const properties = {};
63
- if (option?.splitParams === false) {
64
- return properties;
65
- }
66
- product.properties?.forEach(
67
- ({ key, value }) => properties[`Property [${key}]`] = value
68
- );
69
- return properties;
70
- };
71
84
  const data = products.map((product) => ({
72
85
  ...product,
73
86
  category: mappedCategories[product.categoryId],
@@ -76,8 +89,12 @@ class CSVFormatter {
76
89
  tags: product.tags?.join(","),
77
90
  codesTN: product.codesTN?.join(", "),
78
91
  params: product.params?.map(({ key, value }) => `${key}=${value}`).join(","),
79
- ...getParams(product),
80
- ...getProperties(product)
92
+ ...UTILS.getParams(product, options),
93
+ ...UTILS.getProperties(product, options),
94
+ ...UTILS.getSizes(product, options),
95
+ sizes: void 0,
96
+ keywords: product.keywords?.join(","),
97
+ relatedProducts: product.relatedProducts?.join(",")
81
98
  }));
82
99
  return json2Csv.json2csv(data, { emptyFieldValue: "" });
83
100
  }
@@ -94,33 +111,23 @@ class ExcelFormatter {
94
111
  __publicField$5(this, "formatterName", "Excel");
95
112
  __publicField$5(this, "fileExtension", Extension.XLSX);
96
113
  }
97
- async format(products, categories, _) {
114
+ async format(products, categories, options) {
98
115
  const mappedCategories = {};
99
116
  categories?.forEach(({ id, name }) => mappedCategories[id] = name);
100
- const getParams = (product) => {
101
- const params = {};
102
- product.params?.forEach(
103
- ({ key, value }) => params[`Param [${key}]`] = value
104
- );
105
- return params;
106
- };
107
- const getProperties = (product) => {
108
- const properties = {};
109
- product.properties?.forEach(
110
- ({ key, value }) => properties[`Property [${key}]`] = value
111
- );
112
- return properties;
113
- };
114
117
  const data = products.map((product) => ({
115
118
  ...product,
116
119
  category: mappedCategories[product.categoryId],
117
120
  images: product.images?.join(","),
118
121
  videos: product.videos?.join(","),
119
122
  tags: product.tags?.join(","),
123
+ keywords: product.keywords?.join(","),
124
+ relatedProducts: product.relatedProducts?.join(","),
120
125
  codesTN: product.codesTN?.join(", "),
121
126
  params: product.params?.map(({ key, value }) => `${key}=${value}`).join(","),
122
- ...getParams(product),
123
- ...getProperties(product)
127
+ sizes: void 0,
128
+ ...UTILS.getParams(product, options),
129
+ ...UTILS.getProperties(product, options),
130
+ ...UTILS.getSizes(product, options)
124
131
  }));
125
132
  const workBook = xlsx.utils.book_new();
126
133
  const productsWorkSheet = xlsx.utils.json_to_sheet(data);
@@ -159,6 +166,13 @@ class InsalesFormatter {
159
166
  );
160
167
  return properties;
161
168
  };
169
+ const getSizes = (product) => {
170
+ const sizes = {};
171
+ product.sizes?.forEach(
172
+ ({ name, value }) => sizes[`\u0420\u0430\u0437\u043C\u0435\u0440\u044B [${name}]:`] = value
173
+ );
174
+ return sizes;
175
+ };
162
176
  const getCategories = (product) => {
163
177
  const categories2 = {};
164
178
  const categoryList = new Array();
@@ -202,7 +216,9 @@ class InsalesFormatter {
202
216
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434": product.vendor,
203
217
  \u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
204
218
  ...getParams(product),
205
- ...getProperties(product)
219
+ ...getProperties(product),
220
+ ...getSizes(product),
221
+ "\u0421\u0432\u044F\u0437\u0430\u043D\u043D\u044B\u0435 \u0442\u043E\u0432\u0430\u0440\u044B": product.relatedProducts?.join(",")
206
222
  }));
207
223
  const workBook = xlsx.utils.book_new();
208
224
  const productsWorkSheet = xlsx.utils.json_to_sheet(data);
@@ -344,6 +360,12 @@ class YMLFormatter {
344
360
  available: product.available,
345
361
  "min-quantity": product.minQuantity,
346
362
  "step-quantity": product.stepQuantity,
363
+ size: product.sizes?.map((size) => ({
364
+ "#text": size.value,
365
+ "@_name": size.name,
366
+ "@_delimiter": size.delimiter
367
+ })),
368
+ keyword: product.keywords,
347
369
  property: product.properties?.map((property) => ({
348
370
  "#text": property.value,
349
371
  "@_name": property.key
@@ -381,7 +403,8 @@ class YMLFormatter {
381
403
  },
382
404
  "tn-ved-codes": product.codesTN?.length != null && {
383
405
  "tn-ved-code": product.codesTN
384
- }
406
+ },
407
+ relatedProduct: product.relatedProducts
385
408
  };
386
409
  if (product.parentId !== void 0) {
387
410
  return {