-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.js
35 lines (30 loc) · 922 Bytes
/
validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Parser } from "n3";
export function validate(turtleStream, callBack) {
const parser = new Parser({ format: "text/turtle" });
let feedback = { warnings: [], errors: [] };
parser.parse(turtleStream, function (error, triple, prefixes) {
if (error) {
feedback.errors.push(error.message);
}
if (triple) {
if (triple.object.termType === "literal") {
let value = triple.object.value;
let type = triple.object.datatype;
type = type.replace("http://www.w3.org/2001/XMLSchema#", "");
if (regexp[type] && !regexp[type].test(value)) {
feedback.warnings.push(
"xsd:",
type,
"does not validate for literal. {",
triple.subject.value,
triple.predicate.value,
triple.object.value,
"}"
);
}
}
} else {
callBack(feedback);
}
});
}