n3 2.13.9 → 2.13.11

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.
@@ -137,10 +137,10 @@ class Literal extends Term {
137
137
 
138
138
  // ### The direction of this literal
139
139
  get direction() {
140
- // Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
140
+ // Find the last double dash after the closing quote and language tag (e.g., '"abc"@en-us--ltr')
141
141
  const id = this.id;
142
142
  const endPos = id.lastIndexOf('"');
143
- const dirPos = id.lastIndexOf('--');
143
+ const dirPos = id[endPos + 1] === '@' ? id.lastIndexOf('--') : -1;
144
144
  return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
145
145
  }
146
146
 
package/lib/N3Store.js CHANGED
@@ -37,8 +37,11 @@ function hasInIndex(index0, key0, key1, key2) {
37
37
  // that starts with such a marker (as relative IRIs can) is wrapped in < and >.
38
38
  const markedIRI = /^[?_"[.<]/;
39
39
  function entityKey(term) {
40
- // Strings are term ids, which only need wrapping when they are IRIs starting with <
41
- if (typeof term === 'string') return term.charCodeAt(0) !== 0x3C || term === '<>' ? term : `<${term}>`;
40
+ // Strings are term ids, which only need wrapping when they are IRIs starting with < or .
41
+ if (typeof term === 'string') {
42
+ const first = term.charCodeAt(0);
43
+ return first !== 0x3C && first !== 0x2E || term === '<>' ? term : `<${term}>`;
44
+ }
42
45
  // IDs of IRIs usually start with a lowercase scheme letter, which never marks a term type
43
46
  const id = (0, _N3DataFactory.termToId)(term);
44
47
  if (id.charCodeAt(0) >= 0x61 || !term) return id;
@@ -97,10 +100,12 @@ class N3EntityIndex {
97
100
 
98
101
  // Returns the numeric id of a term given as a string id
99
102
  _stringToNumericId(term) {
100
- // The string is the key unless it is an IRI starting with <. Read the first character
103
+ // The string is the key unless it is an IRI starting with < (which starts the keys of
104
+ // wrapped IRIs) or . (which starts the keys of quoted triples). Read the first character
101
105
  // from the stored key after a match, which is cheaper than from a concatenated string.
102
106
  const id = this._ids[term];
103
- if (id ? this._entities[id].charCodeAt(0) !== 0x3C : term.charCodeAt(0) !== 0x3C) return id;
107
+ const first = id ? this._entities[id].charCodeAt(0) : term.charCodeAt(0);
108
+ if (first !== 0x3C && first !== 0x2E) return id;
104
109
  return term === '<>' ? id : this._ids[`<${term}>`];
105
110
  }
106
111
  _termToNewNumericId(term) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.13.9",
3
+ "version": "2.13.11",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -125,10 +125,10 @@ export class Literal extends Term {
125
125
 
126
126
  // ### The direction of this literal
127
127
  get direction() {
128
- // Find the last double dash after the closing quote (e.g., '"abc"@en-us--ltr')
128
+ // Find the last double dash after the closing quote and language tag (e.g., '"abc"@en-us--ltr')
129
129
  const id = this.id;
130
130
  const endPos = id.lastIndexOf('"');
131
- const dirPos = id.lastIndexOf('--');
131
+ const dirPos = id[endPos + 1] === '@' ? id.lastIndexOf('--') : -1;
132
132
  return dirPos > endPos && dirPos + 2 < id.length ? id.substr(dirPos + 2).toLowerCase() : '';
133
133
  }
134
134
 
package/src/N3Store.js CHANGED
@@ -28,9 +28,11 @@ function hasInIndex(index0, key0, key1, key2) {
28
28
  // that starts with such a marker (as relative IRIs can) is wrapped in < and >.
29
29
  const markedIRI = /^[?_"[.<]/;
30
30
  function entityKey(term) {
31
- // Strings are term ids, which only need wrapping when they are IRIs starting with <
32
- if (typeof term === 'string')
33
- return term.charCodeAt(0) !== 0x3C || term === '<>' ? term : `<${term}>`;
31
+ // Strings are term ids, which only need wrapping when they are IRIs starting with < or .
32
+ if (typeof term === 'string') {
33
+ const first = term.charCodeAt(0);
34
+ return first !== 0x3C && first !== 0x2E || term === '<>' ? term : `<${term}>`;
35
+ }
34
36
  // IDs of IRIs usually start with a lowercase scheme letter, which never marks a term type
35
37
  const id = termToId(term);
36
38
  if (id.charCodeAt(0) >= 0x61 || !term)
@@ -102,10 +104,12 @@ export class N3EntityIndex {
102
104
 
103
105
  // Returns the numeric id of a term given as a string id
104
106
  _stringToNumericId(term) {
105
- // The string is the key unless it is an IRI starting with <. Read the first character
107
+ // The string is the key unless it is an IRI starting with < (which starts the keys of
108
+ // wrapped IRIs) or . (which starts the keys of quoted triples). Read the first character
106
109
  // from the stored key after a match, which is cheaper than from a concatenated string.
107
110
  const id = this._ids[term];
108
- if (id ? this._entities[id].charCodeAt(0) !== 0x3C : term.charCodeAt(0) !== 0x3C)
111
+ const first = id ? this._entities[id].charCodeAt(0) : term.charCodeAt(0);
112
+ if (first !== 0x3C && first !== 0x2E)
109
113
  return id;
110
114
  return term === '<>' ? id : this._ids[`<${term}>`];
111
115
  }