@hestia-earth/schema
Version:
Hestia Schema
29 lines (28 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.refToSchemaType = exports.typeToSchemaType = exports.isExpandable = exports.isBlankNode = exports.isTypeValid = exports.jsonldPath = exports.isNode = exports.isTypeNode = void 0;
var types_1 = require("../types");
exports.isTypeNode = function (type) { return Object.values(types_1.NodeType).includes(type); };
exports.isNode = function (_a) {
var type = _a.type;
return exports.isTypeNode(type);
};
exports.jsonldPath = function (type, id) { return type + "/" + id + ".jsonld"; };
exports.isTypeValid = function (_a) {
var type = _a.type;
return Object.values(types_1.SchemaType).includes(type);
};
exports.isBlankNode = function (node) {
var type = node['@type'] || node.type;
return exports.isTypeValid({ type: type }) && !exports.isTypeNode(type);
};
exports.isExpandable = function (val) { return !!val && !(val instanceof Date) && typeof val === 'object' && (Array.isArray(val) ? val.every(exports.isExpandable) : Object.values(types_1.SchemaType).includes(val.type || val['@type'])); };
exports.typeToSchemaType = function (type) {
return Object.values(types_1.SchemaType).find(function (val) { return val.toLowerCase() === (type || '').toLowerCase(); });
};
exports.refToSchemaType = function (ref) {
if (ref === void 0) { ref = ''; }
return ref ? (ref.startsWith('http') ?
ref :
exports.typeToSchemaType(ref.substring(2).replace('-deep', '').replace('.json#', ''))) : undefined;
};