n3 2.1.0 → 2.1.2
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.
- package/.babelrc +1 -1
- package/README.md +35 -0
- package/browser/n3.esm.min.js +6 -6
- package/browser/n3.min.js +1 -1
- package/lib/N3Lexer.js +8 -2
- package/lib/N3Store.js +3 -1
- package/lib/N3Writer.js +4 -2
- package/package.json +5 -5
- package/src/N3Lexer.js +11 -3
- package/src/N3Store.js +3 -1
- package/src/N3Writer.js +4 -2
package/lib/N3Lexer.js
CHANGED
|
@@ -242,8 +242,14 @@ class N3Lexer {
|
|
|
242
242
|
if (this._n3Mode && (match = this._variable.exec(input))) type = 'var', value = match[0];
|
|
243
243
|
break;
|
|
244
244
|
case '@':
|
|
245
|
-
// Try to find a language code
|
|
246
|
-
|
|
245
|
+
// Try to find a language code. A language code can contain dash-separated
|
|
246
|
+
// subtags, so if the match is immediately followed by a single dash and the
|
|
247
|
+
// input is not finished, another subtag may still arrive in a later chunk and
|
|
248
|
+
// the match would be premature; wait for more input in that case.
|
|
249
|
+
// A double dash starts a direction code, which cannot extend the language code.
|
|
250
|
+
if (this._previousMarker === 'literal' && (match = this._langcode.exec(input)) && match[1] !== 'version') {
|
|
251
|
+
if (!inputFinished && input[match[0].length] === '-' && input[match[0].length + 1] !== '-') match = null;else type = 'langcode', value = match[1];
|
|
252
|
+
}
|
|
247
253
|
// Try to find a keyword
|
|
248
254
|
else if (match = this._atKeyword.exec(input)) type = match[0];
|
|
249
255
|
break;
|
package/lib/N3Store.js
CHANGED
|
@@ -728,7 +728,9 @@ class N3Store {
|
|
|
728
728
|
remove = false,
|
|
729
729
|
ignoreErrors = false
|
|
730
730
|
} = {}) {
|
|
731
|
-
|
|
731
|
+
// Keys are the list heads' term values, so a null-prototype map keeps
|
|
732
|
+
// them from colliding with inherited Object members such as `toString`
|
|
733
|
+
const lists = Object.create(null);
|
|
732
734
|
const onError = ignoreErrors ? () => true : (node, message) => {
|
|
733
735
|
throw new Error(`${node.value} ${message}`);
|
|
734
736
|
};
|
package/lib/N3Writer.js
CHANGED
|
@@ -102,7 +102,9 @@ class N3Writer {
|
|
|
102
102
|
_writeQuad(subject, predicate, object, graph, done) {
|
|
103
103
|
try {
|
|
104
104
|
// Write the graph's label if it has changed
|
|
105
|
-
|
|
105
|
+
// (the id-based fast path of `equals` would conflate
|
|
106
|
+
// the empty named node `<>` with the default graph)
|
|
107
|
+
if (!graph.equals(this._graph) || graph.termType !== this._graph.termType) {
|
|
106
108
|
// Close the previous graph and start the new one
|
|
107
109
|
this._write((this._subject === null ? '' : this._inDefaultGraph ? '.\n' : '\n}\n') + (DEFAULTGRAPH.equals(graph) ? '' : `${this._encodeIriOrBlank(graph)} {\n`));
|
|
108
110
|
this._graph = graph;
|
|
@@ -131,7 +133,7 @@ class N3Writer {
|
|
|
131
133
|
|
|
132
134
|
// ### `quadToString` serializes a quad as a string
|
|
133
135
|
quadToString(subject, predicate, object, graph) {
|
|
134
|
-
return `${this._encodeSubject(subject)} ${this._encodeIriOrBlank(predicate)} ${this._encodeObject(object)}${graph && graph
|
|
136
|
+
return `${this._encodeSubject(subject)} ${this._encodeIriOrBlank(predicate)} ${this._encodeObject(object)}${graph && !(0, _N3Util.isDefaultGraph)(graph) ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`;
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
// ### `quadsToString` serializes an array of quads as a string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
|
|
5
5
|
"author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"readable-stream": "^4.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/cli": "^
|
|
32
|
-
"@babel/core": "^
|
|
33
|
-
"@babel/preset-env": "^
|
|
34
|
-
"@babel/register": "^
|
|
31
|
+
"@babel/cli": "^8.0.1",
|
|
32
|
+
"@babel/core": "^8.0.1",
|
|
33
|
+
"@babel/preset-env": "^8.0.2",
|
|
34
|
+
"@babel/register": "^8.0.1",
|
|
35
35
|
"@rdfjs/data-model": "^1",
|
|
36
36
|
"arrayify-stream": "^3.0.0",
|
|
37
37
|
"browserify": "^17.0.0",
|
package/src/N3Lexer.js
CHANGED
|
@@ -226,9 +226,17 @@ export default class N3Lexer {
|
|
|
226
226
|
break;
|
|
227
227
|
|
|
228
228
|
case '@':
|
|
229
|
-
// Try to find a language code
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
// Try to find a language code. A language code can contain dash-separated
|
|
230
|
+
// subtags, so if the match is immediately followed by a single dash and the
|
|
231
|
+
// input is not finished, another subtag may still arrive in a later chunk and
|
|
232
|
+
// the match would be premature; wait for more input in that case.
|
|
233
|
+
// A double dash starts a direction code, which cannot extend the language code.
|
|
234
|
+
if (this._previousMarker === 'literal' && (match = this._langcode.exec(input)) && match[1] !== 'version') {
|
|
235
|
+
if (!inputFinished && input[match[0].length] === '-' && input[match[0].length + 1] !== '-')
|
|
236
|
+
match = null;
|
|
237
|
+
else
|
|
238
|
+
type = 'langcode', value = match[1];
|
|
239
|
+
}
|
|
232
240
|
// Try to find a keyword
|
|
233
241
|
else if (match = this._atKeyword.exec(input))
|
|
234
242
|
type = match[0];
|
package/src/N3Store.js
CHANGED
|
@@ -759,7 +759,9 @@ export default class N3Store {
|
|
|
759
759
|
// ### `extractLists` finds and removes all list triples
|
|
760
760
|
// and returns the items per list.
|
|
761
761
|
extractLists({ remove = false, ignoreErrors = false } = {}) {
|
|
762
|
-
|
|
762
|
+
// Keys are the list heads' term values, so a null-prototype map keeps
|
|
763
|
+
// them from colliding with inherited Object members such as `toString`
|
|
764
|
+
const lists = Object.create(null);
|
|
763
765
|
const onError = ignoreErrors ? (() => true) :
|
|
764
766
|
((node, message) => { throw new Error(`${node.value} ${message}`); });
|
|
765
767
|
|
package/src/N3Writer.js
CHANGED
|
@@ -85,7 +85,9 @@ export default class N3Writer {
|
|
|
85
85
|
_writeQuad(subject, predicate, object, graph, done) {
|
|
86
86
|
try {
|
|
87
87
|
// Write the graph's label if it has changed
|
|
88
|
-
|
|
88
|
+
// (the id-based fast path of `equals` would conflate
|
|
89
|
+
// the empty named node `<>` with the default graph)
|
|
90
|
+
if (!graph.equals(this._graph) || graph.termType !== this._graph.termType) {
|
|
89
91
|
// Close the previous graph and start the new one
|
|
90
92
|
this._write((this._subject === null ? '' : (this._inDefaultGraph ? '.\n' : '\n}\n')) +
|
|
91
93
|
(DEFAULTGRAPH.equals(graph) ? '' : `${this._encodeIriOrBlank(graph)} {\n`));
|
|
@@ -125,7 +127,7 @@ export default class N3Writer {
|
|
|
125
127
|
return `${this._encodeSubject(subject)} ${
|
|
126
128
|
this._encodeIriOrBlank(predicate)} ${
|
|
127
129
|
this._encodeObject(object)
|
|
128
|
-
}${graph && graph
|
|
130
|
+
}${graph && !isDefaultGraph(graph) ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`;
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
// ### `quadsToString` serializes an array of quads as a string
|