@hestia-earth/schema-convert
Advanced tools
Comparing version 15.2.0 to 16.0.0
166
json.js
@@ -85,3 +85,3 @@ "use strict"; | ||
}; | ||
var _a; | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -311,84 +311,88 @@ exports.toJson = exports.filterEmptyNode = exports.formatNode = exports.cleanStringValue = exports.throwCSVError = void 0; | ||
exports.cleanStringValue = cleanStringValue; | ||
var propertyTypeToValue = { | ||
null: function (value) { | ||
var args = []; | ||
for (var _a = 1; _a < arguments.length; _a++) { | ||
args[_a - 1] = arguments[_a]; | ||
var geojsonRef = 'http://json.schemastore.org/geojson'; | ||
var propertyTypeToValue = (_b = { | ||
null: function (value) { | ||
var args = []; | ||
for (var _a = 1; _a < arguments.length; _a++) { | ||
args[_a - 1] = arguments[_a]; | ||
} | ||
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spreadArray([value], __read(args), false)); | ||
}, | ||
string: function (value) { return (0, exports.cleanStringValue)(value || ''); }, | ||
number: function (value) { | ||
return isEmptyCell(value) | ||
? undefined | ||
: isNaN(+value) | ||
? (function () { | ||
throw new Error('failed to parse number'); | ||
})() | ||
: +value; | ||
}, | ||
integer: function (value) { return isEmptyCell(value) ? undefined : +value; }, | ||
boolean: function (value) { | ||
return isEmptyCell(value) | ||
? undefined | ||
: (0, utils_1.isBoolean)(value) | ||
? value.toLowerCase() === 'true' | ||
: (0, utils_1.isNumber)(value) | ||
? +value === 1 // handle setting 1 or 1.0 as true | ||
: (function () { | ||
throw new Error('failed to parse boolean, expected true or false'); | ||
})(); | ||
}, | ||
object: function (value, schemas, _a, _i) { | ||
var $ref = _a.$ref, required = _a.required; | ||
return $ref === geojsonRef | ||
? propertyTypeToValue[geojsonRef](value) | ||
: $ref | ||
? propertyTypeToValue.$ref(value, schemas, { $ref: $ref }, _i) | ||
: propertyTypeToValue.required(value, schemas, { required: required }, _i); | ||
}, | ||
array: function (value, schemas, _a, _i) { | ||
var items = _a.items; | ||
return (Array.isArray(value) ? value : value.split(arrayDelimiter())) | ||
.map(handleArrayError(function (val) { return items ? ('$ref' in items ? | ||
propertyTypeToValue.object(val, schemas, items, _i) : | ||
Array.isArray(items.type) ? | ||
propertyTypeToValue.auto(val, schemas, items, _i) : | ||
propertyTypeToValue[items.type](val, schemas, items, _i)) : val; })) | ||
.filter(function (val) { return !isEmptyValue(val, schemas); }); | ||
}, | ||
// try to determine the type automatically | ||
auto: function (value, schemas, _d, _i) { | ||
// iris are mapped as {@id: val} | ||
return (0, utils_1.isIri)(value) | ||
? propertyTypeToValue.required(value, schemas, { required: ['@id'] }, _i) | ||
: (0, utils_1.isBoolean)(value) | ||
? propertyTypeToValue.boolean(value) | ||
: (0, utils_1.isNumber)(value) | ||
? propertyTypeToValue.number(value) | ||
: value === 'null' | ||
? null | ||
: propertyTypeToValue.string(value); | ||
}, | ||
required: function (value, _schemas, _a) { | ||
var required = _a.required; | ||
var data = propertyRequiredValue(value, required); | ||
return (0, utils_1.isEmpty)(data) ? {} : data; | ||
}, | ||
$ref: function (value, schemas, _a, _i) { | ||
var $ref = _a.$ref; | ||
var schemaType = (0, schema_1.refToSchemaType)($ref); | ||
var schema = schemaType ? schemas[schemaType] : undefined; | ||
var data = schema | ||
? mapContent(schemas, schema, _i)(schemaRefValue(value, schemaType)) | ||
: $ref in propertyTypeToValue | ||
? propertyTypeToValue[$ref](value) | ||
: safeParseJSON(value); | ||
var includeDefaults = (0, schema_1.isBlankNode)(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed | ||
return (0, utils_1.isEmpty)(data) | ||
? {} | ||
: !!schema | ||
? extendDataFromSchema(data, schema, schemaType, _i, includeDefaults) | ||
: data; | ||
} | ||
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spreadArray([value], __read(args), false)); | ||
}, | ||
string: function (value) { return (0, exports.cleanStringValue)(value || ''); }, | ||
number: function (value) { | ||
return isEmptyCell(value) | ||
? undefined | ||
: isNaN(+value) | ||
? (function () { | ||
throw new Error('failed to parse number'); | ||
})() | ||
: +value; | ||
}, | ||
integer: function (value) { return isEmptyCell(value) ? undefined : +value; }, | ||
boolean: function (value) { | ||
return isEmptyCell(value) | ||
? undefined | ||
: (0, utils_1.isBoolean)(value) | ||
? value.toLowerCase() === 'true' | ||
: (0, utils_1.isNumber)(value) | ||
? +value === 1 // handle setting 1 or 1.0 as true | ||
: (function () { | ||
throw new Error('failed to parse boolean, expected true or false'); | ||
})(); | ||
}, | ||
object: function (value, schemas, _a, _i) { | ||
var $ref = _a.$ref, required = _a.required; | ||
return $ref ? | ||
propertyTypeToValue.$ref(value, schemas, { $ref: $ref }, _i) : | ||
propertyTypeToValue.required(value, schemas, { required: required }, _i); | ||
}, | ||
array: function (value, schemas, _a, _i) { | ||
var items = _a.items; | ||
return (Array.isArray(value) ? value : value.split(arrayDelimiter())) | ||
.map(handleArrayError(function (val) { return items ? ('$ref' in items ? | ||
propertyTypeToValue.object(val, schemas, items, _i) : | ||
Array.isArray(items.type) ? | ||
propertyTypeToValue.auto(val, schemas, items, _i) : | ||
propertyTypeToValue[items.type](val, schemas, items, _i)) : val; })) | ||
.filter(function (val) { return !isEmptyValue(val, schemas); }); | ||
}, | ||
// try to determine the type automatically | ||
auto: function (value, schemas, _d, _i) { | ||
// iris are mapped as {@id: val} | ||
return (0, utils_1.isIri)(value) | ||
? propertyTypeToValue.required(value, schemas, { required: ['@id'] }, _i) | ||
: (0, utils_1.isBoolean)(value) | ||
? propertyTypeToValue.boolean(value) | ||
: (0, utils_1.isNumber)(value) | ||
? propertyTypeToValue.number(value) | ||
: value === 'null' | ||
? null | ||
: propertyTypeToValue.string(value); | ||
}, | ||
required: function (value, _schemas, _a) { | ||
var required = _a.required; | ||
var data = propertyRequiredValue(value, required); | ||
return (0, utils_1.isEmpty)(data) ? {} : data; | ||
}, | ||
$ref: function (value, schemas, _a, _i) { | ||
var $ref = _a.$ref; | ||
var schemaType = (0, schema_1.refToSchemaType)($ref); | ||
var schema = schemaType ? schemas[schemaType] : undefined; | ||
var data = schema | ||
? mapContent(schemas, schema, _i)(schemaRefValue(value, schemaType)) | ||
: $ref in propertyTypeToValue | ||
? propertyTypeToValue[$ref](value) | ||
: safeParseJSON(value); | ||
var includeDefaults = (0, schema_1.isBlankNode)(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed | ||
return (0, utils_1.isEmpty)(data) | ||
? {} | ||
: !!schema | ||
? extendDataFromSchema(data, schema, schemaType, _i, includeDefaults) | ||
: data; | ||
}, | ||
'http://json.schemastore.org/geojson': function (value) { return isEmptyCell(value) ? undefined : parseGeoJSONValue(value); } | ||
}; | ||
_b[geojsonRef] = function (value) { return isEmptyCell(value) ? undefined : parseGeoJSONValue(value); }, | ||
_b); | ||
var getPropertyDefinition = function (schema, key, ignoreErrors, value) { | ||
@@ -395,0 +399,0 @@ if (ignoreErrors === void 0) { ignoreErrors = false; } |
{ | ||
"name": "@hestia-earth/schema-convert", | ||
"version": "15.2.0", | ||
"version": "16.0.0", | ||
"description": "Hestia Schema Converters", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64422
1344