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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  presets: [
3
- "@babel/env",
3
+ ["@babel/env", { modules: "commonjs" }],
4
4
  ],
5
5
  }
package/README.md CHANGED
@@ -204,6 +204,41 @@ function SlowConsumer() {
204
204
  A dedicated `prefix` event signals every prefix with `prefix` and `term` arguments.
205
205
  A dedicated `comment` event can be enabled by setting `comments: true` in the N3.StreamParser constructor.
206
206
 
207
+ Note that `prefix` and `comment` events are emitted as soon as they are parsed,
208
+ whereas quads can remain buffered until the consumer is ready to read them.
209
+ The order of these events relative to `data` events is therefore
210
+ not guaranteed to match the position of prefixes and comments in the document.
211
+ If their position matters,
212
+ use `N3.Parser` with the `onQuad`, `onPrefix` and `onComment` callbacks instead,
213
+ which are invoked in document order.
214
+
215
+ ### From a Web Stream to quads
216
+
217
+ N3.js consumes [Node.js streams](http://nodejs.org/api/stream.html) natively,
218
+ but sources such as `fetch` produce [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API).
219
+ On Node.js 17 or higher, convert such a stream into a Node.js stream:
220
+
221
+ ```JavaScript
222
+ const streamParser = new N3.StreamParser(),
223
+ { Readable } = require('stream');
224
+ Readable.fromWeb(response.body).pipe(streamParser);
225
+ ```
226
+
227
+ In browsers (or anywhere without Node.js streams),
228
+ write the chunks to the parser directly,
229
+ since `N3.StreamParser` exposes a standard writable stream interface:
230
+
231
+ ```JavaScript
232
+ const streamParser = new N3.StreamParser(),
233
+ reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
234
+ (async () => {
235
+ for (let result; !(result = await reader.read()).done;)
236
+ if (!streamParser.write(result.value))
237
+ await new Promise(resolve => streamParser.once('drain', resolve));
238
+ streamParser.end();
239
+ })();
240
+ ```
241
+
207
242
  ## Writing
208
243
 
209
244
  ### From quads to a string