goods-exporter 1.2.5 → 1.2.7
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 +21 -21
- package/README.md +106 -106
- package/dist/bundle.d.ts +9 -0
- package/dist/cjs/index.cjs +30 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +30 -4
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +88 -88
- package/dist/package.json +0 -87
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
|
-
[](https://www.npmjs.com/package/goods-exporter)
|
|
4
|
-

|
|
5
|
-

|
|
6
|
-
[](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
|
-
[](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
|
-
[](https://t.me/PoizonAPI)
|
|
1
|
+
# goods-exporter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/goods-exporter)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](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
|
+
[](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
|
+
[](https://t.me/PoizonAPI)
|
package/dist/bundle.d.ts
CHANGED
|
@@ -241,6 +241,15 @@ interface Product {
|
|
|
241
241
|
* Поле указывает, есть ли товар в наличии.
|
|
242
242
|
*/
|
|
243
243
|
available?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* **Время доставки**
|
|
246
|
+
*
|
|
247
|
+
* Указывает на время доставки в днях, от и до скольких.
|
|
248
|
+
*/
|
|
249
|
+
timeDelivery?: {
|
|
250
|
+
min?: number;
|
|
251
|
+
max?: number;
|
|
252
|
+
};
|
|
244
253
|
/**
|
|
245
254
|
* **Минимальное количество товара**
|
|
246
255
|
*
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -78,6 +78,8 @@ class CSVFormatter {
|
|
|
78
78
|
"category",
|
|
79
79
|
"images",
|
|
80
80
|
"videos",
|
|
81
|
+
"timeDeliveryMin",
|
|
82
|
+
"timeDeliveryMax",
|
|
81
83
|
"price",
|
|
82
84
|
"oldPrice",
|
|
83
85
|
"purchasePrice",
|
|
@@ -110,7 +112,9 @@ class CSVFormatter {
|
|
|
110
112
|
properties: product.properties?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
111
113
|
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", "),
|
|
112
114
|
keywords: product.keywords?.join(","),
|
|
113
|
-
relatedProducts: product.relatedProducts?.join(",")
|
|
115
|
+
relatedProducts: product.relatedProducts?.join(","),
|
|
116
|
+
timeDeliveryMin: product.timeDelivery?.min,
|
|
117
|
+
timeDeliveryMax: product.timeDelivery?.max
|
|
114
118
|
};
|
|
115
119
|
csvStream.addRow(row);
|
|
116
120
|
});
|
|
@@ -142,6 +146,8 @@ class ExcelFormatter {
|
|
|
142
146
|
"category",
|
|
143
147
|
"images",
|
|
144
148
|
"videos",
|
|
149
|
+
"timeDeliveryMin",
|
|
150
|
+
"timeDeliveryMax",
|
|
145
151
|
"price",
|
|
146
152
|
"oldPrice",
|
|
147
153
|
"purchasePrice",
|
|
@@ -181,7 +187,9 @@ class ExcelFormatter {
|
|
|
181
187
|
codesTN: product.codesTN?.join(", "),
|
|
182
188
|
params: product.params?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
183
189
|
properties: product.properties?.map(({ key, value }) => `${key}=${value}`).join(", "),
|
|
184
|
-
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", ")
|
|
190
|
+
sizes: product.sizes?.map(({ name, value }) => `${name}=${value}`).join(", "),
|
|
191
|
+
timeDeliveryMin: product.timeDelivery?.min,
|
|
192
|
+
timeDeliveryMax: product.timeDelivery?.max
|
|
185
193
|
};
|
|
186
194
|
worksheet.addRow(row).commit();
|
|
187
195
|
});
|
|
@@ -249,6 +257,8 @@ class InsalesFormatter {
|
|
|
249
257
|
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 1",
|
|
250
258
|
"\u041F\u043E\u0434\u043A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F 2",
|
|
251
259
|
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438",
|
|
260
|
+
"\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435",
|
|
261
|
+
"\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435",
|
|
252
262
|
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430",
|
|
253
263
|
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438",
|
|
254
264
|
"C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C",
|
|
@@ -294,6 +304,8 @@ class InsalesFormatter {
|
|
|
294
304
|
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
|
|
295
305
|
\u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
|
|
296
306
|
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438": product.title,
|
|
307
|
+
"\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435": product.timeDelivery?.min,
|
|
308
|
+
"\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435": product.timeDelivery?.max,
|
|
297
309
|
"\u0421\u0442\u0430\u0440\u0430\u044F \u0446\u0435\u043D\u0430": product.oldPrice,
|
|
298
310
|
"\u0426\u0435\u043D\u0430 \u043F\u0440\u043E\u0434\u0430\u0436\u0438": product.price,
|
|
299
311
|
C\u0435\u0431\u0435\u0441\u0442\u043E\u0438\u043C\u043E\u0441\u0442\u044C: product.purchasePrice,
|
|
@@ -691,6 +703,7 @@ class WooCommerceFormatter {
|
|
|
691
703
|
csvStream.getWritableStream().pipe(writableStream);
|
|
692
704
|
const columns = new Set(this.DEFAULT_COLUMNS);
|
|
693
705
|
const attributes = this.extractAttributes(products);
|
|
706
|
+
const variationsByParentId = /* @__PURE__ */ new Map();
|
|
694
707
|
const variations = products.map((product, index) => {
|
|
695
708
|
const pathsArray = categoriePaths.get(product.categoryId)?.map((category) => category.name);
|
|
696
709
|
let row = {
|
|
@@ -711,6 +724,11 @@ class WooCommerceFormatter {
|
|
|
711
724
|
const productParams = attributes.params.get(product.variantId) ?? {};
|
|
712
725
|
this.removeVisibleFromAttributes(productParams);
|
|
713
726
|
row = { ...row, ...productParams };
|
|
727
|
+
if (variationsByParentId.has(row.Parent)) {
|
|
728
|
+
variationsByParentId.get(row.Parent)?.push(row);
|
|
729
|
+
} else {
|
|
730
|
+
variationsByParentId.set(row.Parent, [row]);
|
|
731
|
+
}
|
|
714
732
|
return row;
|
|
715
733
|
});
|
|
716
734
|
const parentProducts = /* @__PURE__ */ new Map();
|
|
@@ -746,8 +764,11 @@ class WooCommerceFormatter {
|
|
|
746
764
|
});
|
|
747
765
|
const variableProducts = Array.from(parentProducts.values());
|
|
748
766
|
csvStream.setColumns(columns);
|
|
749
|
-
|
|
750
|
-
csvStream.addRow(
|
|
767
|
+
variableProducts.forEach((parentProduct) => {
|
|
768
|
+
csvStream.addRow(parentProduct);
|
|
769
|
+
variationsByParentId.get(parentProduct.ID)?.forEach((variationProduct) => {
|
|
770
|
+
csvStream.addRow(variationProduct);
|
|
771
|
+
});
|
|
751
772
|
});
|
|
752
773
|
csvStream.getWritableStream().end();
|
|
753
774
|
}
|
|
@@ -845,6 +866,11 @@ class YMLFormatter {
|
|
|
845
866
|
picture: product.images,
|
|
846
867
|
video: product.videos,
|
|
847
868
|
available: product.available,
|
|
869
|
+
"time-delivery": product.timeDelivery ? {
|
|
870
|
+
"@_min": product.timeDelivery.min,
|
|
871
|
+
"@_max": product.timeDelivery.max,
|
|
872
|
+
"#text": `${product.timeDelivery.min}-${product.timeDelivery.max}`
|
|
873
|
+
} : void 0,
|
|
848
874
|
series: product.seriesName,
|
|
849
875
|
"min-quantity": product.minQuantity,
|
|
850
876
|
"step-quantity": product.stepQuantity,
|