goods-exporter 0.3.10 → 0.3.11

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,16 @@ 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[];
474
484
  }
475
485
  declare enum Vat {
476
486
  NO_VAT = "NO_VAT",
@@ -496,6 +506,22 @@ interface IParam {
496
506
  */
497
507
  value: string;
498
508
  }
509
+ interface ISize {
510
+ /**
511
+ * **Название единицы измерения**
512
+ */
513
+ name: string;
514
+ /**
515
+ * **Разделитель**
516
+ */
517
+ delimiter: string;
518
+ /**
519
+ * **Значения размерного ряда**
520
+ *
521
+ * Размеры указываются через разделитель
522
+ */
523
+ value: string;
524
+ }
499
525
 
500
526
  interface Category {
501
527
  /**
@@ -535,13 +561,13 @@ declare enum Extension {
535
561
  declare class CSVFormatter implements FormatterAbstract {
536
562
  formatterName: string;
537
563
  fileExtension: Extension;
538
- format(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<string>;
564
+ format(products: Product[], categories?: Category[], options?: FormatterOptions): Promise<string>;
539
565
  }
540
566
 
541
567
  declare class ExcelFormatter implements FormatterAbstract {
542
568
  formatterName: string;
543
569
  fileExtension: Extension;
544
- format(products: Product[], categories?: Category[], _?: FormatterOptions): Promise<Buffer>;
570
+ format(products: Product[], categories?: Category[], options?: FormatterOptions): Promise<Buffer>;
545
571
  }
546
572
 
547
573
  declare class InsalesFormatter implements FormatterAbstract {
@@ -592,4 +618,4 @@ declare class GoodsExporter {
592
618
  export(products: Product[], categories?: Category[], option?: FormatterOptions): Promise<Buffer>;
593
619
  }
594
620
 
595
- export { type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type Product, type Transformer, Vat };
621
+ 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,11 @@ 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
+ sizes: void 0,
95
+ keywords: product.keywords?.join(","),
96
+ ...UTILS.getSizes(product, options)
81
97
  }));
82
98
  return json2Csv.json2csv(data, { emptyFieldValue: "" });
83
99
  }
@@ -94,33 +110,22 @@ class ExcelFormatter {
94
110
  __publicField$5(this, "formatterName", "Excel");
95
111
  __publicField$5(this, "fileExtension", Extension.XLSX);
96
112
  }
97
- async format(products, categories, _) {
113
+ async format(products, categories, options) {
98
114
  const mappedCategories = {};
99
115
  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
116
  const data = products.map((product) => ({
115
117
  ...product,
116
118
  category: mappedCategories[product.categoryId],
117
119
  images: product.images?.join(","),
118
120
  videos: product.videos?.join(","),
119
121
  tags: product.tags?.join(","),
122
+ keywords: product.keywords?.join(","),
120
123
  codesTN: product.codesTN?.join(", "),
121
124
  params: product.params?.map(({ key, value }) => `${key}=${value}`).join(","),
122
- ...getParams(product),
123
- ...getProperties(product)
125
+ sizes: void 0,
126
+ ...UTILS.getParams(product, options),
127
+ ...UTILS.getProperties(product, options),
128
+ ...UTILS.getSizes(product, options)
124
129
  }));
125
130
  const workBook = xlsx.utils.book_new();
126
131
  const productsWorkSheet = xlsx.utils.json_to_sheet(data);
@@ -159,6 +164,13 @@ class InsalesFormatter {
159
164
  );
160
165
  return properties;
161
166
  };
167
+ const getSizes = (product) => {
168
+ const sizes = {};
169
+ product.sizes?.forEach(
170
+ ({ name, value }) => sizes[`\u0420\u0430\u0437\u043C\u0435\u0440\u044B [${name}]:`] = value
171
+ );
172
+ return sizes;
173
+ };
162
174
  const getCategories = (product) => {
163
175
  const categories2 = {};
164
176
  const categoryList = new Array();
@@ -202,7 +214,8 @@ class InsalesFormatter {
202
214
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0411\u0440\u0435\u043D\u0434": product.vendor,
203
215
  \u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
204
216
  ...getParams(product),
205
- ...getProperties(product)
217
+ ...getProperties(product),
218
+ ...getSizes(product)
206
219
  }));
207
220
  const workBook = xlsx.utils.book_new();
208
221
  const productsWorkSheet = xlsx.utils.json_to_sheet(data);
@@ -344,6 +357,12 @@ class YMLFormatter {
344
357
  available: product.available,
345
358
  "min-quantity": product.minQuantity,
346
359
  "step-quantity": product.stepQuantity,
360
+ size: product.sizes?.map((size) => ({
361
+ "#text": size.value,
362
+ "@_name": size.name,
363
+ "@_delimiter": size.delimiter
364
+ })),
365
+ keyword: product.keywords,
347
366
  property: product.properties?.map((property) => ({
348
367
  "#text": property.value,
349
368
  "@_name": property.key