@hestia-earth/schema-convert 30.2.1 → 30.3.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/csv-pivot.js +1 -5
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/package.json +1 -1
- package/utils.d.ts +2 -0
- package/utils.js +21 -1
package/csv-pivot.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toCsvPivot = exports.toCsv = void 0;
|
|
4
|
-
var json_2_csv_1 = require("json-2-csv");
|
|
5
4
|
var utils_1 = require("./utils");
|
|
6
5
|
var json_pivot_1 = require("./json-pivot");
|
|
7
6
|
var parseValue = function (value) {
|
|
@@ -16,13 +15,10 @@ var withType = function (nodes) {
|
|
|
16
15
|
};
|
|
17
16
|
var toCsv = function (nodes, keys, excludeKeys) {
|
|
18
17
|
if (excludeKeys === void 0) { excludeKeys = utils_1.omitKeys; }
|
|
19
|
-
return (0,
|
|
18
|
+
return (0, utils_1.jsonToCsv)(withType(nodes), {
|
|
20
19
|
keys: keys,
|
|
21
20
|
excludeKeys: excludeKeys,
|
|
22
21
|
emptyFieldValue: '-',
|
|
23
|
-
expandArrayObjects: true,
|
|
24
|
-
arrayIndexesAsKeys: true,
|
|
25
|
-
sortHeader: true,
|
|
26
22
|
parseValue: parseValue
|
|
27
23
|
});
|
|
28
24
|
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.pivotNodes = exports.pivotNode = exports.toCsvPivot = void 0;
|
|
17
|
+
exports.pivotNodes = exports.pivotNode = exports.toCsvPivot = exports.jsonToCsv = void 0;
|
|
18
|
+
var utils_1 = require("./utils");
|
|
19
|
+
Object.defineProperty(exports, "jsonToCsv", { enumerable: true, get: function () { return utils_1.jsonToCsv; } });
|
|
18
20
|
var csv_pivot_1 = require("./csv-pivot");
|
|
19
21
|
Object.defineProperty(exports, "toCsvPivot", { enumerable: true, get: function () { return csv_pivot_1.toCsvPivot; } });
|
|
20
22
|
var json_pivot_1 = require("./json-pivot");
|
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Json2CsvOptions } from 'json-2-csv';
|
|
1
2
|
export declare const omitKeys: string[];
|
|
2
3
|
export declare const parentKey: (key: string) => string;
|
|
3
4
|
export declare const childkey: (key: string) => string;
|
|
@@ -18,3 +19,4 @@ export declare const daysInYear: (year: number) => 366 | 365;
|
|
|
18
19
|
export declare const convertValue: (value: any) => any;
|
|
19
20
|
export declare const findDuplicates: (values: string[]) => string[];
|
|
20
21
|
export declare const findNonDuplicates: (values: string[]) => string[];
|
|
22
|
+
export declare const jsonToCsv: (values: Record<string, any>[], options?: Json2CsvOptions) => string;
|
package/utils.js
CHANGED
|
@@ -36,7 +36,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
36
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.findNonDuplicates = exports.findDuplicates = exports.convertValue = exports.daysInYear = exports.daysBefore = exports.diffInDays = exports.keyToLabel = exports.ellipsis = exports.reduceUndefinedValues = exports.nonEmptyNode = exports.nonEmptyValue = exports.isEmpty = exports.isNumber = exports.isBoolean = exports.isIri = exports.isExpandable = exports.omit = exports.childkey = exports.parentKey = exports.omitKeys = void 0;
|
|
39
|
+
exports.jsonToCsv = exports.findNonDuplicates = exports.findDuplicates = exports.convertValue = exports.daysInYear = exports.daysBefore = exports.diffInDays = exports.keyToLabel = exports.ellipsis = exports.reduceUndefinedValues = exports.nonEmptyNode = exports.nonEmptyValue = exports.isEmpty = exports.isNumber = exports.isBoolean = exports.isIri = exports.isExpandable = exports.omit = exports.childkey = exports.parentKey = exports.omitKeys = void 0;
|
|
40
|
+
var json_2_csv_1 = require("json-2-csv");
|
|
40
41
|
var get = require('lodash.get');
|
|
41
42
|
var unset = require('lodash.unset');
|
|
42
43
|
exports.omitKeys = __spreadArray([
|
|
@@ -161,3 +162,22 @@ var findDuplicates = function (values) { return duplicates(count(values)); };
|
|
|
161
162
|
exports.findDuplicates = findDuplicates;
|
|
162
163
|
var findNonDuplicates = function (values) { return nonDuplicates(count(values)); };
|
|
163
164
|
exports.findNonDuplicates = findNonDuplicates;
|
|
165
|
+
/**
|
|
166
|
+
* Move every item on the same row.
|
|
167
|
+
*
|
|
168
|
+
* @param data
|
|
169
|
+
* @returns List of original records with less gaps in data.
|
|
170
|
+
*/
|
|
171
|
+
var compactDataForCsv = function (data) {
|
|
172
|
+
return data.reduce(function (prev, curr) {
|
|
173
|
+
var _a = __read(Object.entries(curr), 1), _b = __read(_a[0], 2), key = _b[0], value = _b[1];
|
|
174
|
+
var prevNoKeyIndex = prev.findIndex(function (p) { return !Object.keys(p).includes(key); });
|
|
175
|
+
prevNoKeyIndex >= 0 ? (prev[prevNoKeyIndex][key] = value) : prev.push(curr);
|
|
176
|
+
return prev;
|
|
177
|
+
}, []);
|
|
178
|
+
};
|
|
179
|
+
var jsonToCsv = function (values, options) {
|
|
180
|
+
if (options === void 0) { options = {}; }
|
|
181
|
+
return (0, json_2_csv_1.json2csv)(compactDataForCsv(values), __assign({ emptyFieldValue: '', expandNestedObjects: true, expandArrayObjects: true, arrayIndexesAsKeys: true, sortHeader: true }, options));
|
|
182
|
+
};
|
|
183
|
+
exports.jsonToCsv = jsonToCsv;
|