@hestia-earth/schema-convert 7.8.0 → 7.9.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.
Files changed (2) hide show
  1. package/json.js +24 -10
  2. package/package.json +1 -1
package/json.js CHANGED
@@ -151,8 +151,9 @@ var parseError = function (err) { return safeParseJSON(err.message); };
151
151
  exports.throwCSVError = function (error) {
152
152
  throw new Error(JSON.stringify(error));
153
153
  };
154
- var schemaNotFoundError = function () { return exports.throwCSVError({
155
- message: 'schema-not-found'
154
+ var schemaNotFoundError = function (schema) { return exports.throwCSVError({
155
+ message: 'schema-not-found',
156
+ schema: schema
156
157
  }); };
157
158
  var propertyNotFoundError = function (schema, key, value) { return exports.throwCSVError({
158
159
  schema: schema.title,
@@ -219,7 +220,15 @@ var propertyTypeToValue = {
219
220
  })() : +value;
220
221
  },
221
222
  integer: function (value) { return isEmptyCell(value) ? undefined : +value; },
222
- boolean: function (value) { return isEmptyCell(value) ? undefined : value.toLowerCase() === 'true'; },
223
+ boolean: function (value) {
224
+ return isEmptyCell(value) ?
225
+ undefined :
226
+ utils_1.isBoolean(value) ?
227
+ value.toLowerCase() === 'true' :
228
+ (function () {
229
+ throw new Error('failed to parse boolean, expected true or false');
230
+ })();
231
+ },
223
232
  object: function (value, schemas, _a, _i) {
224
233
  var $ref = _a.$ref, required = _a.required;
225
234
  return $ref ?
@@ -325,7 +334,7 @@ var mapContent = function (schemas, schema, ignoreInternal) { return function (j
325
334
  }; };
326
335
  exports.formatNode = function (schemas, type, data, ignoreInternal, top) {
327
336
  if (top === void 0) { top = false; }
328
- var schema = type in schemas ? schemas[type] : schemaNotFoundError();
337
+ var schema = type in schemas ? schemas[type] : schemaNotFoundError(type);
329
338
  var content = mapContent(schemas, schema, ignoreInternal)(data);
330
339
  return utils_1.reduceUndefinedValues(__assign({ id: isEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal, top)), true);
331
340
  };
@@ -347,9 +356,14 @@ var convetToNode = function (schemas) { return function (data) {
347
356
  * @param content The content of the CSV as a string
348
357
  * @returns A list of JSON-LD content.
349
358
  */
350
- exports.toJson = function (schemas, content) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
351
- switch (_a.label) {
352
- case 0: return [4 /*yield*/, csvtojson({ delimiter: 'auto' }).fromString(content)];
353
- case 1: return [2 /*return*/, (_a.sent()).flatMap(convetToNode(schemas))];
354
- }
355
- }); }); };
359
+ exports.toJson = function (schemas, content) { return __awaiter(void 0, void 0, void 0, function () {
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0: return [4 /*yield*/, csvtojson({
363
+ delimiter: 'auto',
364
+ ignoreColumns: /^$/
365
+ }).fromString(content)];
366
+ case 1: return [2 /*return*/, (_a.sent()).flatMap(convetToNode(schemas))];
367
+ }
368
+ });
369
+ }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "7.8.0",
3
+ "version": "7.9.0",
4
4
  "description": "Hestia Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",