@hestia-earth/schema-convert 26.6.0 → 27.0.0
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/convert-csv.js +7 -16
- package/csv-pivot.d.ts +2 -2
- package/csv-pivot.js +2 -1
- package/package.json +2 -2
package/convert-csv.js
CHANGED
|
@@ -72,28 +72,19 @@ var listFiles = function (folder) { return __awaiter(void 0, void 0, void 0, fun
|
|
|
72
72
|
});
|
|
73
73
|
}); };
|
|
74
74
|
var processFile = function (filepath, pivot) { return __awaiter(void 0, void 0, void 0, function () {
|
|
75
|
-
var data, content, nodes, res,
|
|
76
|
-
return __generator(this, function (
|
|
77
|
-
switch (
|
|
75
|
+
var data, content, nodes, res, destPath;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
78
|
case 0: return [4 /*yield*/, readFile(filepath, encoding)];
|
|
79
79
|
case 1:
|
|
80
|
-
data =
|
|
80
|
+
data = _a.sent();
|
|
81
81
|
content = JSON.parse(data.trim());
|
|
82
82
|
nodes = Array.isArray(content) ? content : 'nodes' in content ? content.nodes : [content];
|
|
83
|
-
|
|
84
|
-
return [4 /*yield*/, (0, csv_pivot_1.toCsvPivot)(nodes)];
|
|
85
|
-
case 2:
|
|
86
|
-
_a = _b.sent();
|
|
87
|
-
return [3 /*break*/, 4];
|
|
88
|
-
case 3:
|
|
89
|
-
_a = (0, csv_1.toCsv)(nodes);
|
|
90
|
-
_b.label = 4;
|
|
91
|
-
case 4:
|
|
92
|
-
res = _a;
|
|
83
|
+
res = pivot ? (0, csv_pivot_1.toCsvPivot)(nodes) : (0, csv_1.toCsv)(nodes);
|
|
93
84
|
destPath = filepath.replace('.jsonld', '.csv').replace('.json', '.csv');
|
|
94
85
|
return [4 /*yield*/, writeFile(destPath, res, encoding)];
|
|
95
|
-
case
|
|
96
|
-
|
|
86
|
+
case 2:
|
|
87
|
+
_a.sent();
|
|
97
88
|
return [2 /*return*/, destPath];
|
|
98
89
|
}
|
|
99
90
|
});
|
package/csv-pivot.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const toCsv: (nodes: any[], keys?: string[], excludeKeys?: string[]) =>
|
|
1
|
+
export declare const toCsv: (nodes: any[], keys?: string[], excludeKeys?: string[]) => string;
|
|
2
2
|
export declare const pivotNode: (node: any) => Partial<any>;
|
|
3
3
|
/**
|
|
4
4
|
* CSV format for data processing.
|
|
@@ -6,4 +6,4 @@ export declare const pivotNode: (node: any) => Partial<any>;
|
|
|
6
6
|
* @param nodes List of nodes to convert.
|
|
7
7
|
* @returns CSV content formatted with pivoted blank nodes.
|
|
8
8
|
*/
|
|
9
|
-
export declare const toCsvPivot: (nodes: any[]) =>
|
|
9
|
+
export declare const toCsvPivot: (nodes: any[]) => string;
|
package/csv-pivot.js
CHANGED
|
@@ -57,11 +57,12 @@ var parseValue = function (value) {
|
|
|
57
57
|
};
|
|
58
58
|
var toCsv = function (nodes, keys, excludeKeys) {
|
|
59
59
|
if (excludeKeys === void 0) { excludeKeys = omitKeys; }
|
|
60
|
-
return (0, json_2_csv_1.
|
|
60
|
+
return (0, json_2_csv_1.json2csv)(nodes, {
|
|
61
61
|
keys: keys,
|
|
62
62
|
excludeKeys: excludeKeys,
|
|
63
63
|
emptyFieldValue: '-',
|
|
64
64
|
expandArrayObjects: true,
|
|
65
|
+
arrayIndexesAsKeys: true,
|
|
65
66
|
sortHeader: true,
|
|
66
67
|
parseValue: parseValue
|
|
67
68
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hestia-earth/schema-convert",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "27.0.0",
|
|
4
4
|
"description": "Hestia Schema Converters",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@terraformer/wkt": "^2.1.1",
|
|
32
32
|
"csvtojson": "^2.0.0",
|
|
33
33
|
"fast-levenshtein": "^3.0.0",
|
|
34
|
-
"json-2-csv": "^
|
|
34
|
+
"json-2-csv": "^5.4.0",
|
|
35
35
|
"lodash.get": "^4.0.0",
|
|
36
36
|
"lodash.unset": "^4.0.0"
|
|
37
37
|
}
|