eyeling 1.26.0 → 1.26.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.
@@ -32,20 +32,20 @@ function emptyParsedDocument() {
32
32
  }
33
33
 
34
34
  function lineStartsForText(text) {
35
- const s = String(text);
36
35
  const starts = [0];
37
- for (let i = 0; i < s.length; i++) {
38
- const c = s.charCodeAt(i);
39
- if (c === 10) starts.push(i + 1); // LF
40
- else if (c === 13) { // CR or CRLF
41
- if (i + 1 < s.length && s.charCodeAt(i + 1) === 10) i++;
42
- starts.push(i + 1);
36
+ const str = String(text);
37
+ for (let i = 0; i < str.length; i++) {
38
+ const c = str[i];
39
+ if (c === '\n') starts.push(i + 1);
40
+ else if (c === '\r') {
41
+ starts.push(i + 1 < str.length && str[i + 1] === '\n' ? i + 2 : i + 1);
42
+ if (i + 1 < str.length && str[i + 1] === '\n') i++;
43
43
  }
44
44
  }
45
45
  return starts;
46
46
  }
47
47
 
48
- function offsetToLineFromStarts(offset, lineStarts) {
48
+ function offsetToLine(lineStarts, offset) {
49
49
  if (typeof offset !== 'number') return null;
50
50
  let lo = 0;
51
51
  let hi = lineStarts.length;
@@ -57,9 +57,9 @@ function offsetToLineFromStarts(offset, lineStarts) {
57
57
  return lo + 1;
58
58
  }
59
59
 
60
- function annotateSourceLocation(obj, label, lineStarts) {
60
+ function annotateSourceLocation(obj, lineStarts, label) {
61
61
  if (!obj || typeof obj.__sourceOffset !== 'number') return obj;
62
- const line = offsetToLineFromStarts(obj.__sourceOffset, lineStarts);
62
+ const line = offsetToLine(lineStarts, obj.__sourceOffset);
63
63
  Object.defineProperty(obj, '__source', {
64
64
  value: { label, line },
65
65
  enumerable: false,
@@ -71,10 +71,10 @@ function annotateSourceLocation(obj, label, lineStarts) {
71
71
 
72
72
  function annotateParsedSourceLocations(doc, text, label) {
73
73
  const lineStarts = lineStartsForText(text);
74
- for (const tr of doc.triples || []) annotateSourceLocation(tr, label, lineStarts);
75
- for (const r of doc.frules || []) annotateSourceLocation(r, label, lineStarts);
76
- for (const r of doc.brules || []) annotateSourceLocation(r, label, lineStarts);
77
- for (const r of doc.logQueryRules || []) annotateSourceLocation(r, label, lineStarts);
74
+ for (const tr of doc.triples || []) annotateSourceLocation(tr, lineStarts, label);
75
+ for (const r of doc.frules || []) annotateSourceLocation(r, lineStarts, label);
76
+ for (const r of doc.brules || []) annotateSourceLocation(r, lineStarts, label);
77
+ for (const r of doc.logQueryRules || []) annotateSourceLocation(r, lineStarts, label);
78
78
  }
79
79
 
80
80
  function copySourceMetadata(from, to) {
@@ -169,7 +169,7 @@ function parseN3Text(text, opts = {}) {
169
169
  label = '<input>',
170
170
  keepSourceArtifacts = true,
171
171
  collectUsedPrefixes = false,
172
- collectSourceLocations = true,
172
+ sourceLocations = false,
173
173
  rdf = false,
174
174
  } = opts || {};
175
175
  const tokens = lex(text, { rdf });
@@ -178,7 +178,7 @@ function parseN3Text(text, opts = {}) {
178
178
  const [prefixes, triples, frules, brules, logQueryRules] = parser.parseDocument();
179
179
 
180
180
  const doc = { prefixes, triples, frules, brules, logQueryRules, label };
181
- if (collectSourceLocations) annotateParsedSourceLocations(doc, text, label);
181
+ if (sourceLocations) annotateParsedSourceLocations(doc, text, label);
182
182
 
183
183
  if (collectUsedPrefixes) {
184
184
  Object.defineProperty(doc, 'usedPrefixes', {
@@ -369,8 +369,8 @@ function parseN3SourceList(input, opts = {}) {
369
369
  label: source.label,
370
370
  baseIri: source.baseIri || (sources.length === 1 ? defaultBaseIri : ''),
371
371
  collectUsedPrefixes: true,
372
- collectSourceLocations: !!opts.collectSourceLocations,
373
372
  keepSourceArtifacts: !!opts.keepSourceArtifacts,
373
+ sourceLocations: !!opts.sourceLocations,
374
374
  rdf: !!opts.rdf,
375
375
  }),
376
376
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eyeling",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "description": "A minimal Notation3 (N3) reasoner in JavaScript.",
5
5
  "main": "./index.js",
6
6
  "keywords": [