n3 3.0.0-alpha.2 → 3.0.0-alpha.4

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/N3Parser.js CHANGED
@@ -61,8 +61,8 @@ class N3Parser {
61
61
  });
62
62
  // Disable explicit quantifiers by default
63
63
  this._explicitQuantifiers = !!options.explicitQuantifiers;
64
- // Disable formula-only blank node scoping by default
65
- this._formulaScopedBlankNodes = !!options.formulaScopedBlankNodes;
64
+ // Scope blank node labels to formulas only, unless explicitly disabled
65
+ this._formulaScopedBlankNodes = options.formulaScopedBlankNodes !== false;
66
66
  // Disable parsing of unsupported versions by default
67
67
  this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
68
68
  this._version = options.version;
package/lib/N3Writer.js CHANGED
@@ -79,7 +79,7 @@ class N3Writer {
79
79
  this._prefixIRIs = Object.create(null);
80
80
  if (options.baseIRI) {
81
81
  this._baseIri = new _BaseIRI.default(options.baseIRI);
82
- if (options.writeBase) this._write(`@base <${options.baseIRI}>.\n`);
82
+ if (options.writeBase !== false) this._write(`@base <${options.baseIRI}>.\n`);
83
83
  }
84
84
  options.prefixes && this.addPrefixes(options.prefixes);
85
85
  } else {
@@ -177,7 +177,7 @@ class N3Writer {
177
177
  if (escape.test(iri)) iri = iri.replace(escapeAll, characterReplacer);
178
178
  // Try to represent the IRI as prefixed name, unless no prefixes were added
179
179
  const prefixMatch = this._hasPrefixes ? this._prefixRegex.exec(iri) : null;
180
- return !prefixMatch ? `<${iri}>` : !prefixMatch[1] ? iri : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2];
180
+ return !prefixMatch ? `<${iri}>` : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2];
181
181
  }
182
182
 
183
183
  // ### `_encodeLiteral` represents a literal
@@ -307,14 +307,10 @@ class N3Writer {
307
307
  // Recreate the prefix matcher
308
308
  if (hasPrefixes) {
309
309
  this._hasPrefixes = true;
310
- let IRIlist = '',
311
- prefixList = '';
312
- for (const prefixIRI in this._prefixIRIs) {
313
- IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI;
314
- prefixList += (prefixList ? '|' : '') + this._prefixIRIs[prefixIRI];
315
- }
310
+ let IRIlist = '';
311
+ for (const prefixIRI in this._prefixIRIs) IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI;
316
312
  IRIlist = (0, _Util.escapeRegex)(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
317
- this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` + `^(${IRIlist})([_a-zA-Z0-9](?:\\.?[\\-_a-zA-Z0-9])*)$`);
313
+ this._prefixRegex = new RegExp(`^(${IRIlist})([_a-zA-Z0-9](?:\\.?[\\-_a-zA-Z0-9])*)$`);
318
314
  }
319
315
  // End a prefix block with a newline
320
316
  this._write(hasPrefixes ? '\n' : '', done);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.4",
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/N3Parser.js CHANGED
@@ -50,8 +50,8 @@ export default class N3Parser {
50
50
  this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: this._isImpliedBy });
51
51
  // Disable explicit quantifiers by default
52
52
  this._explicitQuantifiers = !!options.explicitQuantifiers;
53
- // Disable formula-only blank node scoping by default
54
- this._formulaScopedBlankNodes = !!options.formulaScopedBlankNodes;
53
+ // Scope blank node labels to formulas only, unless explicitly disabled
54
+ this._formulaScopedBlankNodes = options.formulaScopedBlankNodes !== false;
55
55
  // Disable parsing of unsupported versions by default
56
56
  this._parseUnsupportedVersions = !!options.parseUnsupportedVersions;
57
57
  this._version = options.version;
package/src/N3Writer.js CHANGED
@@ -61,7 +61,7 @@ export default class N3Writer {
61
61
  this._prefixIRIs = Object.create(null);
62
62
  if (options.baseIRI) {
63
63
  this._baseIri = new BaseIRI(options.baseIRI);
64
- if (options.writeBase)
64
+ if (options.writeBase !== false)
65
65
  this._write(`@base <${options.baseIRI}>.\n`);
66
66
  }
67
67
  options.prefixes && this.addPrefixes(options.prefixes);
@@ -178,8 +178,7 @@ export default class N3Writer {
178
178
  iri = iri.replace(escapeAll, characterReplacer);
179
179
  // Try to represent the IRI as prefixed name, unless no prefixes were added
180
180
  const prefixMatch = this._hasPrefixes ? this._prefixRegex.exec(iri) : null;
181
- return !prefixMatch ? `<${iri}>` :
182
- (!prefixMatch[1] ? iri : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2]);
181
+ return !prefixMatch ? `<${iri}>` : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2];
183
182
  }
184
183
 
185
184
  // ### `_encodeLiteral` represents a literal
@@ -321,14 +320,11 @@ export default class N3Writer {
321
320
  // Recreate the prefix matcher
322
321
  if (hasPrefixes) {
323
322
  this._hasPrefixes = true;
324
- let IRIlist = '', prefixList = '';
325
- for (const prefixIRI in this._prefixIRIs) {
323
+ let IRIlist = '';
324
+ for (const prefixIRI in this._prefixIRIs)
326
325
  IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI;
327
- prefixList += (prefixList ? '|' : '') + this._prefixIRIs[prefixIRI];
328
- }
329
326
  IRIlist = escapeRegex(IRIlist, /[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&');
330
- this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` +
331
- `^(${IRIlist})([_a-zA-Z0-9](?:\\.?[\\-_a-zA-Z0-9])*)$`);
327
+ this._prefixRegex = new RegExp(`^(${IRIlist})([_a-zA-Z0-9](?:\\.?[\\-_a-zA-Z0-9])*)$`);
332
328
  }
333
329
  // End a prefix block with a newline
334
330
  this._write(hasPrefixes ? '\n' : '', done);