n3 2.7.5 → 2.7.7

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/lib/N3Lexer.js CHANGED
@@ -464,6 +464,7 @@ class N3Lexer {
464
464
  // ### `_unescape` replaces N3 escape codes by their corresponding characters,
465
465
  // allowing only the fixed escape sequences from the given replacement table
466
466
  _unescape(item, replacements) {
467
+ if (item.indexOf('\\') < 0) return item;
467
468
  let invalid = false;
468
469
  const replaced = item.replace(escapeSequence, (sequence, unicode4, unicode8, escapedChar) => {
469
470
  // 4-digit unicode character
@@ -13,9 +13,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
13
13
  class N3StreamParser extends _readableStream.Transform {
14
14
  constructor(options) {
15
15
  super({
16
- decodeStrings: true
16
+ decodeStrings: true,
17
+ readableObjectMode: true
17
18
  });
18
- this._readableState.objectMode = true;
19
19
 
20
20
  // Set up parser with dummy stream to obtain `data` and `end` callbacks
21
21
  const parser = new _N3Parser.default(options);
@@ -59,15 +59,17 @@ class N3StreamParser extends _readableStream.Transform {
59
59
 
60
60
  // ### Parses a stream of strings
61
61
  import(stream) {
62
- stream.on('data', chunk => {
63
- this.write(chunk);
64
- });
65
- stream.on('end', () => {
66
- this.end();
67
- });
68
62
  stream.on('error', error => {
69
63
  this.emit('error', error);
70
64
  });
65
+ if (typeof stream.pipe === 'function') stream.pipe(this);else {
66
+ stream.on('data', chunk => {
67
+ this.write(chunk);
68
+ });
69
+ stream.on('end', () => {
70
+ this.end();
71
+ });
72
+ }
71
73
  return this;
72
74
  }
73
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.7.5",
3
+ "version": "2.7.7",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Lexer.js CHANGED
@@ -485,6 +485,8 @@ export default class N3Lexer {
485
485
  // ### `_unescape` replaces N3 escape codes by their corresponding characters,
486
486
  // allowing only the fixed escape sequences from the given replacement table
487
487
  _unescape(item, replacements) {
488
+ if (item.indexOf('\\') < 0)
489
+ return item;
488
490
  let invalid = false;
489
491
  const replaced = item.replace(escapeSequence, (sequence, unicode4, unicode8, escapedChar) => {
490
492
  // 4-digit unicode character
@@ -5,8 +5,7 @@ import N3Parser from './N3Parser';
5
5
  // ## Constructor
6
6
  export default class N3StreamParser extends Transform {
7
7
  constructor(options) {
8
- super({ decodeStrings: true });
9
- this._readableState.objectMode = true;
8
+ super({ decodeStrings: true, readableObjectMode: true });
10
9
 
11
10
  // Set up parser with dummy stream to obtain `data` and `end` callbacks
12
11
  const parser = new N3Parser(options);
@@ -38,9 +37,13 @@ export default class N3StreamParser extends Transform {
38
37
 
39
38
  // ### Parses a stream of strings
40
39
  import(stream) {
41
- stream.on('data', chunk => { this.write(chunk); });
42
- stream.on('end', () => { this.end(); });
43
40
  stream.on('error', error => { this.emit('error', error); });
41
+ if (typeof stream.pipe === 'function')
42
+ stream.pipe(this);
43
+ else {
44
+ stream.on('data', chunk => { this.write(chunk); });
45
+ stream.on('end', () => { this.end(); });
46
+ }
44
47
  return this;
45
48
  }
46
49
  }