n3 2.11.8 → 2.12.1
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/README.md +25 -0
- package/browser/n3.esm.min.js +9 -9
- package/browser/n3.min.js +8 -8
- package/lib/N3Lexer.js +45 -7
- package/lib/N3Parser.js +18 -4
- package/lib/N3StreamParser.js +4 -0
- package/lib/N3Writer.js +18 -3
- package/package.json +1 -1
- package/src/N3Lexer.js +53 -7
- package/src/N3Parser.js +20 -4
- package/src/N3StreamParser.js +2 -0
- package/src/N3Writer.js +21 -5
package/README.md
CHANGED
|
@@ -158,6 +158,20 @@ const quads = parser.parse('<a> <b> "hello"@en.', {
|
|
|
158
158
|
});
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
+
Packages that extend a format with their own directives can register their names with the `directives` option.
|
|
162
|
+
Between statements (outside graph blocks and formulas), a registered directive is accepted
|
|
163
|
+
as `@name .` in Turtle, TriG and N3, and as `NAME` (case-insensitive) in all formats, including N-Triples and N-Quads.
|
|
164
|
+
`onDirective(name)` receives each one in order with the quads, and `N3.StreamParser` emits them as `directive` events.
|
|
165
|
+
Names consist of letters only, and cannot be words that already have a meaning in the grammar, such as `prefix` or `a`.
|
|
166
|
+
|
|
167
|
+
```JavaScript
|
|
168
|
+
const parser = new N3.Parser({ format: 'N-Quads', directives: ['message'] });
|
|
169
|
+
parser.parse('<a> <b> <c> .\nMESSAGE\n<a> <b> <d> .\n', {
|
|
170
|
+
onQuad: (error, quad) => { /* … */ },
|
|
171
|
+
onDirective: name => { console.log('end of a message'); },
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
161
175
|
If no callbacks are provided, parsing happens synchronously returning an array of quads:
|
|
162
176
|
|
|
163
177
|
```JavaScript
|
|
@@ -573,6 +587,17 @@ Both budgets are unbounded by default;
|
|
|
573
587
|
`reason()` throws when one is exceeded,
|
|
574
588
|
leaving any quads derived up to that point in the store.
|
|
575
589
|
|
|
590
|
+
## Extensions
|
|
591
|
+
The following packages build on N3.js to support formats or features beyond the W3C specifications listed under [Compatibility](#compatibility).
|
|
592
|
+
They are maintained separately from N3.js; please report issues with them in their own repositories.
|
|
593
|
+
|
|
594
|
+
| Package | Description |
|
|
595
|
+
| ------- | ----------- |
|
|
596
|
+
| [n3.js-messages](https://www.npmjs.com/package/n3.js-messages) | Parses and writes [RDF Messages](https://w3c-cg.github.io/rsp/spec/messages) (message-delimited Turtle, TriG, N-Triples and N-Quads). |
|
|
597
|
+
| [@jeswr/n3-provenance](https://github.com/jeswr/n3-provenance) | Experimental. Maps the terms of parsed quads back to their source positions in the input document. Terms that the parser generates, such as list nodes and reification scaffolding, have no position. It builds on the parser's `onToken` and `onTokenEnd` callbacks, but also subclasses private parser and index internals, so it is pinned to a specific N3.js revision. |
|
|
598
|
+
|
|
599
|
+
To list a package here, open a pull request that adds a row to this table.
|
|
600
|
+
|
|
576
601
|
## Compatibility
|
|
577
602
|
### Format specifications
|
|
578
603
|
The N3.js parser and writer is fully compatible with the following W3C specifications:
|