microdata-rdf-streaming-parser
Version:
A fast and lightweight streaming Microdata to RDF parser
39 lines • 1.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ItemPropertyHandlerTime = void 0;
const Util_1 = require("../Util");
/**
* Handler for an item property for time tags.
*/
class ItemPropertyHandlerTime {
canHandle(tagName, attributes) {
return tagName === 'time' && 'datetime' in attributes;
}
getObject(attributes, util, itemScope) {
const value = attributes.datetime;
let datatype;
for (const entry of ItemPropertyHandlerTime.TIME_REGEXES) {
if (entry.regex.test(value)) {
datatype = util.dataFactory.namedNode(Util_1.Util.XSD + entry.type);
break;
}
}
return util.dataFactory.literal(value, datatype);
}
}
exports.ItemPropertyHandlerTime = ItemPropertyHandlerTime;
ItemPropertyHandlerTime.TIME_REGEXES = [
{
regex: /^-?P(\d+Y)?(\d+M)?(\d+D)?(T(\d+H)?(\d+M)?(\d+(\.\d)?S)?)?$/u,
type: 'duration',
},
{
regex: /^\d+-\d\d-\d\dT\d\d:\d\d:\d\d((Z?)|([+-]\d\d:\d\d))$/u,
type: 'dateTime',
},
{ regex: /^\d+-\d\d-\d\dZ?$/u, type: 'date' },
{ regex: /^\d\d:\d\d:\d\d((Z?)|([+-]\d\d:\d\d))$/u, type: 'time' },
{ regex: /^\d+-\d\d$/u, type: 'gYearMonth' },
{ regex: /^\d+$/u, type: 'gYear' },
];
//# sourceMappingURL=ItemPropertyHandlerTime.js.map