Comparing version 1.6.3 to 1.6.4
@@ -7,19 +7,19 @@ "use strict"; | ||
exports.default = void 0; | ||
var RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
XSD = 'http://www.w3.org/2001/XMLSchema#', | ||
SWAP = 'http://www.w3.org/2000/10/swap/'; | ||
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
XSD = 'http://www.w3.org/2001/XMLSchema#', | ||
SWAP = 'http://www.w3.org/2000/10/swap/'; | ||
var _default = { | ||
xsd: { | ||
decimal: XSD + 'decimal', | ||
boolean: XSD + 'boolean', | ||
double: XSD + 'double', | ||
integer: XSD + 'integer', | ||
string: XSD + 'string' | ||
decimal: `${XSD}decimal`, | ||
boolean: `${XSD}boolean`, | ||
double: `${XSD}double`, | ||
integer: `${XSD}integer`, | ||
string: `${XSD}string` | ||
}, | ||
rdf: { | ||
type: RDF + 'type', | ||
nil: RDF + 'nil', | ||
first: RDF + 'first', | ||
rest: RDF + 'rest', | ||
langString: RDF + 'langString' | ||
type: `${RDF}type`, | ||
nil: `${RDF}nil`, | ||
first: `${RDF}first`, | ||
rest: `${RDF}rest`, | ||
langString: `${RDF}langString` | ||
}, | ||
@@ -30,9 +30,9 @@ owl: { | ||
r: { | ||
forSome: SWAP + 'reify#forSome', | ||
forAll: SWAP + 'reify#forAll' | ||
forSome: `${SWAP}reify#forSome`, | ||
forAll: `${SWAP}reify#forAll` | ||
}, | ||
log: { | ||
implies: SWAP + 'log#implies' | ||
implies: `${SWAP}log#implies` | ||
} | ||
}; | ||
exports.default = _default; |
@@ -23,3 +23,4 @@ "use strict"; | ||
xsd | ||
} = _IRIs.default; | ||
} = _IRIs.default; // eslint-disable-next-line prefer-const | ||
let DEFAULTGRAPH; | ||
@@ -100,4 +101,4 @@ let _blankNodeCounter = 0; | ||
// Find the last quotation mark (e.g., '"abc"@en-us') | ||
var id = this.id, | ||
atPos = id.lastIndexOf('"') + 1; // If "@" it follows, return the remaining substring; empty otherwise | ||
const id = this.id; | ||
let atPos = id.lastIndexOf('"') + 1; // If "@" it follows, return the remaining substring; empty otherwise | ||
@@ -115,8 +116,8 @@ return atPos < id.length && id[atPos++] === '@' ? id.substr(atPos).toLowerCase() : ''; | ||
// Find the last quotation mark (e.g., '"abc"^^http://ex.org/types#t') | ||
var id = this.id, | ||
dtPos = id.lastIndexOf('"') + 1, | ||
ch; // If "^" it follows, return the remaining substring | ||
const id = this.id, | ||
dtPos = id.lastIndexOf('"') + 1; | ||
const char = dtPos < id.length ? id[dtPos] : ''; // If "^" it follows, return the remaining substring | ||
return dtPos < id.length && (ch = id[dtPos]) === '^' ? id.substr(dtPos + 2) : // If "@" follows, return rdf:langString; xsd:string otherwise | ||
ch !== '@' ? xsd.string : rdf.langString; | ||
return char === '^' ? id.substr(dtPos + 2) : // If "@" follows, return rdf:langString; xsd:string otherwise | ||
char !== '@' ? xsd.string : rdf.langString; | ||
} // ### Returns whether this object represents the same term as the other | ||
@@ -152,3 +153,3 @@ | ||
constructor(name) { | ||
super('_:' + name); | ||
super(`_:${name}`); | ||
} // ### The term type of this term | ||
@@ -172,3 +173,3 @@ | ||
constructor(name) { | ||
super('?' + name); | ||
super(`?${name}`); | ||
} // ### The term type of this term | ||
@@ -234,3 +235,3 @@ | ||
var endPos = id.lastIndexOf('"', id.length - 1); | ||
const endPos = id.lastIndexOf('"', id.length - 1); | ||
return factory.literal(id.substr(1, endPos - 1), id[endPos + 1] === '@' ? id.substr(endPos + 2) : factory.namedNode(id.substr(endPos + 3))); | ||
@@ -258,6 +259,6 @@ | ||
case 'BlankNode': | ||
return '_:' + term.value; | ||
return `_:${term.value}`; | ||
case 'Variable': | ||
return '?' + term.value; | ||
return `?${term.value}`; | ||
@@ -268,3 +269,3 @@ case 'DefaultGraph': | ||
case 'Literal': | ||
return '"' + term.value + '"' + (term.language ? '@' + term.language : term.datatype && term.datatype.value !== xsd.string ? '^^' + term.datatype.value : ''); | ||
return `"${term.value}"${term.language ? `@${term.language}` : term.datatype && term.datatype.value !== xsd.string ? `^^${term.datatype.value}` : ''}`; | ||
@@ -277,3 +278,3 @@ case 'Quad': | ||
default: | ||
throw new Error('Unexpected termType: ' + term.termType); | ||
throw new Error(`Unexpected termType: ${term.termType}`); | ||
} | ||
@@ -340,3 +341,3 @@ } // ## Quad constructor | ||
// Create a language-tagged string | ||
if (typeof languageOrDataType === 'string') return new Literal('"' + value + '"@' + languageOrDataType.toLowerCase()); // Automatically determine datatype for booleans and numbers | ||
if (typeof languageOrDataType === 'string') return new Literal(`"${value}"@${languageOrDataType.toLowerCase()}`); // Automatically determine datatype for booleans and numbers | ||
@@ -357,3 +358,3 @@ let datatype = languageOrDataType ? languageOrDataType.value : ''; | ||
return datatype === '' || datatype === xsd.string ? new Literal('"' + value + '"') : new Literal('"' + value + '"^^' + datatype); | ||
return datatype === '' || datatype === xsd.string ? new Literal(`"${value}"`) : new Literal(`"${value}"^^${datatype}`); | ||
} // ### Creates a variable | ||
@@ -360,0 +361,0 @@ |
@@ -19,4 +19,4 @@ "use strict"; | ||
var escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g; | ||
var escapeReplacements = { | ||
const escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g; | ||
const escapeReplacements = { | ||
'\\': '\\', | ||
@@ -50,4 +50,4 @@ "'": "'", | ||
}; | ||
var illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/; | ||
var lineModeRegExps = { | ||
const illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/; | ||
const lineModeRegExps = { | ||
_iri: true, | ||
@@ -63,3 +63,3 @@ _unescapedIri: true, | ||
}; | ||
var invalidRegExp = /$0^/; // ## Constructor | ||
const invalidRegExp = /$0^/; // ## Constructor | ||
@@ -96,3 +96,3 @@ class N3Lexer { | ||
for (var key in this) { | ||
for (const key in this) { | ||
if (!(key in lineModeRegExps) && this[key] instanceof RegExp) this[key] = invalidRegExp; | ||
@@ -115,8 +115,8 @@ } | ||
// Continue parsing as far as possible; the loop will return eventually | ||
var input = this._input, | ||
outputComments = this._comments; | ||
let input = this._input; | ||
const outputComments = this._comments; | ||
while (true) { | ||
// Count and skip whitespace lines | ||
var whiteSpaceMatch, comment; | ||
let whiteSpaceMatch, comment; | ||
@@ -161,7 +161,7 @@ while (whiteSpaceMatch = this._newline.exec(input)) { | ||
var line = this._line, | ||
type = '', | ||
const line = this._line, | ||
firstChar = input[0]; | ||
let type = '', | ||
value = '', | ||
prefix = '', | ||
firstChar = input[0], | ||
match = null, | ||
@@ -215,3 +215,3 @@ matchLength = 0, | ||
// Therefore, try inserting a space if we're at the end of the input. | ||
if ((match = this._blank.exec(input)) || inputFinished && (match = this._blank.exec(input + ' '))) type = 'blank', prefix = '_', value = match[1]; | ||
if ((match = this._blank.exec(input)) || inputFinished && (match = this._blank.exec(`${input} `))) type = 'blank', prefix = '_', value = match[1]; | ||
break; | ||
@@ -293,3 +293,3 @@ | ||
// Therefore, try inserting a space if we're at the end of the input. | ||
if (match = this._number.exec(input) || inputFinished && (match = this._number.exec(input + ' '))) { | ||
if (match = this._number.exec(input) || inputFinished && (match = this._number.exec(`${input} `))) { | ||
type = 'literal', value = match[0]; | ||
@@ -359,3 +359,3 @@ prefix = typeof match[1] === 'string' ? xsd.double : typeof match[2] === 'string' ? xsd.decimal : xsd.integer; | ||
// Therefore, try inserting a space if we're at the end of the input. | ||
else if ((match = this._prefixed.exec(input)) || inputFinished && (match = this._prefixed.exec(input + ' '))) type = 'prefixed', prefix = match[1] || '', value = this._unescape(match[2]); | ||
else if ((match = this._prefixed.exec(input)) || inputFinished && (match = this._prefixed.exec(`${input} `))) type = 'prefixed', prefix = match[1] || '', value = this._unescape(match[2]); | ||
} // A type token is special: it can only be emitted after an IRI or prefixed name is read | ||
@@ -388,3 +388,3 @@ | ||
var token = { | ||
const token = { | ||
line: line, | ||
@@ -476,3 +476,3 @@ type: type, | ||
this._input = null; | ||
var err = new Error('Unexpected "' + issue + '" on line ' + this._line + '.'); | ||
const err = new Error(`Unexpected "${issue}" on line ${this._line}.`); | ||
err.context = { | ||
@@ -490,3 +490,2 @@ token: undefined, | ||
tokenize(input, callback) { | ||
var self = this; | ||
this._line = 1; // If the input is a string, continuously emit tokens through the callback until the end | ||
@@ -497,10 +496,8 @@ | ||
if (typeof callback === 'function') (0, _queueMicrotask.default)(() => self._tokenizeToEnd(callback, true)); // If no callback was passed, tokenize synchronously and return | ||
if (typeof callback === 'function') (0, _queueMicrotask.default)(() => this._tokenizeToEnd(callback, true)); // If no callback was passed, tokenize synchronously and return | ||
else { | ||
var tokens = [], | ||
error; | ||
const tokens = []; | ||
let error; | ||
this._tokenizeToEnd(function (e, t) { | ||
e ? error = e : tokens.push(t); | ||
}, true); | ||
this._tokenizeToEnd((e, t) => e ? error = e : tokens.push(t), true); | ||
@@ -516,8 +513,8 @@ if (error) throw error; | ||
input.on('data', function (data) { | ||
if (self._input !== null && data.length !== 0) { | ||
input.on('data', data => { | ||
if (this._input !== null && data.length !== 0) { | ||
// Prepend any previous pending writes | ||
if (self._pendingBuffer) { | ||
data = Buffer.concat([self._pendingBuffer, data]); | ||
self._pendingBuffer = null; | ||
if (this._pendingBuffer) { | ||
data = Buffer.concat([this._pendingBuffer, data]); | ||
this._pendingBuffer = null; | ||
} // Hold if the buffer ends in an incomplete unicode sequence | ||
@@ -527,8 +524,8 @@ | ||
if (data[data.length - 1] & 0x80) { | ||
self._pendingBuffer = data; | ||
this._pendingBuffer = data; | ||
} // Otherwise, tokenize as far as possible | ||
else { | ||
self._input += data; | ||
this._input += data; | ||
self._tokenizeToEnd(callback, false); | ||
this._tokenizeToEnd(callback, false); | ||
} | ||
@@ -538,4 +535,4 @@ } | ||
input.on('end', function () { | ||
if (self._input !== null) self._tokenizeToEnd(callback, true); | ||
input.on('end', () => { | ||
if (this._input !== null) this._tokenizeToEnd(callback, true); | ||
}); | ||
@@ -542,0 +539,0 @@ input.on('error', callback); |
@@ -30,9 +30,9 @@ "use strict"; | ||
var format = typeof options.format === 'string' ? options.format.match(/\w*$/)[0].toLowerCase() : '', | ||
isTurtle = /turtle/.test(format), | ||
isTriG = /trig/.test(format), | ||
isNTriples = /triple/.test(format), | ||
isNQuads = /quad/.test(format), | ||
isN3 = this._n3Mode = /n3/.test(format), | ||
isLineMode = isNTriples || isNQuads; | ||
const format = typeof options.format === 'string' ? options.format.match(/\w*$/)[0].toLowerCase() : '', | ||
isTurtle = /turtle/.test(format), | ||
isTriG = /trig/.test(format), | ||
isNTriples = /triple/.test(format), | ||
isNQuads = /quad/.test(format), | ||
isN3 = this._n3Mode = /n3/.test(format), | ||
isLineMode = isNTriples || isNQuads; | ||
if (!(this._supportsNamedGraphs = !(isTurtle || isN3))) this._readPredicateOrNamedGraph = this._readPredicate; // Support triples in other graphs | ||
@@ -44,3 +44,3 @@ | ||
if (isLineMode) this._resolveRelativeIRI = function (iri) { | ||
if (isLineMode) this._resolveRelativeIRI = iri => { | ||
return null; | ||
@@ -71,3 +71,3 @@ }; | ||
// Remove fragment if present | ||
var fragmentPos = baseIRI.indexOf('#'); | ||
const fragmentPos = baseIRI.indexOf('#'); | ||
if (fragmentPos >= 0) baseIRI = baseIRI.substr(0, fragmentPos); // Set base IRI and its components | ||
@@ -86,3 +86,3 @@ | ||
_saveContext(type, graph, subject, predicate, object) { | ||
var n3Mode = this._n3Mode; | ||
const n3Mode = this._n3Mode; | ||
@@ -106,3 +106,3 @@ this._contextStack.push({ | ||
this._prefixes._ = this._graph ? this._graph.id.substr(2) + '.' : '.'; // Quantifiers are scoped to a formula | ||
this._prefixes._ = this._graph ? `${this._graph.id.substr(2)}.` : '.'; // Quantifiers are scoped to a formula | ||
@@ -116,4 +116,4 @@ this._quantified = Object.create(this._quantified); | ||
_restoreContext() { | ||
var context = this._contextStack.pop(), | ||
n3Mode = this._n3Mode; | ||
const context = this._contextStack.pop(), | ||
n3Mode = this._n3Mode; | ||
@@ -174,3 +174,3 @@ this._subject = context.subject; | ||
_readEntity(token, quantifier) { | ||
var value; | ||
let value; | ||
@@ -181,3 +181,3 @@ switch (token.type) { | ||
case 'typeIRI': | ||
var iri = this._resolveIRI(token.value); | ||
const iri = this._resolveIRI(token.value); | ||
@@ -191,4 +191,4 @@ if (iri === null) return this._error('Invalid IRI', token); | ||
case 'prefixed': | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === undefined) return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
const prefix = this._prefixes[token.prefix]; | ||
if (prefix === undefined) return this._error(`Undefined prefix "${token.prefix}:"`, token); | ||
value = this._namedNode(prefix + token.value); | ||
@@ -209,3 +209,3 @@ break; | ||
default: | ||
return this._error('Expected entity but got ' + token.type, token); | ||
return this._error(`Expected entity but got ${token.type}`, token); | ||
} // In N3 mode, replace the entity if it is quantified | ||
@@ -294,3 +294,3 @@ | ||
_readPredicate(token) { | ||
var type = token.type; | ||
const type = token.type; | ||
@@ -309,3 +309,3 @@ switch (type) { | ||
// Expected predicate didn't come, must have been trailing semicolon | ||
if (this._predicate === null) return this._error('Unexpected ' + type, token); | ||
if (this._predicate === null) return this._error(`Unexpected ${type}`, token); | ||
this._subject = null; | ||
@@ -388,3 +388,3 @@ return type === ']' ? this._readBlankNodeTail(token) : this._readPunctuation(token); | ||
_readGraph(token) { | ||
if (token.type !== '{') return this._error('Expected graph but got ' + token.type, token); // The "subject" we read is actually the GRAPH's label | ||
if (token.type !== '{') return this._error(`Expected graph but got ${token.type}`, token); // The "subject" we read is actually the GRAPH's label | ||
@@ -412,3 +412,3 @@ this._graph = this._subject, this._subject = null; | ||
var empty = this._predicate === null; | ||
const empty = this._predicate === null; | ||
@@ -439,14 +439,14 @@ this._restoreContext(); // If the blank node was the subject, continue reading the predicate | ||
_readListItem(token) { | ||
var item = null, | ||
let item = null, | ||
// The item of the list | ||
list = null, | ||
// The list itself | ||
previousList = this._subject, | ||
// The previous list that contains this list | ||
stack = this._contextStack, | ||
// The stack of parent contexts | ||
parent = stack[stack.length - 1], | ||
// The parent containing the current list | ||
next = this._readListItem; // The next function to execute | ||
const previousList = this._subject, | ||
// The previous list that contains this list | ||
stack = this._contextStack, | ||
// The stack of parent contexts | ||
parent = stack[stack.length - 1]; // The parent containing the current list | ||
switch (token.type) { | ||
@@ -565,3 +565,3 @@ case '[': | ||
case 'typeIRI': | ||
var datatype = this._readEntity(token); | ||
const datatype = this._readEntity(token); | ||
@@ -625,6 +625,6 @@ if (datatype === undefined) return; // No datatype means an error occurred | ||
_readPunctuation(token) { | ||
var next, | ||
subject = this._subject, | ||
graph = this._graph, | ||
inversePredicate = this._inversePredicate; | ||
let next, | ||
graph = this._graph; | ||
const subject = this._subject, | ||
inversePredicate = this._inversePredicate; | ||
@@ -662,3 +662,3 @@ switch (token.type) { | ||
return this._error('Expected punctuation to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected punctuation to follow "${this._object.id}"`, token); | ||
} // A quad has been completed now, so return it | ||
@@ -668,4 +668,4 @@ | ||
if (subject !== null) { | ||
var predicate = this._predicate, | ||
object = this._object; | ||
const predicate = this._predicate, | ||
object = this._object; | ||
if (!inversePredicate) this._emit(subject, predicate, object, graph);else this._emit(object, predicate, subject, graph); | ||
@@ -679,3 +679,3 @@ } | ||
_readBlankNodePunctuation(token) { | ||
var next; | ||
let next; | ||
@@ -694,3 +694,3 @@ switch (token.type) { | ||
default: | ||
return this._error('Expected punctuation to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected punctuation to follow "${this._object.id}"`, token); | ||
} // A quad has been completed now, so return it | ||
@@ -719,5 +719,5 @@ | ||
_readPrefixIRI(token) { | ||
if (token.type !== 'IRI') return this._error('Expected IRI to follow prefix "' + this._prefix + ':"', token); | ||
if (token.type !== 'IRI') return this._error(`Expected IRI to follow prefix "${this._prefix}:"`, token); | ||
var prefixNode = this._readEntity(token); | ||
const prefixNode = this._readEntity(token); | ||
@@ -733,3 +733,3 @@ this._prefixes[this._prefix] = prefixNode.value; | ||
_readBaseIRI(token) { | ||
var iri = token.type === 'IRI' && this._resolveIRI(token.value); | ||
const iri = token.type === 'IRI' && this._resolveIRI(token.value); | ||
@@ -780,3 +780,3 @@ if (!iri) return this._error('Expected valid IRI to follow base declaration', token); | ||
_readQuantifierList(token) { | ||
var entity; | ||
let entity; | ||
@@ -789,3 +789,3 @@ switch (token.type) { | ||
default: | ||
return this._error('Unexpected ' + token.type, token); | ||
return this._error(`Unexpected ${token.type}`, token); | ||
} // Without explicit quantifiers, map entities to a quantified entity | ||
@@ -842,8 +842,8 @@ | ||
default: | ||
var stack = this._contextStack, | ||
parent = stack.length && stack[stack.length - 1]; // If we were reading a list item, we still need to output it | ||
const stack = this._contextStack, | ||
parent = stack.length && stack[stack.length - 1]; // If we were reading a list item, we still need to output it | ||
if (parent && parent.type === 'item') { | ||
// The list item is the remaining subejct after reading the path | ||
var item = this._subject; // Switch back to the context of the list | ||
const item = this._subject; // Switch back to the context of the list | ||
@@ -862,7 +862,7 @@ this._restoreContext(); // Output the list item | ||
_readForwardPath(token) { | ||
var subject, | ||
predicate, | ||
object = this._blankNode(); // The next token is the predicate | ||
let subject, predicate; | ||
const object = this._blankNode(); // The next token is the predicate | ||
if ((predicate = this._readEntity(token)) === undefined) return; // If we were reading a subject, replace the subject by the path's object | ||
@@ -880,6 +880,5 @@ | ||
_readBackwardPath(token) { | ||
var subject = this._blankNode(), | ||
predicate, | ||
object; // The next token is the predicate | ||
const subject = this._blankNode(); | ||
let predicate, object; // The next token is the predicate | ||
@@ -901,3 +900,3 @@ if ((predicate = this._readEntity(token)) === undefined) return; // If we were reading a subject, replace the subject by the path's subject | ||
if (this._supportsQuads && this._graph === null && (this._graph = this._readEntity(token)) !== undefined) return this._readRDFStarTail; | ||
return this._error('Expected >> to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected >> to follow "${this._object.id}"`, token); | ||
} | ||
@@ -929,3 +928,3 @@ | ||
_getContextEndReader() { | ||
var contextStack = this._contextStack; | ||
const contextStack = this._contextStack; | ||
if (!contextStack.length) return this._readPunctuation; | ||
@@ -955,3 +954,3 @@ | ||
_error(message, token) { | ||
var err = new Error(message + ' on line ' + token.line + '.'); | ||
const err = new Error(`${message} on line ${token.line}.`); | ||
err.context = { | ||
@@ -1005,4 +1004,4 @@ token: token, | ||
var result = '', | ||
length = iri.length, | ||
const length = iri.length; | ||
let result = '', | ||
i = -1, | ||
@@ -1058,3 +1057,3 @@ pathStart = -1, | ||
if (next !== '/') return result + '/' + iri.substr(i + 1); | ||
if (next !== '/') return `${result}/${iri.substr(i + 1)}`; | ||
segmentStart = i + 1; | ||
@@ -1077,9 +1076,8 @@ } | ||
parse(input, quadCallback, prefixCallback) { | ||
var self = this; // The read callback is the next function to be executed when a token arrives. | ||
// The read callback is the next function to be executed when a token arrives. | ||
// We start reading in the top context. | ||
this._readCallback = this._readInTopContext; | ||
this._sparqlStyle = false; | ||
this._prefixes = Object.create(null); | ||
this._prefixes._ = this._blankNodePrefix ? this._blankNodePrefix.substr(2) : 'b' + blankNodePrefix++ + '_'; | ||
this._prefixes._ = this._blankNodePrefix ? this._blankNodePrefix.substr(2) : `b${blankNodePrefix++}_`; | ||
this._prefixCallback = prefixCallback || noop; | ||
@@ -1090,11 +1088,11 @@ this._inversePredicate = false; | ||
if (!quadCallback) { | ||
var quads = [], | ||
error; | ||
const quads = []; | ||
let error; | ||
this._callback = function (e, t) { | ||
this._callback = (e, t) => { | ||
e ? error = e : t && quads.push(t); | ||
}; | ||
this._lexer.tokenize(input).every(function (token) { | ||
return self._readCallback = self._readCallback(token); | ||
this._lexer.tokenize(input).every(token => { | ||
return this._readCallback = this._readCallback(token); | ||
}); | ||
@@ -1109,4 +1107,4 @@ | ||
this._lexer.tokenize(input, function (error, token) { | ||
if (error !== null) self._callback(error), self._callback = noop;else if (self._readCallback) self._readCallback = self._readCallback(token); | ||
this._lexer.tokenize(input, (error, token) => { | ||
if (error !== null) this._callback(error), this._callback = noop;else if (this._readCallback) this._readCallback = this._readCallback(token); | ||
}); | ||
@@ -1125,3 +1123,3 @@ } | ||
// Set factory methods | ||
var namedNode = factory.namedNode; | ||
const namedNode = factory.namedNode; | ||
parser._namedNode = namedNode; | ||
@@ -1128,0 +1126,0 @@ parser._blankNode = factory.blankNode; |
@@ -50,11 +50,10 @@ "use strict"; | ||
// Return the quad count if if was cached | ||
var size = this._size; | ||
let size = this._size; | ||
if (size !== null) return size; // Calculate the number of quads by counting to the deepest level | ||
size = 0; | ||
var graphs = this._graphs, | ||
subjects, | ||
subject; | ||
const graphs = this._graphs; | ||
let subjects, subject; | ||
for (var graphKey in graphs) for (var subjectKey in subjects = graphs[graphKey].subjects) for (var predicateKey in subject = subjects[subjectKey]) size += Object.keys(subject[predicateKey]).length; | ||
for (const graphKey in graphs) for (const subjectKey in subjects = graphs[graphKey].subjects) for (const predicateKey in subject = subjects[subjectKey]) size += Object.keys(subject[predicateKey]).length; | ||
@@ -69,6 +68,6 @@ return this._size = size; | ||
// Create layers as necessary | ||
var index1 = index0[key0] || (index0[key0] = {}); | ||
var index2 = index1[key1] || (index1[key1] = {}); // Setting the key to _any_ value signals the presence of the quad | ||
const index1 = index0[key0] || (index0[key0] = {}); | ||
const index2 = index1[key1] || (index1[key1] = {}); // Setting the key to _any_ value signals the presence of the quad | ||
var existed = (key2 in index2); | ||
const existed = (key2 in index2); | ||
if (!existed) index2[key2] = null; | ||
@@ -81,12 +80,11 @@ return !existed; | ||
// Remove the quad from the index | ||
var index1 = index0[key0], | ||
index2 = index1[key1], | ||
key; | ||
const index1 = index0[key0], | ||
index2 = index1[key1]; | ||
delete index2[key2]; // Remove intermediary index layers if they are empty | ||
for (key in index2) return; | ||
for (const key in index2) return; | ||
delete index1[key1]; | ||
for (key in index1) return; | ||
for (const key in index1) return; | ||
@@ -107,13 +105,11 @@ delete index0[key0]; | ||
_findInIndex(index0, key0, key1, key2, name0, name1, name2, graph, callback, array) { | ||
var tmp, | ||
index1, | ||
index2, | ||
varCount = !key0 + !key1 + !key2, | ||
// depending on the number of variables, keys or reverse index are faster | ||
entityKeys = varCount > 1 ? Object.keys(this._ids) : this._entities; // If a key is specified, use only that part of index 0. | ||
let tmp, index1, index2; // Depending on the number of variables, keys or reverse index are faster | ||
const varCount = !key0 + !key1 + !key2, | ||
entityKeys = varCount > 1 ? Object.keys(this._ids) : this._entities; // If a key is specified, use only that part of index 0. | ||
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0]; | ||
for (var value0 in index0) { | ||
var entity0 = entityKeys[value0]; | ||
for (const value0 in index0) { | ||
const entity0 = entityKeys[value0]; | ||
@@ -124,11 +120,11 @@ if (index1 = index0[value0]) { | ||
for (var value1 in index1) { | ||
var entity1 = entityKeys[value1]; | ||
for (const value1 in index1) { | ||
const entity1 = entityKeys[value1]; | ||
if (index2 = index1[value1]) { | ||
// If a key is specified, use only that part of index 2, if it exists. | ||
var values = key2 ? key2 in index2 ? [key2] : [] : Object.keys(index2); // Create quads for all items found in index 2. | ||
const values = key2 ? key2 in index2 ? [key2] : [] : Object.keys(index2); // Create quads for all items found in index 2. | ||
for (var l = 0; l < values.length; l++) { | ||
var parts = { | ||
for (let l = 0; l < values.length; l++) { | ||
const parts = { | ||
subject: null, | ||
@@ -142,3 +138,3 @@ predicate: null, | ||
var quad = this._factory.quad(parts.subject, parts.predicate, parts.object, (0, _N3DataFactory.termFromId)(graph, this._factory)); | ||
const quad = this._factory.quad(parts.subject, parts.predicate, parts.object, (0, _N3DataFactory.termFromId)(graph, this._factory)); | ||
@@ -157,3 +153,3 @@ if (array) array.push(quad);else if (callback(quad)) return true; | ||
_loop(index0, callback) { | ||
for (var key0 in index0) callback(key0); | ||
for (const key0 in index0) callback(key0); | ||
} // ### `_loopByKey0` executes the callback on all keys of a certain entry in index 0 | ||
@@ -163,3 +159,3 @@ | ||
_loopByKey0(index0, key0, callback) { | ||
var index1, key1; | ||
let index1, key1; | ||
@@ -173,3 +169,3 @@ if (index1 = index0[key0]) { | ||
_loopByKey1(index0, key1, callback) { | ||
var key0, index1; | ||
let key0, index1; | ||
@@ -184,3 +180,3 @@ for (key0 in index0) { | ||
_loopBy2Keys(index0, key0, key1, callback) { | ||
var index1, index2, key2; | ||
let index1, index2, key2; | ||
@@ -196,3 +192,3 @@ if ((index1 = index0[key0]) && (index2 = index1[key1])) { | ||
_countInIndex(index0, key0, key1, key2) { | ||
var count = 0, | ||
let count = 0, | ||
tmp, | ||
@@ -204,3 +200,3 @@ index1, | ||
for (var value0 in index0) { | ||
for (const value0 in index0) { | ||
if (index1 = index0[value0]) { | ||
@@ -210,3 +206,3 @@ // If a key is specified, count only that part of index 1 | ||
for (var value1 in index1) { | ||
for (const value1 in index1) { | ||
if (index2 = index1[value1]) { | ||
@@ -228,3 +224,3 @@ // If a key is specified, count the quad if it exists | ||
if (!isString(graph)) return this._graphs; | ||
var graphs = {}; | ||
const graphs = {}; | ||
graphs[graph] = this._graphs[graph]; | ||
@@ -237,8 +233,7 @@ return graphs; | ||
_uniqueEntities(callback) { | ||
var uniqueIds = Object.create(null), | ||
entities = this._entities; | ||
return function (id) { | ||
const uniqueIds = Object.create(null); | ||
return id => { | ||
if (!(id in uniqueIds)) { | ||
uniqueIds[id] = true; | ||
callback((0, _N3DataFactory.termFromId)(entities[id])); | ||
callback((0, _N3DataFactory.termFromId)(this._entities[id], this._factory)); | ||
} | ||
@@ -260,3 +255,3 @@ }; | ||
var graphItem = this._graphs[graph]; // Create the graph if it doesn't exist yet | ||
let graphItem = this._graphs[graph]; // Create the graph if it doesn't exist yet | ||
@@ -277,4 +272,4 @@ if (!graphItem) { | ||
var ids = this._ids; | ||
var entities = this._entities; | ||
const ids = this._ids; | ||
const entities = this._entities; | ||
subject = ids[subject] || (ids[entities[++this._id] = subject] = this._id); | ||
@@ -284,3 +279,3 @@ predicate = ids[predicate] || (ids[entities[++this._id] = predicate] = this._id); | ||
var changed = this._addToIndex(graphItem.subjects, subject, predicate, object); | ||
const changed = this._addToIndex(graphItem.subjects, subject, predicate, object); | ||
@@ -298,3 +293,3 @@ this._addToIndex(graphItem.predicates, predicate, object, subject); | ||
addQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) this.addQuad(quads[i]); | ||
for (let i = 0; i < quads.length; i++) this.addQuad(quads[i]); | ||
} // ### `import` adds a stream of quads to the store | ||
@@ -304,5 +299,4 @@ | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { | ||
self.addQuad(quad); | ||
stream.on('data', quad => { | ||
this.addQuad(quad); | ||
}); | ||
@@ -323,7 +317,5 @@ return stream; | ||
var graphItem, | ||
ids = this._ids, | ||
graphs = this._graphs, | ||
subjects, | ||
predicates; | ||
const ids = this._ids, | ||
graphs = this._graphs; | ||
let graphItem, subjects, predicates; | ||
if (!(subject = ids[subject]) || !(predicate = ids[predicate]) || !(object = ids[object]) || !(graphItem = graphs[graph]) || !(subjects = graphItem.subjects[subject]) || !(predicates = subjects[predicate]) || !(object in predicates)) return false; // Remove it from all indexes | ||
@@ -347,3 +339,3 @@ | ||
removeQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) this.removeQuad(quads[i]); | ||
for (let i = 0; i < quads.length; i++) this.removeQuad(quads[i]); | ||
} // ### `remove` removes a stream of quads from the store | ||
@@ -353,5 +345,4 @@ | ||
remove(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { | ||
self.removeQuad(quad); | ||
stream.on('data', quad => { | ||
this.removeQuad(quad); | ||
}); | ||
@@ -381,14 +372,11 @@ return stream; | ||
var quads = [], | ||
graphs = this._getGraphs(graph), | ||
content, | ||
ids = this._ids, | ||
subjectId, | ||
predicateId, | ||
objectId; // Translate IRIs to internal index keys. | ||
const quads = [], | ||
graphs = this._getGraphs(graph), | ||
ids = this._ids; | ||
let content, subjectId, predicateId, objectId; // Translate IRIs to internal index keys. | ||
if (isString(subject) && !(subjectId = ids[subject]) || isString(predicate) && !(predicateId = ids[predicate]) || isString(object) && !(objectId = ids[object])) return quads; | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -414,3 +402,3 @@ if (content = graphs[graphId]) { | ||
match(subject, predicate, object, graph) { | ||
var stream = new _readableStream.Readable({ | ||
const stream = new _readableStream.Readable({ | ||
objectMode: true | ||
@@ -420,3 +408,3 @@ }); // Initialize stream once it is being read | ||
stream._read = () => { | ||
for (var quad of this.getQuads(subject, predicate, object, graph)) stream.push(quad); | ||
for (const quad of this.getQuads(subject, predicate, object, graph)) stream.push(quad); | ||
@@ -438,6 +426,7 @@ stream.push(null); | ||
var count = 0, | ||
graphs = this._getGraphs(graph), | ||
const graphs = this._getGraphs(graph), | ||
ids = this._ids; | ||
let count = 0, | ||
content, | ||
ids = this._ids, | ||
subjectId, | ||
@@ -447,6 +436,5 @@ predicateId, | ||
if (isString(subject) && !(subjectId = ids[subject]) || isString(predicate) && !(predicateId = ids[predicate]) || isString(object) && !(objectId = ids[object])) return 0; | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -475,3 +463,3 @@ if (content = graphs[graphId]) { | ||
forEach(callback, subject, predicate, object, graph) { | ||
this.some(function (quad) { | ||
this.some(quad => { | ||
callback(quad); | ||
@@ -486,4 +474,4 @@ return false; | ||
every(callback, subject, predicate, object, graph) { | ||
var some = false; | ||
var every = !this.some(function (quad) { | ||
let some = false; | ||
const every = !this.some(quad => { | ||
some = true; | ||
@@ -505,13 +493,10 @@ return !callback(quad); | ||
var graphs = this._getGraphs(graph), | ||
content, | ||
ids = this._ids, | ||
subjectId, | ||
predicateId, | ||
objectId; // Translate IRIs to internal index keys. | ||
const graphs = this._getGraphs(graph), | ||
ids = this._ids; | ||
let content, subjectId, predicateId, objectId; // Translate IRIs to internal index keys. | ||
if (isString(subject) && !(subjectId = ids[subject]) || isString(predicate) && !(predicateId = ids[predicate]) || isString(object) && !(objectId = ids[object])) return false; | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -549,4 +534,4 @@ if (content = graphs[graphId]) { | ||
getSubjects(predicate, object, graph) { | ||
var results = []; | ||
this.forSubjects(function (s) { | ||
const results = []; | ||
this.forSubjects(s => { | ||
results.push(s); | ||
@@ -565,8 +550,6 @@ }, predicate, object, graph); | ||
var ids = this._ids, | ||
graphs = this._getGraphs(graph), | ||
content, | ||
predicateId, | ||
objectId; | ||
const ids = this._ids, | ||
graphs = this._getGraphs(graph); | ||
let content, predicateId, objectId; | ||
callback = this._uniqueEntities(callback); // Translate IRIs to internal index keys. | ||
@@ -594,4 +577,4 @@ | ||
getPredicates(subject, object, graph) { | ||
var results = []; | ||
this.forPredicates(function (p) { | ||
const results = []; | ||
this.forPredicates(p => { | ||
results.push(p); | ||
@@ -610,8 +593,6 @@ }, subject, object, graph); | ||
var ids = this._ids, | ||
graphs = this._getGraphs(graph), | ||
content, | ||
subjectId, | ||
objectId; | ||
const ids = this._ids, | ||
graphs = this._getGraphs(graph); | ||
let content, subjectId, objectId; | ||
callback = this._uniqueEntities(callback); // Translate IRIs to internal index keys. | ||
@@ -639,4 +620,4 @@ | ||
getObjects(subject, predicate, graph) { | ||
var results = []; | ||
this.forObjects(function (o) { | ||
const results = []; | ||
this.forObjects(o => { | ||
results.push(o); | ||
@@ -655,8 +636,6 @@ }, subject, predicate, graph); | ||
var ids = this._ids, | ||
graphs = this._getGraphs(graph), | ||
content, | ||
subjectId, | ||
predicateId; | ||
const ids = this._ids, | ||
graphs = this._getGraphs(graph); | ||
let content, subjectId, predicateId; | ||
callback = this._uniqueEntities(callback); // Translate IRIs to internal index keys. | ||
@@ -684,4 +663,4 @@ | ||
getGraphs(subject, predicate, object) { | ||
var results = []; | ||
this.forGraphs(function (g) { | ||
const results = []; | ||
this.forGraphs(g => { | ||
results.push(g); | ||
@@ -695,4 +674,4 @@ }, subject, predicate, object); | ||
forGraphs(callback, subject, predicate, object) { | ||
for (var graph in this._graphs) { | ||
this.some(function (quad) { | ||
for (const graph in this._graphs) { | ||
this.some(quad => { | ||
callback(quad.graph); | ||
@@ -706,6 +685,6 @@ return true; // Halt iteration of some() | ||
createBlankNode(suggestedName) { | ||
var name, index; // Generate a name based on the suggested name | ||
let name, index; // Generate a name based on the suggested name | ||
if (suggestedName) { | ||
name = suggestedName = '_:' + suggestedName, index = 1; | ||
name = suggestedName = `_:${suggestedName}`, index = 1; | ||
@@ -716,3 +695,3 @@ while (this._ids[name]) name = suggestedName + index++; | ||
do { | ||
name = '_:b' + this._blankNodeIndex++; | ||
name = `_:b${this._blankNodeIndex++}`; | ||
} while (this._ids[name]); | ||
@@ -733,29 +712,28 @@ } // Add the blank node to the entities, avoiding the generation of duplicates | ||
} = {}) { | ||
var lists = {}; // has scalar keys so could be a simple Object | ||
const lists = {}; // has scalar keys so could be a simple Object | ||
var onError = ignoreErrors ? () => true : (node, message) => { | ||
const onError = ignoreErrors ? () => true : (node, message) => { | ||
throw new Error(`${node.value} ${message}`); | ||
}; // Traverse each list from its tail | ||
var tails = this.getQuads(null, _IRIs.default.rdf.rest, _IRIs.default.rdf.nil, null); | ||
var toRemove = remove ? [...tails] : []; | ||
const tails = this.getQuads(null, _IRIs.default.rdf.rest, _IRIs.default.rdf.nil, null); | ||
const toRemove = remove ? [...tails] : []; | ||
tails.forEach(tailQuad => { | ||
var items = []; // the members found as objects of rdf:first quads | ||
const items = []; // the members found as objects of rdf:first quads | ||
var malformed = false; // signals whether the current list is malformed | ||
let malformed = false; // signals whether the current list is malformed | ||
var head; // the head of the list (_:b1 in above example) | ||
let head; // the head of the list (_:b1 in above example) | ||
var headPos; // set to subject or object when head is set | ||
let headPos; // set to subject or object when head is set | ||
var graph = tailQuad.graph; // make sure list is in exactly one graph | ||
const graph = tailQuad.graph; // make sure list is in exactly one graph | ||
// Traverse the list from tail to end | ||
var current = tailQuad.subject; | ||
let current = tailQuad.subject; | ||
while (current && !malformed) { | ||
var objectQuads = this.getQuads(null, null, current, null); | ||
var subjectQuads = this.getQuads(current, null, null, null); | ||
var i, | ||
quad, | ||
const objectQuads = this.getQuads(null, null, current, null); | ||
const subjectQuads = this.getQuads(current, null, null, null); | ||
let quad, | ||
first = null, | ||
@@ -765,3 +743,3 @@ rest = null, | ||
for (i = 0; i < subjectQuads.length && !malformed; i++) { | ||
for (let i = 0; i < subjectQuads.length && !malformed; i++) { | ||
quad = subjectQuads[i]; | ||
@@ -784,3 +762,3 @@ if (!quad.graph.equals(graph)) malformed = onError(current, 'not confined to single graph');else if (head) malformed = onError(current, 'has non-list arcs out'); // one rdf:first | ||
for (i = 0; i < objectQuads.length && !malformed; ++i) { | ||
for (let i = 0; i < objectQuads.length && !malformed; ++i) { | ||
quad = objectQuads[i]; | ||
@@ -787,0 +765,0 @@ if (head) malformed = onError(current, 'can\'t have coreferences'); // one rdf:rest |
@@ -23,8 +23,6 @@ "use strict"; | ||
var self = this, | ||
parser = new _N3Parser.default(options), | ||
onData, | ||
onEnd; | ||
const parser = new _N3Parser.default(options); | ||
let onData, onEnd; | ||
parser.parse({ | ||
on: function (event, callback) { | ||
on: (event, callback) => { | ||
switch (event) { | ||
@@ -41,10 +39,10 @@ case 'data': | ||
}, // Handle quads by pushing them down the pipeline | ||
function (error, quad) { | ||
error && self.emit('error', error) || quad && self.push(quad); | ||
(error, quad) => { | ||
error && this.emit('error', error) || quad && this.push(quad); | ||
}, // Emit prefixes through the `prefix` event | ||
function (prefix, uri) { | ||
self.emit('prefix', prefix, uri); | ||
(prefix, uri) => { | ||
this.emit('prefix', prefix, uri); | ||
}); // Implement Transform methods through parser callbacks | ||
this._transform = function (chunk, encoding, done) { | ||
this._transform = (chunk, encoding, done) => { | ||
onData(chunk); | ||
@@ -54,3 +52,3 @@ done(); | ||
this._flush = function (done) { | ||
this._flush = done => { | ||
onEnd(); | ||
@@ -63,11 +61,10 @@ done(); | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (chunk) { | ||
self.write(chunk); | ||
stream.on('data', chunk => { | ||
this.write(chunk); | ||
}); | ||
stream.on('end', function () { | ||
self.end(); | ||
stream.on('end', () => { | ||
this.end(); | ||
}); | ||
stream.on('error', function (error) { | ||
self.emit('error', error); | ||
stream.on('error', error => { | ||
this.emit('error', error); | ||
}); | ||
@@ -74,0 +71,0 @@ return this; |
@@ -23,10 +23,9 @@ "use strict"; | ||
var self = this; | ||
var writer = this._writer = new _N3Writer.default({ | ||
write: function (quad, encoding, callback) { | ||
self.push(quad); | ||
const writer = this._writer = new _N3Writer.default({ | ||
write: (quad, encoding, callback) => { | ||
this.push(quad); | ||
callback && callback(); | ||
}, | ||
end: function (callback) { | ||
self.push(null); | ||
end: callback => { | ||
this.push(null); | ||
callback && callback(); | ||
@@ -36,7 +35,7 @@ } | ||
this._transform = function (quad, encoding, done) { | ||
this._transform = (quad, encoding, done) => { | ||
writer.addQuad(quad, done); | ||
}; | ||
this._flush = function (done) { | ||
this._flush = done => { | ||
writer.end(done); | ||
@@ -48,14 +47,13 @@ }; | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { | ||
self.write(quad); | ||
stream.on('data', quad => { | ||
this.write(quad); | ||
}); | ||
stream.on('end', function () { | ||
self.end(); | ||
stream.on('end', () => { | ||
this.end(); | ||
}); | ||
stream.on('error', function (error) { | ||
self.emit('error', error); | ||
stream.on('error', error => { | ||
this.emit('error', error); | ||
}); | ||
stream.on('prefix', function (prefix, iri) { | ||
self._writer.addPrefix(prefix, iri); | ||
stream.on('prefix', (prefix, iri) => { | ||
this._writer.addPrefix(prefix, iri); | ||
}); | ||
@@ -62,0 +60,0 @@ return this; |
@@ -60,5 +60,5 @@ "use strict"; | ||
// Add all of the default prefixes | ||
var prefixes = Object.create(null); | ||
const prefixes = Object.create(null); | ||
for (var prefix in defaultPrefixes) processPrefix(prefix, defaultPrefixes[prefix]); // Set the default factory if none was specified | ||
for (const prefix in defaultPrefixes) processPrefix(prefix, defaultPrefixes[prefix]); // Set the default factory if none was specified | ||
@@ -73,9 +73,9 @@ | ||
// Create a function that expands the prefix | ||
var cache = Object.create(null); | ||
const cache = Object.create(null); | ||
prefixes[prefix] = function (local) { | ||
prefixes[prefix] = local => { | ||
return cache[local] || (cache[local] = factory.namedNode(iri + local)); | ||
}; | ||
} else if (!(prefix in prefixes)) { | ||
throw new Error('Unknown prefix: ' + prefix); | ||
throw new Error(`Unknown prefix: ${prefix}`); | ||
} | ||
@@ -82,0 +82,0 @@ |
@@ -28,5 +28,5 @@ "use strict"; | ||
var escape = /["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/, | ||
escapeAll = /["\\\t\n\r\b\f\u0000-\u0019]|[\ud800-\udbff][\udc00-\udfff]/g, | ||
escapedCharacters = { | ||
const escape = /["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/, | ||
escapeAll = /["\\\t\n\r\b\f\u0000-\u0019]|[\ud800-\udbff][\udc00-\udfff]/g, | ||
escapedCharacters = { | ||
'\\': '\\\\', | ||
@@ -61,3 +61,3 @@ '"': '\\"', | ||
if (!outputStream) { | ||
var output = ''; | ||
let output = ''; | ||
this._outputStream = { | ||
@@ -69,3 +69,3 @@ write(chunk, encoding, done) { | ||
end: function (done) { | ||
end: done => { | ||
done && done(null, output); | ||
@@ -109,3 +109,3 @@ } | ||
// Close the previous graph and start the new one | ||
this._write((this._subject === null ? '' : this._inDefaultGraph ? '.\n' : '\n}\n') + (DEFAULTGRAPH.equals(graph) ? '' : this._encodeIriOrBlank(graph) + ' {\n')); | ||
this._write((this._subject === null ? '' : this._inDefaultGraph ? '.\n' : '\n}\n') + (DEFAULTGRAPH.equals(graph) ? '' : `${this._encodeIriOrBlank(graph)} {\n`)); | ||
@@ -119,6 +119,6 @@ this._graph = graph; | ||
// Don't repeat the predicate if it's the same | ||
if (predicate.equals(this._predicate)) this._write(', ' + this._encodeObject(object), done); // Same subject, different predicate | ||
else this._write(';\n ' + this._encodePredicate(this._predicate = predicate) + ' ' + this._encodeObject(object), done); | ||
if (predicate.equals(this._predicate)) this._write(`, ${this._encodeObject(object)}`, done); // Same subject, different predicate | ||
else this._write(`;\n ${this._encodePredicate(this._predicate = predicate)} ${this._encodeObject(object)}`, done); | ||
} // Different subject; write the whole quad | ||
else this._write((this._subject === null ? '' : '.\n') + this._encodeSubject(this._subject = subject) + ' ' + this._encodePredicate(this._predicate = predicate) + ' ' + this._encodeObject(object), done); | ||
else this._write(`${(this._subject === null ? '' : '.\n') + this._encodeSubject(this._subject = subject)} ${this._encodePredicate(this._predicate = predicate)} ${this._encodeObject(object)}`, done); | ||
} catch (error) { | ||
@@ -139,3 +139,3 @@ done && done(error); | ||
quadToString(subject, predicate, object, graph) { | ||
return this._encodeSubject(subject) + ' ' + this._encodeIriOrBlank(predicate) + ' ' + this._encodeObject(object) + (graph && graph.value ? ' ' + this._encodeIriOrBlank(graph) + ' .\n' : ' .\n'); | ||
return `${this._encodeSubject(subject)} ${this._encodeIriOrBlank(predicate)} ${this._encodeObject(object)}${graph && graph.value ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`; | ||
} // ### `quadsToString` serializes an array of quads as a string | ||
@@ -145,5 +145,5 @@ | ||
quadsToString(quads) { | ||
return quads.map(function (t) { | ||
return quads.map(t => { | ||
return this.quadToString(t.subject, t.predicate, t.object, t.graph); | ||
}, this).join(''); | ||
}).join(''); | ||
} // ### `_encodeSubject` represents a subject | ||
@@ -162,12 +162,12 @@ | ||
if (this._lists && entity.value in this._lists) entity = this.list(this._lists[entity.value]); | ||
return 'id' in entity ? entity.id : '_:' + entity.value; | ||
return 'id' in entity ? entity.id : `_:${entity.value}`; | ||
} // Escape special characters | ||
var iri = entity.value; | ||
let iri = entity.value; | ||
if (escape.test(iri)) iri = iri.replace(escapeAll, characterReplacer); // Try to represent the IRI as prefixed name | ||
var prefixMatch = this._prefixRegex.exec(iri); | ||
const prefixMatch = this._prefixRegex.exec(iri); | ||
return !prefixMatch ? '<' + iri + '>' : !prefixMatch[1] ? iri : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2]; | ||
return !prefixMatch ? `<${iri}>` : !prefixMatch[1] ? iri : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2]; | ||
} // ### `_encodeLiteral` represents a literal | ||
@@ -178,6 +178,6 @@ | ||
// Escape special characters | ||
var value = literal.value; | ||
let value = literal.value; | ||
if (escape.test(value)) value = value.replace(escapeAll, characterReplacer); // Write the literal, possibly with type or language | ||
if (literal.language) return '"' + value + '"@' + literal.language;else if (literal.datatype.value !== xsd.string) return '"' + value + '"^^' + this._encodeIriOrBlank(literal.datatype);else return '"' + value + '"'; | ||
if (literal.language) return `"${value}"@${literal.language}`;else if (literal.datatype.value !== xsd.string) return `"${value}"^^${this._encodeIriOrBlank(literal.datatype)}`;else return `"${value}"`; | ||
} // ### `_encodePredicate` represents a predicate | ||
@@ -229,3 +229,3 @@ | ||
addQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) this.addQuad(quads[i]); | ||
for (let i = 0; i < quads.length; i++) this.addQuad(quads[i]); | ||
} // ### `addPrefix` adds the prefix to the output stream | ||
@@ -235,3 +235,3 @@ | ||
addPrefix(prefix, iri, done) { | ||
var prefixes = {}; | ||
const prefixes = {}; | ||
prefixes[prefix] = iri; | ||
@@ -243,7 +243,9 @@ this.addPrefixes(prefixes, done); | ||
addPrefixes(prefixes, done) { | ||
var prefixIRIs = this._prefixIRIs, | ||
hasPrefixes = false; | ||
// Ignore prefixes if not supported by the serialization | ||
if (!this._prefixIRIs) return done && done(); // Write all new prefixes | ||
for (var prefix in prefixes) { | ||
var iri = prefixes[prefix]; | ||
let hasPrefixes = false; | ||
for (let prefix in prefixes) { | ||
let iri = prefixes[prefix]; | ||
if (typeof iri !== 'string') iri = iri.value; | ||
@@ -259,5 +261,5 @@ hasPrefixes = true; // Finish a possible pending quad | ||
prefixIRIs[iri] = prefix += ':'; | ||
this._prefixIRIs[iri] = prefix += ':'; | ||
this._write('@prefix ' + prefix + ' <' + iri + '>.\n'); | ||
this._write(`@prefix ${prefix} <${iri}>.\n`); | ||
} // Recreate the prefix matcher | ||
@@ -267,12 +269,12 @@ | ||
if (hasPrefixes) { | ||
var IRIlist = '', | ||
let IRIlist = '', | ||
prefixList = ''; | ||
for (var prefixIRI in prefixIRIs) { | ||
IRIlist += IRIlist ? '|' + prefixIRI : prefixIRI; | ||
prefixList += (prefixList ? '|' : '') + prefixIRIs[prefixIRI]; | ||
for (const prefixIRI in this._prefixIRIs) { | ||
IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI; | ||
prefixList += (prefixList ? '|' : '') + this._prefixIRIs[prefixIRI]; | ||
} | ||
IRIlist = IRIlist.replace(/[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&'); | ||
this._prefixRegex = new RegExp('^(?:' + prefixList + ')[^\/]*$|' + '^(' + IRIlist + ')([a-zA-Z][\\-_a-zA-Z0-9]*)$'); | ||
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` + `^(${IRIlist})([a-zA-Z][\\-_a-zA-Z0-9]*)$`); | ||
} // End a prefix block with a newline | ||
@@ -286,3 +288,3 @@ | ||
blank(predicate, object) { | ||
var children = predicate, | ||
let children = predicate, | ||
child, | ||
@@ -306,14 +308,14 @@ length; // Empty blank node | ||
child = children[0]; | ||
if (!(child.object instanceof SerializedTerm)) return new SerializedTerm('[ ' + this._encodePredicate(child.predicate) + ' ' + this._encodeObject(child.object) + ' ]'); | ||
if (!(child.object instanceof SerializedTerm)) return new SerializedTerm(`[ ${this._encodePredicate(child.predicate)} ${this._encodeObject(child.object)} ]`); | ||
// Generate a multi-triple or nested blank node | ||
default: | ||
var contents = '['; // Write all triples in order | ||
let contents = '['; // Write all triples in order | ||
for (var i = 0; i < length; i++) { | ||
for (let i = 0; i < length; i++) { | ||
child = children[i]; // Write only the object is the predicate is the same as the previous | ||
if (child.predicate.equals(predicate)) contents += ', ' + this._encodeObject(child.object); // Otherwise, write the predicate and the object | ||
if (child.predicate.equals(predicate)) contents += `, ${this._encodeObject(child.object)}`; // Otherwise, write the predicate and the object | ||
else { | ||
contents += (i ? ';\n ' : '\n ') + this._encodePredicate(child.predicate) + ' ' + this._encodeObject(child.object); | ||
contents += `${(i ? ';\n ' : '\n ') + this._encodePredicate(child.predicate)} ${this._encodeObject(child.object)}`; | ||
predicate = child.predicate; | ||
@@ -323,3 +325,3 @@ } | ||
return new SerializedTerm(contents + '\n]'); | ||
return new SerializedTerm(`${contents}\n]`); | ||
} | ||
@@ -330,8 +332,8 @@ } // ### `list` creates a list node with the given content | ||
list(elements) { | ||
var length = elements && elements.length || 0, | ||
contents = new Array(length); | ||
const length = elements && elements.length || 0, | ||
contents = new Array(length); | ||
for (var i = 0; i < length; i++) contents[i] = this._encodeObject(elements[i]); | ||
for (let i = 0; i < length; i++) contents[i] = this._encodeObject(elements[i]); | ||
return new SerializedTerm('(' + contents.join(' ') + ')'); | ||
return new SerializedTerm(`(${contents.join(' ')})`); | ||
} // ### `end` signals the end of the output stream | ||
@@ -351,5 +353,5 @@ | ||
var singleDone = done && function (error, result) { | ||
let singleDone = done && ((error, result) => { | ||
singleDone = null, done(error, result); | ||
}; | ||
}); | ||
@@ -374,3 +376,3 @@ if (this._endStream) { | ||
// Replace a single character by its escaped version | ||
var result = escapedCharacters[character]; | ||
let result = escapedCharacters[character]; | ||
@@ -377,0 +379,0 @@ if (result === undefined) { |
{ | ||
"name": "n3", | ||
"version": "1.6.3", | ||
"version": "1.6.4", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -63,3 +63,3 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", | ||
"spec-clean": "rm -r .rdf-test-suite-cache/", | ||
"docs": "docco src/*.js" | ||
"docs": "cd src && docco *.js -o ../docs && cd .." | ||
}, | ||
@@ -66,0 +66,0 @@ "repository": { |
# Lightning fast, asynchronous, streaming RDF for JavaScript | ||
[](https://travis-ci.org/rdfjs/N3.js) | ||
[](https://api.travis-ci.com/rdfjs/N3.js.svg?branch=master) | ||
[](https://coveralls.io/github/rdfjs/N3.js) | ||
@@ -4,0 +4,0 @@ [](https://www.npmjs.com/package/n3) |
@@ -1,2 +0,2 @@ | ||
var RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', | ||
XSD = 'http://www.w3.org/2001/XMLSchema#', | ||
@@ -7,14 +7,14 @@ SWAP = 'http://www.w3.org/2000/10/swap/'; | ||
xsd: { | ||
decimal: XSD + 'decimal', | ||
boolean: XSD + 'boolean', | ||
double: XSD + 'double', | ||
integer: XSD + 'integer', | ||
string: XSD + 'string', | ||
decimal: `${XSD}decimal`, | ||
boolean: `${XSD}boolean`, | ||
double: `${XSD}double`, | ||
integer: `${XSD}integer`, | ||
string: `${XSD}string`, | ||
}, | ||
rdf: { | ||
type: RDF + 'type', | ||
nil: RDF + 'nil', | ||
first: RDF + 'first', | ||
rest: RDF + 'rest', | ||
langString: RDF + 'langString', | ||
type: `${RDF}type`, | ||
nil: `${RDF}nil`, | ||
first: `${RDF}first`, | ||
rest: `${RDF}rest`, | ||
langString: `${RDF}langString`, | ||
}, | ||
@@ -25,8 +25,8 @@ owl: { | ||
r: { | ||
forSome: SWAP + 'reify#forSome', | ||
forAll: SWAP + 'reify#forAll', | ||
forSome: `${SWAP}reify#forSome`, | ||
forAll: `${SWAP}reify#forAll`, | ||
}, | ||
log: { | ||
implies: SWAP + 'log#implies', | ||
implies: `${SWAP}log#implies`, | ||
}, | ||
}; |
@@ -8,2 +8,3 @@ // N3.js implementations of the RDF/JS core data types | ||
// eslint-disable-next-line prefer-const | ||
let DEFAULTGRAPH; | ||
@@ -82,3 +83,4 @@ let _blankNodeCounter = 0; | ||
// Find the last quotation mark (e.g., '"abc"@en-us') | ||
var id = this.id, atPos = id.lastIndexOf('"') + 1; | ||
const id = this.id; | ||
let atPos = id.lastIndexOf('"') + 1; | ||
// If "@" it follows, return the remaining substring; empty otherwise | ||
@@ -96,7 +98,8 @@ return atPos < id.length && id[atPos++] === '@' ? id.substr(atPos).toLowerCase() : ''; | ||
// Find the last quotation mark (e.g., '"abc"^^http://ex.org/types#t') | ||
var id = this.id, dtPos = id.lastIndexOf('"') + 1, ch; | ||
const id = this.id, dtPos = id.lastIndexOf('"') + 1; | ||
const char = dtPos < id.length ? id[dtPos] : ''; | ||
// If "^" it follows, return the remaining substring | ||
return dtPos < id.length && (ch = id[dtPos]) === '^' ? id.substr(dtPos + 2) : | ||
return char === '^' ? id.substr(dtPos + 2) : | ||
// If "@" follows, return rdf:langString; xsd:string otherwise | ||
(ch !== '@' ? xsd.string : rdf.langString); | ||
(char !== '@' ? xsd.string : rdf.langString); | ||
} | ||
@@ -131,3 +134,3 @@ | ||
constructor(name) { | ||
super('_:' + name); | ||
super(`_:${name}`); | ||
} | ||
@@ -148,3 +151,3 @@ | ||
constructor(name) { | ||
super('?' + name); | ||
super(`?${name}`); | ||
} | ||
@@ -210,3 +213,3 @@ | ||
// Literal with datatype or language | ||
var endPos = id.lastIndexOf('"', id.length - 1); | ||
const endPos = id.lastIndexOf('"', id.length - 1); | ||
return factory.literal(id.substr(1, endPos - 1), | ||
@@ -240,8 +243,8 @@ id[endPos + 1] === '@' ? id.substr(endPos + 2) | ||
case 'NamedNode': return term.value; | ||
case 'BlankNode': return '_:' + term.value; | ||
case 'Variable': return '?' + term.value; | ||
case 'BlankNode': return `_:${term.value}`; | ||
case 'Variable': return `?${term.value}`; | ||
case 'DefaultGraph': return ''; | ||
case 'Literal': return '"' + term.value + '"' + | ||
(term.language ? '@' + term.language : | ||
(term.datatype && term.datatype.value !== xsd.string ? '^^' + term.datatype.value : '')); | ||
case 'Literal': return `"${term.value}"${ | ||
term.language ? `@${term.language}` : | ||
(term.datatype && term.datatype.value !== xsd.string ? `^^${term.datatype.value}` : '')}`; | ||
case 'Quad': | ||
@@ -259,3 +262,3 @@ // To identify RDF* quad components, we escape quotes by doubling them. | ||
}>>`; | ||
default: throw new Error('Unexpected termType: ' + term.termType); | ||
default: throw new Error(`Unexpected termType: ${term.termType}`); | ||
} | ||
@@ -325,3 +328,3 @@ } | ||
if (typeof languageOrDataType === 'string') | ||
return new Literal('"' + value + '"@' + languageOrDataType.toLowerCase()); | ||
return new Literal(`"${value}"@${languageOrDataType.toLowerCase()}`); | ||
@@ -348,4 +351,4 @@ // Automatically determine datatype for booleans and numbers | ||
return (datatype === '' || datatype === xsd.string) ? | ||
new Literal('"' + value + '"') : | ||
new Literal('"' + value + '"^^' + datatype); | ||
new Literal(`"${value}"`) : | ||
new Literal(`"${value}"^^${datatype}`); | ||
} | ||
@@ -352,0 +355,0 @@ |
@@ -8,4 +8,4 @@ // **N3Lexer** tokenizes N3 documents. | ||
// Regular expression and replacement string to escape N3 strings | ||
var escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g; | ||
var escapeReplacements = { | ||
const escapeSequence = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\([^])/g; | ||
const escapeReplacements = { | ||
'\\': '\\', "'": "'", '"': '"', | ||
@@ -17,5 +17,5 @@ 'n': '\n', 'r': '\r', 't': '\t', 'f': '\f', 'b': '\b', | ||
}; | ||
var illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/; | ||
const illegalIriChars = /[\x00-\x20<>\\"\{\}\|\^\`]/; | ||
var lineModeRegExps = { | ||
const lineModeRegExps = { | ||
_iri: true, | ||
@@ -31,3 +31,3 @@ _unescapedIri: true, | ||
}; | ||
var invalidRegExp = /$0^/; | ||
const invalidRegExp = /$0^/; | ||
@@ -63,3 +63,3 @@ // ## Constructor | ||
// Don't tokenize special literals | ||
for (var key in this) { | ||
for (const key in this) { | ||
if (!(key in lineModeRegExps) && this[key] instanceof RegExp) | ||
@@ -84,6 +84,7 @@ this[key] = invalidRegExp; | ||
// Continue parsing as far as possible; the loop will return eventually | ||
var input = this._input, outputComments = this._comments; | ||
let input = this._input; | ||
const outputComments = this._comments; | ||
while (true) { | ||
// Count and skip whitespace lines | ||
var whiteSpaceMatch, comment; | ||
let whiteSpaceMatch, comment; | ||
while (whiteSpaceMatch = this._newline.exec(input)) { | ||
@@ -114,4 +115,5 @@ // Try to find a comment | ||
// Look for specific token types based on the first character | ||
var line = this._line, type = '', value = '', prefix = '', | ||
firstChar = input[0], match = null, matchLength = 0, inconclusive = false; | ||
const line = this._line, firstChar = input[0]; | ||
let type = '', value = '', prefix = '', | ||
match = null, matchLength = 0, inconclusive = false; | ||
switch (firstChar) { | ||
@@ -170,3 +172,3 @@ case '^': | ||
if ((match = this._blank.exec(input)) || | ||
inputFinished && (match = this._blank.exec(input + ' '))) | ||
inputFinished && (match = this._blank.exec(`${input} `))) | ||
type = 'blank', prefix = '_', value = match[1]; | ||
@@ -249,3 +251,3 @@ break; | ||
if (match = this._number.exec(input) || | ||
inputFinished && (match = this._number.exec(input + ' '))) { | ||
inputFinished && (match = this._number.exec(`${input} `))) { | ||
type = 'literal', value = match[0]; | ||
@@ -329,3 +331,3 @@ prefix = (typeof match[1] === 'string' ? xsd.double : | ||
else if ((match = this._prefixed.exec(input)) || | ||
inputFinished && (match = this._prefixed.exec(input + ' '))) | ||
inputFinished && (match = this._prefixed.exec(`${input} `))) | ||
type = 'prefixed', prefix = match[1] || '', value = this._unescape(match[2]); | ||
@@ -355,3 +357,3 @@ } | ||
// Emit the parsed token | ||
var token = { line: line, type: type, value: value, prefix: prefix }; | ||
const token = { line: line, type: type, value: value, prefix: prefix }; | ||
callback(null, token); | ||
@@ -431,3 +433,3 @@ this.previousToken = token; | ||
this._input = null; | ||
var err = new Error('Unexpected "' + issue + '" on line ' + this._line + '.'); | ||
const err = new Error(`Unexpected "${issue}" on line ${this._line}.`); | ||
err.context = { | ||
@@ -446,3 +448,2 @@ token: undefined, | ||
tokenize(input, callback) { | ||
var self = this; | ||
this._line = 1; | ||
@@ -455,7 +456,8 @@ | ||
if (typeof callback === 'function') | ||
queueMicrotask(() => self._tokenizeToEnd(callback, true)); | ||
queueMicrotask(() => this._tokenizeToEnd(callback, true)); | ||
// If no callback was passed, tokenize synchronously and return | ||
else { | ||
var tokens = [], error; | ||
this._tokenizeToEnd(function (e, t) { e ? (error = e) : tokens.push(t); }, true); | ||
const tokens = []; | ||
let error; | ||
this._tokenizeToEnd((e, t) => e ? (error = e) : tokens.push(t), true); | ||
if (error) throw error; | ||
@@ -472,17 +474,17 @@ return tokens; | ||
// Adds the data chunk to the buffer and parses as far as possible | ||
input.on('data', function (data) { | ||
if (self._input !== null && data.length !== 0) { | ||
input.on('data', data => { | ||
if (this._input !== null && data.length !== 0) { | ||
// Prepend any previous pending writes | ||
if (self._pendingBuffer) { | ||
data = Buffer.concat([self._pendingBuffer, data]); | ||
self._pendingBuffer = null; | ||
if (this._pendingBuffer) { | ||
data = Buffer.concat([this._pendingBuffer, data]); | ||
this._pendingBuffer = null; | ||
} | ||
// Hold if the buffer ends in an incomplete unicode sequence | ||
if (data[data.length - 1] & 0x80) { | ||
self._pendingBuffer = data; | ||
this._pendingBuffer = data; | ||
} | ||
// Otherwise, tokenize as far as possible | ||
else { | ||
self._input += data; | ||
self._tokenizeToEnd(callback, false); | ||
this._input += data; | ||
this._tokenizeToEnd(callback, false); | ||
} | ||
@@ -492,5 +494,5 @@ } | ||
// Parses until the end | ||
input.on('end', function () { | ||
if (self._input !== null) | ||
self._tokenizeToEnd(callback, true); | ||
input.on('end', () => { | ||
if (this._input !== null) | ||
this._tokenizeToEnd(callback, true); | ||
}); | ||
@@ -497,0 +499,0 @@ input.on('error', callback); |
@@ -20,3 +20,3 @@ // **N3Parser** parses N3 documents. | ||
// Set supported features depending on the format | ||
var format = (typeof options.format === 'string') ? | ||
const format = (typeof options.format === 'string') ? | ||
options.format.match(/\w*$/)[0].toLowerCase() : '', | ||
@@ -35,3 +35,3 @@ isTurtle = /turtle/.test(format), isTriG = /trig/.test(format), | ||
if (isLineMode) | ||
this._resolveRelativeIRI = function (iri) { return null; }; | ||
this._resolveRelativeIRI = iri => { return null; }; | ||
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' : | ||
@@ -61,3 +61,3 @@ options.blankNodePrefix.replace(/^(?!_:)/, '_:'); | ||
// Remove fragment if present | ||
var fragmentPos = baseIRI.indexOf('#'); | ||
const fragmentPos = baseIRI.indexOf('#'); | ||
if (fragmentPos >= 0) | ||
@@ -78,3 +78,3 @@ baseIRI = baseIRI.substr(0, fragmentPos); | ||
_saveContext(type, graph, subject, predicate, object) { | ||
var n3Mode = this._n3Mode; | ||
const n3Mode = this._n3Mode; | ||
this._contextStack.push({ | ||
@@ -93,3 +93,3 @@ subject: subject, predicate: predicate, object: object, | ||
// (using a dot as separator, as a blank node label cannot start with it) | ||
this._prefixes._ = (this._graph ? this._graph.id.substr(2) + '.' : '.'); | ||
this._prefixes._ = (this._graph ? `${this._graph.id.substr(2)}.` : '.'); | ||
// Quantifiers are scoped to a formula | ||
@@ -103,3 +103,3 @@ this._quantified = Object.create(this._quantified); | ||
_restoreContext() { | ||
var context = this._contextStack.pop(), n3Mode = this._n3Mode; | ||
const context = this._contextStack.pop(), n3Mode = this._n3Mode; | ||
this._subject = context.subject; | ||
@@ -154,3 +154,3 @@ this._predicate = context.predicate; | ||
_readEntity(token, quantifier) { | ||
var value; | ||
let value; | ||
switch (token.type) { | ||
@@ -160,3 +160,3 @@ // Read a relative or absolute IRI | ||
case 'typeIRI': | ||
var iri = this._resolveIRI(token.value); | ||
const iri = this._resolveIRI(token.value); | ||
if (iri === null) | ||
@@ -169,5 +169,5 @@ return this._error('Invalid IRI', token); | ||
case 'prefixed': | ||
var prefix = this._prefixes[token.prefix]; | ||
const prefix = this._prefixes[token.prefix]; | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
return this._error(`Undefined prefix "${token.prefix}:"`, token); | ||
value = this._namedNode(prefix + token.value); | ||
@@ -185,3 +185,3 @@ break; | ||
default: | ||
return this._error('Expected entity but got ' + token.type, token); | ||
return this._error(`Expected entity but got ${token.type}`, token); | ||
} | ||
@@ -266,3 +266,3 @@ // In N3 mode, replace the entity if it is quantified | ||
_readPredicate(token) { | ||
var type = token.type; | ||
const type = token.type; | ||
switch (type) { | ||
@@ -279,3 +279,3 @@ case 'inverse': | ||
if (this._predicate === null) | ||
return this._error('Unexpected ' + type, token); | ||
return this._error(`Unexpected ${type}`, token); | ||
this._subject = null; | ||
@@ -353,3 +353,3 @@ return type === ']' ? this._readBlankNodeTail(token) : this._readPunctuation(token); | ||
if (token.type !== '{') | ||
return this._error('Expected graph but got ' + token.type, token); | ||
return this._error(`Expected graph but got ${token.type}`, token); | ||
// The "subject" we read is actually the GRAPH's label | ||
@@ -382,3 +382,3 @@ this._graph = this._subject, this._subject = null; | ||
// Restore the parent context containing this blank node | ||
var empty = this._predicate === null; | ||
const empty = this._predicate === null; | ||
this._restoreContext(); | ||
@@ -409,8 +409,8 @@ // If the blank node was the subject, continue reading the predicate | ||
_readListItem(token) { | ||
var item = null, // The item of the list | ||
let item = null, // The item of the list | ||
list = null, // The list itself | ||
previousList = this._subject, // The previous list that contains this list | ||
next = this._readListItem; // The next function to execute | ||
const previousList = this._subject, // The previous list that contains this list | ||
stack = this._contextStack, // The stack of parent contexts | ||
parent = stack[stack.length - 1], // The parent containing the current list | ||
next = this._readListItem; // The next function to execute | ||
parent = stack[stack.length - 1]; // The parent containing the current list | ||
@@ -532,3 +532,3 @@ switch (token.type) { | ||
case 'typeIRI': | ||
var datatype = this._readEntity(token); | ||
const datatype = this._readEntity(token); | ||
if (datatype === undefined) return; // No datatype means an error occurred | ||
@@ -593,4 +593,4 @@ literal = this._literal(this._literalValue, datatype); | ||
_readPunctuation(token) { | ||
var next, subject = this._subject, graph = this._graph, | ||
inversePredicate = this._inversePredicate; | ||
let next, graph = this._graph; | ||
const subject = this._subject, inversePredicate = this._inversePredicate; | ||
switch (token.type) { | ||
@@ -624,7 +624,7 @@ // A closing brace ends a graph | ||
} | ||
return this._error('Expected punctuation to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected punctuation to follow "${this._object.id}"`, token); | ||
} | ||
// A quad has been completed now, so return it | ||
if (subject !== null) { | ||
var predicate = this._predicate, object = this._object; | ||
const predicate = this._predicate, object = this._object; | ||
if (!inversePredicate) | ||
@@ -640,3 +640,3 @@ this._emit(subject, predicate, object, graph); | ||
_readBlankNodePunctuation(token) { | ||
var next; | ||
let next; | ||
switch (token.type) { | ||
@@ -652,3 +652,3 @@ // Semicolon means the subject is shared; predicate and object are different | ||
default: | ||
return this._error('Expected punctuation to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected punctuation to follow "${this._object.id}"`, token); | ||
} | ||
@@ -678,4 +678,4 @@ // A quad has been completed now, so return it | ||
if (token.type !== 'IRI') | ||
return this._error('Expected IRI to follow prefix "' + this._prefix + ':"', token); | ||
var prefixNode = this._readEntity(token); | ||
return this._error(`Expected IRI to follow prefix "${this._prefix}:"`, token); | ||
const prefixNode = this._readEntity(token); | ||
this._prefixes[this._prefix] = prefixNode.value; | ||
@@ -688,3 +688,3 @@ this._prefixCallback(this._prefix, prefixNode); | ||
_readBaseIRI(token) { | ||
var iri = token.type === 'IRI' && this._resolveIRI(token.value); | ||
const iri = token.type === 'IRI' && this._resolveIRI(token.value); | ||
if (!iri) | ||
@@ -733,3 +733,3 @@ return this._error('Expected valid IRI to follow base declaration', token); | ||
_readQuantifierList(token) { | ||
var entity; | ||
let entity; | ||
switch (token.type) { | ||
@@ -741,3 +741,3 @@ case 'IRI': | ||
default: | ||
return this._error('Unexpected ' + token.type, token); | ||
return this._error(`Unexpected ${token.type}`, token); | ||
} | ||
@@ -796,7 +796,7 @@ // Without explicit quantifiers, map entities to a quantified entity | ||
default: | ||
var stack = this._contextStack, parent = stack.length && stack[stack.length - 1]; | ||
const stack = this._contextStack, parent = stack.length && stack[stack.length - 1]; | ||
// If we were reading a list item, we still need to output it | ||
if (parent && parent.type === 'item') { | ||
// The list item is the remaining subejct after reading the path | ||
var item = this._subject; | ||
const item = this._subject; | ||
// Switch back to the context of the list | ||
@@ -813,3 +813,4 @@ this._restoreContext(); | ||
_readForwardPath(token) { | ||
var subject, predicate, object = this._blankNode(); | ||
let subject, predicate; | ||
const object = this._blankNode(); | ||
// The next token is the predicate | ||
@@ -831,3 +832,4 @@ if ((predicate = this._readEntity(token)) === undefined) | ||
_readBackwardPath(token) { | ||
var subject = this._blankNode(), predicate, object; | ||
const subject = this._blankNode(); | ||
let predicate, object; | ||
// The next token is the predicate | ||
@@ -853,3 +855,3 @@ if ((predicate = this._readEntity(token)) === undefined) | ||
return this._readRDFStarTail; | ||
return this._error('Expected >> to follow "' + this._object.id + '"', token); | ||
return this._error(`Expected >> to follow "${this._object.id}"`, token); | ||
} | ||
@@ -881,3 +883,3 @@ return this._readRDFStarTail(token); | ||
_getContextEndReader() { | ||
var contextStack = this._contextStack; | ||
const contextStack = this._contextStack; | ||
if (!contextStack.length) | ||
@@ -905,3 +907,3 @@ return this._readPunctuation; | ||
_error(message, token) { | ||
var err = new Error(message + ' on line ' + token.line + '.'); | ||
const err = new Error(`${message} on line ${token.line}.`); | ||
err.context = { | ||
@@ -951,3 +953,4 @@ token: token, | ||
// Start with an imaginary slash before the IRI in order to resolve trailing './' and '../' | ||
var result = '', length = iri.length, i = -1, pathStart = -1, segmentStart = 0, next = '/'; | ||
const length = iri.length; | ||
let result = '', i = -1, pathStart = -1, segmentStart = 0, next = '/'; | ||
@@ -996,3 +999,3 @@ while (i < length) { | ||
if (next !== '/') | ||
return result + '/' + iri.substr(i + 1); | ||
return `${result}/${iri.substr(i + 1)}`; | ||
segmentStart = i + 1; | ||
@@ -1012,3 +1015,2 @@ } | ||
parse(input, quadCallback, prefixCallback) { | ||
var self = this; | ||
// The read callback is the next function to be executed when a token arrives. | ||
@@ -1020,3 +1022,3 @@ // We start reading in the top context. | ||
this._prefixes._ = this._blankNodePrefix ? this._blankNodePrefix.substr(2) | ||
: 'b' + blankNodePrefix++ + '_'; | ||
: `b${blankNodePrefix++}_`; | ||
this._prefixCallback = prefixCallback || noop; | ||
@@ -1028,6 +1030,7 @@ this._inversePredicate = false; | ||
if (!quadCallback) { | ||
var quads = [], error; | ||
this._callback = function (e, t) { e ? (error = e) : t && quads.push(t); }; | ||
this._lexer.tokenize(input).every(function (token) { | ||
return self._readCallback = self._readCallback(token); | ||
const quads = []; | ||
let error; | ||
this._callback = (e, t) => { e ? (error = e) : t && quads.push(t); }; | ||
this._lexer.tokenize(input).every(token => { | ||
return this._readCallback = this._readCallback(token); | ||
}); | ||
@@ -1040,7 +1043,7 @@ if (error) throw error; | ||
this._callback = quadCallback; | ||
this._lexer.tokenize(input, function (error, token) { | ||
this._lexer.tokenize(input, (error, token) => { | ||
if (error !== null) | ||
self._callback(error), self._callback = noop; | ||
else if (self._readCallback) | ||
self._readCallback = self._readCallback(token); | ||
this._callback(error), this._callback = noop; | ||
else if (this._readCallback) | ||
this._readCallback = this._readCallback(token); | ||
}); | ||
@@ -1056,3 +1059,3 @@ } | ||
// Set factory methods | ||
var namedNode = factory.namedNode; | ||
const namedNode = factory.namedNode; | ||
parser._namedNode = namedNode; | ||
@@ -1059,0 +1062,0 @@ parser._blankNode = factory.blankNode; |
@@ -38,3 +38,3 @@ // **N3Store** objects store N3 quads by graph in memory. | ||
// Return the quad count if if was cached | ||
var size = this._size; | ||
let size = this._size; | ||
if (size !== null) | ||
@@ -45,6 +45,7 @@ return size; | ||
size = 0; | ||
var graphs = this._graphs, subjects, subject; | ||
for (var graphKey in graphs) | ||
for (var subjectKey in (subjects = graphs[graphKey].subjects)) | ||
for (var predicateKey in (subject = subjects[subjectKey])) | ||
const graphs = this._graphs; | ||
let subjects, subject; | ||
for (const graphKey in graphs) | ||
for (const subjectKey in (subjects = graphs[graphKey].subjects)) | ||
for (const predicateKey in (subject = subjects[subjectKey])) | ||
size += Object.keys(subject[predicateKey]).length; | ||
@@ -60,6 +61,6 @@ return this._size = size; | ||
// Create layers as necessary | ||
var index1 = index0[key0] || (index0[key0] = {}); | ||
var index2 = index1[key1] || (index1[key1] = {}); | ||
const index1 = index0[key0] || (index0[key0] = {}); | ||
const index2 = index1[key1] || (index1[key1] = {}); | ||
// Setting the key to _any_ value signals the presence of the quad | ||
var existed = key2 in index2; | ||
const existed = key2 in index2; | ||
if (!existed) | ||
@@ -73,9 +74,9 @@ index2[key2] = null; | ||
// Remove the quad from the index | ||
var index1 = index0[key0], index2 = index1[key1], key; | ||
const index1 = index0[key0], index2 = index1[key1]; | ||
delete index2[key2]; | ||
// Remove intermediary index layers if they are empty | ||
for (key in index2) return; | ||
for (const key in index2) return; | ||
delete index1[key1]; | ||
for (key in index1) return; | ||
for (const key in index1) return; | ||
delete index0[key0]; | ||
@@ -95,4 +96,5 @@ } | ||
_findInIndex(index0, key0, key1, key2, name0, name1, name2, graph, callback, array) { | ||
var tmp, index1, index2, varCount = !key0 + !key1 + !key2, | ||
// depending on the number of variables, keys or reverse index are faster | ||
let tmp, index1, index2; | ||
// Depending on the number of variables, keys or reverse index are faster | ||
const varCount = !key0 + !key1 + !key2, | ||
entityKeys = varCount > 1 ? Object.keys(this._ids) : this._entities; | ||
@@ -102,4 +104,4 @@ | ||
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0]; | ||
for (var value0 in index0) { | ||
var entity0 = entityKeys[value0]; | ||
for (const value0 in index0) { | ||
const entity0 = entityKeys[value0]; | ||
@@ -109,15 +111,15 @@ if (index1 = index0[value0]) { | ||
if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1]; | ||
for (var value1 in index1) { | ||
var entity1 = entityKeys[value1]; | ||
for (const value1 in index1) { | ||
const entity1 = entityKeys[value1]; | ||
if (index2 = index1[value1]) { | ||
// If a key is specified, use only that part of index 2, if it exists. | ||
var values = key2 ? (key2 in index2 ? [key2] : []) : Object.keys(index2); | ||
const values = key2 ? (key2 in index2 ? [key2] : []) : Object.keys(index2); | ||
// Create quads for all items found in index 2. | ||
for (var l = 0; l < values.length; l++) { | ||
var parts = { subject: null, predicate: null, object: null }; | ||
for (let l = 0; l < values.length; l++) { | ||
const parts = { subject: null, predicate: null, object: null }; | ||
parts[name0] = termFromId(entity0, this._factory); | ||
parts[name1] = termFromId(entity1, this._factory); | ||
parts[name2] = termFromId(entityKeys[values[l]], this._factory); | ||
var quad = this._factory.quad( | ||
const quad = this._factory.quad( | ||
parts.subject, parts.predicate, parts.object, termFromId(graph, this._factory)); | ||
@@ -138,3 +140,3 @@ if (array) | ||
_loop(index0, callback) { | ||
for (var key0 in index0) | ||
for (const key0 in index0) | ||
callback(key0); | ||
@@ -145,3 +147,3 @@ } | ||
_loopByKey0(index0, key0, callback) { | ||
var index1, key1; | ||
let index1, key1; | ||
if (index1 = index0[key0]) { | ||
@@ -155,3 +157,3 @@ for (key1 in index1) | ||
_loopByKey1(index0, key1, callback) { | ||
var key0, index1; | ||
let key0, index1; | ||
for (key0 in index0) { | ||
@@ -166,3 +168,3 @@ index1 = index0[key0]; | ||
_loopBy2Keys(index0, key0, key1, callback) { | ||
var index1, index2, key2; | ||
let index1, index2, key2; | ||
if ((index1 = index0[key0]) && (index2 = index1[key1])) { | ||
@@ -178,11 +180,11 @@ for (key2 in index2) | ||
_countInIndex(index0, key0, key1, key2) { | ||
var count = 0, tmp, index1, index2; | ||
let count = 0, tmp, index1, index2; | ||
// If a key is specified, count only that part of index 0 | ||
if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0]; | ||
for (var value0 in index0) { | ||
for (const value0 in index0) { | ||
if (index1 = index0[value0]) { | ||
// If a key is specified, count only that part of index 1 | ||
if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1]; | ||
for (var value1 in index1) { | ||
for (const value1 in index1) { | ||
if (index2 = index1[value1]) { | ||
@@ -205,3 +207,3 @@ // If a key is specified, count the quad if it exists | ||
return this._graphs; | ||
var graphs = {}; | ||
const graphs = {}; | ||
graphs[graph] = this._graphs[graph]; | ||
@@ -214,7 +216,7 @@ return graphs; | ||
_uniqueEntities(callback) { | ||
var uniqueIds = Object.create(null), entities = this._entities; | ||
return function (id) { | ||
const uniqueIds = Object.create(null); | ||
return id => { | ||
if (!(id in uniqueIds)) { | ||
uniqueIds[id] = true; | ||
callback(termFromId(entities[id])); | ||
callback(termFromId(this._entities[id], this._factory)); | ||
} | ||
@@ -241,3 +243,3 @@ }; | ||
// Find the graph that will contain the triple | ||
var graphItem = this._graphs[graph]; | ||
let graphItem = this._graphs[graph]; | ||
// Create the graph if it doesn't exist yet | ||
@@ -254,4 +256,4 @@ if (!graphItem) { | ||
// which are then used as keys in the other indexes. | ||
var ids = this._ids; | ||
var entities = this._entities; | ||
const ids = this._ids; | ||
const entities = this._entities; | ||
subject = ids[subject] || (ids[entities[++this._id] = subject] = this._id); | ||
@@ -261,3 +263,3 @@ predicate = ids[predicate] || (ids[entities[++this._id] = predicate] = this._id); | ||
var changed = this._addToIndex(graphItem.subjects, subject, predicate, object); | ||
const changed = this._addToIndex(graphItem.subjects, subject, predicate, object); | ||
this._addToIndex(graphItem.predicates, predicate, object, subject); | ||
@@ -273,3 +275,3 @@ this._addToIndex(graphItem.objects, object, subject, predicate); | ||
addQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) | ||
for (let i = 0; i < quads.length; i++) | ||
this.addQuad(quads[i]); | ||
@@ -280,4 +282,3 @@ } | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { self.addQuad(quad); }); | ||
stream.on('data', quad => { this.addQuad(quad); }); | ||
return stream; | ||
@@ -301,3 +302,4 @@ } | ||
// and verify the quad exists. | ||
var graphItem, ids = this._ids, graphs = this._graphs, subjects, predicates; | ||
const ids = this._ids, graphs = this._graphs; | ||
let graphItem, subjects, predicates; | ||
if (!(subject = ids[subject]) || !(predicate = ids[predicate]) || | ||
@@ -324,3 +326,3 @@ !(object = ids[object]) || !(graphItem = graphs[graph]) || | ||
removeQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) | ||
for (let i = 0; i < quads.length; i++) | ||
this.removeQuad(quads[i]); | ||
@@ -331,4 +333,3 @@ } | ||
remove(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { self.removeQuad(quad); }); | ||
stream.on('data', quad => { this.removeQuad(quad); }); | ||
return stream; | ||
@@ -357,4 +358,4 @@ } | ||
var quads = [], graphs = this._getGraphs(graph), content, | ||
ids = this._ids, subjectId, predicateId, objectId; | ||
const quads = [], graphs = this._getGraphs(graph), ids = this._ids; | ||
let content, subjectId, predicateId, objectId; | ||
@@ -367,3 +368,3 @@ // Translate IRIs to internal index keys. | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -402,7 +403,7 @@ if (content = graphs[graphId]) { | ||
match(subject, predicate, object, graph) { | ||
var stream = new Readable({ objectMode: true }); | ||
const stream = new Readable({ objectMode: true }); | ||
// Initialize stream once it is being read | ||
stream._read = () => { | ||
for (var quad of this.getQuads(subject, predicate, object, graph)) | ||
for (const quad of this.getQuads(subject, predicate, object, graph)) | ||
stream.push(quad); | ||
@@ -424,4 +425,4 @@ stream.push(null); | ||
var count = 0, graphs = this._getGraphs(graph), content, | ||
ids = this._ids, subjectId, predicateId, objectId; | ||
const graphs = this._getGraphs(graph), ids = this._ids; | ||
let count = 0, content, subjectId, predicateId, objectId; | ||
@@ -434,3 +435,3 @@ // Translate IRIs to internal index keys. | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -463,3 +464,3 @@ if (content = graphs[graphId]) { | ||
forEach(callback, subject, predicate, object, graph) { | ||
this.some(function (quad) { | ||
this.some(quad => { | ||
callback(quad); | ||
@@ -474,4 +475,4 @@ return false; | ||
every(callback, subject, predicate, object, graph) { | ||
var some = false; | ||
var every = !this.some(function (quad) { | ||
let some = false; | ||
const every = !this.some(quad => { | ||
some = true; | ||
@@ -493,4 +494,4 @@ return !callback(quad); | ||
var graphs = this._getGraphs(graph), content, | ||
ids = this._ids, subjectId, predicateId, objectId; | ||
const graphs = this._getGraphs(graph), ids = this._ids; | ||
let content, subjectId, predicateId, objectId; | ||
@@ -503,3 +504,3 @@ // Translate IRIs to internal index keys. | ||
for (var graphId in graphs) { | ||
for (const graphId in graphs) { | ||
// Only if the specified graph contains triples, there can be results | ||
@@ -549,4 +550,4 @@ if (content = graphs[graphId]) { | ||
getSubjects(predicate, object, graph) { | ||
var results = []; | ||
this.forSubjects(function (s) { results.push(s); }, predicate, object, graph); | ||
const results = []; | ||
this.forSubjects(s => { results.push(s); }, predicate, object, graph); | ||
return results; | ||
@@ -563,3 +564,4 @@ } | ||
var ids = this._ids, graphs = this._getGraphs(graph), content, predicateId, objectId; | ||
const ids = this._ids, graphs = this._getGraphs(graph); | ||
let content, predicateId, objectId; | ||
callback = this._uniqueEntities(callback); | ||
@@ -597,4 +599,4 @@ | ||
getPredicates(subject, object, graph) { | ||
var results = []; | ||
this.forPredicates(function (p) { results.push(p); }, subject, object, graph); | ||
const results = []; | ||
this.forPredicates(p => { results.push(p); }, subject, object, graph); | ||
return results; | ||
@@ -611,3 +613,4 @@ } | ||
var ids = this._ids, graphs = this._getGraphs(graph), content, subjectId, objectId; | ||
const ids = this._ids, graphs = this._getGraphs(graph); | ||
let content, subjectId, objectId; | ||
callback = this._uniqueEntities(callback); | ||
@@ -645,4 +648,4 @@ | ||
getObjects(subject, predicate, graph) { | ||
var results = []; | ||
this.forObjects(function (o) { results.push(o); }, subject, predicate, graph); | ||
const results = []; | ||
this.forObjects(o => { results.push(o); }, subject, predicate, graph); | ||
return results; | ||
@@ -659,3 +662,4 @@ } | ||
var ids = this._ids, graphs = this._getGraphs(graph), content, subjectId, predicateId; | ||
const ids = this._ids, graphs = this._getGraphs(graph); | ||
let content, subjectId, predicateId; | ||
callback = this._uniqueEntities(callback); | ||
@@ -693,4 +697,4 @@ | ||
getGraphs(subject, predicate, object) { | ||
var results = []; | ||
this.forGraphs(function (g) { results.push(g); }, subject, predicate, object); | ||
const results = []; | ||
this.forGraphs(g => { results.push(g); }, subject, predicate, object); | ||
return results; | ||
@@ -702,4 +706,4 @@ } | ||
forGraphs(callback, subject, predicate, object) { | ||
for (var graph in this._graphs) { | ||
this.some(function (quad) { | ||
for (const graph in this._graphs) { | ||
this.some(quad => { | ||
callback(quad.graph); | ||
@@ -713,6 +717,6 @@ return true; // Halt iteration of some() | ||
createBlankNode(suggestedName) { | ||
var name, index; | ||
let name, index; | ||
// Generate a name based on the suggested name | ||
if (suggestedName) { | ||
name = suggestedName = '_:' + suggestedName, index = 1; | ||
name = suggestedName = `_:${suggestedName}`, index = 1; | ||
while (this._ids[name]) | ||
@@ -723,3 +727,3 @@ name = suggestedName + index++; | ||
else { | ||
do { name = '_:b' + this._blankNodeIndex++; } | ||
do { name = `_:b${this._blankNodeIndex++}`; } | ||
while (this._ids[name]); | ||
@@ -736,25 +740,25 @@ } | ||
extractLists({ remove = false, ignoreErrors = false } = {}) { | ||
var lists = {}; // has scalar keys so could be a simple Object | ||
var onError = ignoreErrors ? (() => true) : | ||
const lists = {}; // has scalar keys so could be a simple Object | ||
const onError = ignoreErrors ? (() => true) : | ||
((node, message) => { throw new Error(`${node.value} ${message}`); }); | ||
// Traverse each list from its tail | ||
var tails = this.getQuads(null, namespaces.rdf.rest, namespaces.rdf.nil, null); | ||
var toRemove = remove ? [...tails] : []; | ||
const tails = this.getQuads(null, namespaces.rdf.rest, namespaces.rdf.nil, null); | ||
const toRemove = remove ? [...tails] : []; | ||
tails.forEach(tailQuad => { | ||
var items = []; // the members found as objects of rdf:first quads | ||
var malformed = false; // signals whether the current list is malformed | ||
var head; // the head of the list (_:b1 in above example) | ||
var headPos; // set to subject or object when head is set | ||
var graph = tailQuad.graph; // make sure list is in exactly one graph | ||
const items = []; // the members found as objects of rdf:first quads | ||
let malformed = false; // signals whether the current list is malformed | ||
let head; // the head of the list (_:b1 in above example) | ||
let headPos; // set to subject or object when head is set | ||
const graph = tailQuad.graph; // make sure list is in exactly one graph | ||
// Traverse the list from tail to end | ||
var current = tailQuad.subject; | ||
let current = tailQuad.subject; | ||
while (current && !malformed) { | ||
var objectQuads = this.getQuads(null, null, current, null); | ||
var subjectQuads = this.getQuads(current, null, null, null); | ||
var i, quad, first = null, rest = null, parent = null; | ||
const objectQuads = this.getQuads(null, null, current, null); | ||
const subjectQuads = this.getQuads(current, null, null, null); | ||
let quad, first = null, rest = null, parent = null; | ||
// Find the first and rest of this list node | ||
for (i = 0; i < subjectQuads.length && !malformed; i++) { | ||
for (let i = 0; i < subjectQuads.length && !malformed; i++) { | ||
quad = subjectQuads[i]; | ||
@@ -793,3 +797,3 @@ if (!quad.graph.equals(graph)) | ||
// { (1 2) :p :o } arrives here with head set to the list. | ||
for (i = 0; i < objectQuads.length && !malformed; ++i) { | ||
for (let i = 0; i < objectQuads.length && !malformed; ++i) { | ||
quad = objectQuads[i]; | ||
@@ -796,0 +800,0 @@ if (head) |
@@ -12,5 +12,6 @@ // **N3StreamParser** parses a text stream into a quad stream. | ||
// Set up parser with dummy stream to obtain `data` and `end` callbacks | ||
var self = this, parser = new N3Parser(options), onData, onEnd; | ||
const parser = new N3Parser(options); | ||
let onData, onEnd; | ||
parser.parse({ | ||
on: function (event, callback) { | ||
on: (event, callback) => { | ||
switch (event) { | ||
@@ -23,10 +24,10 @@ case 'data': onData = callback; break; | ||
// Handle quads by pushing them down the pipeline | ||
function (error, quad) { error && self.emit('error', error) || quad && self.push(quad); }, | ||
(error, quad) => { error && this.emit('error', error) || quad && this.push(quad); }, | ||
// Emit prefixes through the `prefix` event | ||
function (prefix, uri) { self.emit('prefix', prefix, uri); } | ||
(prefix, uri) => { this.emit('prefix', prefix, uri); } | ||
); | ||
// Implement Transform methods through parser callbacks | ||
this._transform = function (chunk, encoding, done) { onData(chunk); done(); }; | ||
this._flush = function (done) { onEnd(); done(); }; | ||
this._transform = (chunk, encoding, done) => { onData(chunk); done(); }; | ||
this._flush = done => { onEnd(); done(); }; | ||
} | ||
@@ -36,8 +37,7 @@ | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (chunk) { self.write(chunk); }); | ||
stream.on('end', function () { self.end(); }); | ||
stream.on('error', function (error) { self.emit('error', error); }); | ||
stream.on('data', chunk => { this.write(chunk); }); | ||
stream.on('end', () => { this.end(); }); | ||
stream.on('error', error => { this.emit('error', error); }); | ||
return this; | ||
} | ||
} |
@@ -12,11 +12,10 @@ // **N3StreamWriter** serializes a quad stream into a text stream. | ||
// Set up writer with a dummy stream object | ||
var self = this; | ||
var writer = this._writer = new N3Writer({ | ||
write: function (quad, encoding, callback) { self.push(quad); callback && callback(); }, | ||
end: function (callback) { self.push(null); callback && callback(); }, | ||
const writer = this._writer = new N3Writer({ | ||
write: (quad, encoding, callback) => { this.push(quad); callback && callback(); }, | ||
end: callback => { this.push(null); callback && callback(); }, | ||
}, options); | ||
// Implement Transform methods on top of writer | ||
this._transform = function (quad, encoding, done) { writer.addQuad(quad, done); }; | ||
this._flush = function (done) { writer.end(done); }; | ||
this._transform = (quad, encoding, done) => { writer.addQuad(quad, done); }; | ||
this._flush = done => { writer.end(done); }; | ||
} | ||
@@ -26,9 +25,8 @@ | ||
import(stream) { | ||
var self = this; | ||
stream.on('data', function (quad) { self.write(quad); }); | ||
stream.on('end', function () { self.end(); }); | ||
stream.on('error', function (error) { self.emit('error', error); }); | ||
stream.on('prefix', function (prefix, iri) { self._writer.addPrefix(prefix, iri); }); | ||
stream.on('data', quad => { this.write(quad); }); | ||
stream.on('end', () => { this.end(); }); | ||
stream.on('error', error => { this.emit('error', error); }); | ||
stream.on('prefix', (prefix, iri) => { this._writer.addPrefix(prefix, iri); }); | ||
return this; | ||
} | ||
} |
@@ -43,4 +43,4 @@ // **N3Util** provides N3 utility functions. | ||
// Add all of the default prefixes | ||
var prefixes = Object.create(null); | ||
for (var prefix in defaultPrefixes) | ||
const prefixes = Object.create(null); | ||
for (const prefix in defaultPrefixes) | ||
processPrefix(prefix, defaultPrefixes[prefix]); | ||
@@ -56,4 +56,4 @@ // Set the default factory if none was specified | ||
// Create a function that expands the prefix | ||
var cache = Object.create(null); | ||
prefixes[prefix] = function (local) { | ||
const cache = Object.create(null); | ||
prefixes[prefix] = local => { | ||
return cache[local] || (cache[local] = factory.namedNode(iri + local)); | ||
@@ -63,3 +63,3 @@ }; | ||
else if (!(prefix in prefixes)) { | ||
throw new Error('Unknown prefix: ' + prefix); | ||
throw new Error(`Unknown prefix: ${prefix}`); | ||
} | ||
@@ -66,0 +66,0 @@ return prefixes[prefix]; |
@@ -11,3 +11,3 @@ // **N3Writer** writes N3 documents. | ||
// Characters in literals that require escaping | ||
var escape = /["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/, | ||
const escape = /["\\\t\n\r\b\f\u0000-\u0019\ud800-\udbff]/, | ||
escapeAll = /["\\\t\n\r\b\f\u0000-\u0019]|[\ud800-\udbff][\udc00-\udfff]/g, | ||
@@ -42,6 +42,6 @@ escapedCharacters = { | ||
if (!outputStream) { | ||
var output = ''; | ||
let output = ''; | ||
this._outputStream = { | ||
write(chunk, encoding, done) { output += chunk; done && done(); }, | ||
end: function (done) { done && done(null, output); }, | ||
end: done => { done && done(null, output); }, | ||
}; | ||
@@ -86,3 +86,3 @@ this._endStream = true; | ||
this._write((this._subject === null ? '' : (this._inDefaultGraph ? '.\n' : '\n}\n')) + | ||
(DEFAULTGRAPH.equals(graph) ? '' : this._encodeIriOrBlank(graph) + ' {\n')); | ||
(DEFAULTGRAPH.equals(graph) ? '' : `${this._encodeIriOrBlank(graph)} {\n`)); | ||
this._graph = graph; | ||
@@ -95,15 +95,15 @@ this._subject = null; | ||
if (predicate.equals(this._predicate)) | ||
this._write(', ' + this._encodeObject(object), done); | ||
this._write(`, ${this._encodeObject(object)}`, done); | ||
// Same subject, different predicate | ||
else | ||
this._write(';\n ' + | ||
this._encodePredicate(this._predicate = predicate) + ' ' + | ||
this._encodeObject(object), done); | ||
this._write(`;\n ${ | ||
this._encodePredicate(this._predicate = predicate)} ${ | ||
this._encodeObject(object)}`, done); | ||
} | ||
// Different subject; write the whole quad | ||
else | ||
this._write((this._subject === null ? '' : '.\n') + | ||
this._encodeSubject(this._subject = subject) + ' ' + | ||
this._encodePredicate(this._predicate = predicate) + ' ' + | ||
this._encodeObject(object), done); | ||
this._write(`${(this._subject === null ? '' : '.\n') + | ||
this._encodeSubject(this._subject = subject)} ${ | ||
this._encodePredicate(this._predicate = predicate)} ${ | ||
this._encodeObject(object)}`, done); | ||
} | ||
@@ -122,6 +122,6 @@ catch (error) { done && done(error); } | ||
quadToString(subject, predicate, object, graph) { | ||
return this._encodeSubject(subject) + ' ' + | ||
this._encodeIriOrBlank(predicate) + ' ' + | ||
this._encodeObject(object) + | ||
(graph && graph.value ? ' ' + this._encodeIriOrBlank(graph) + ' .\n' : ' .\n'); | ||
return `${this._encodeSubject(subject)} ${ | ||
this._encodeIriOrBlank(predicate)} ${ | ||
this._encodeObject(object) | ||
}${graph && graph.value ? ` ${this._encodeIriOrBlank(graph)} .\n` : ' .\n'}`; | ||
} | ||
@@ -131,5 +131,5 @@ | ||
quadsToString(quads) { | ||
return quads.map(function (t) { | ||
return quads.map(t => { | ||
return this.quadToString(t.subject, t.predicate, t.object, t.graph); | ||
}, this).join(''); | ||
}).join(''); | ||
} | ||
@@ -150,11 +150,11 @@ | ||
entity = this.list(this._lists[entity.value]); | ||
return 'id' in entity ? entity.id : '_:' + entity.value; | ||
return 'id' in entity ? entity.id : `_:${entity.value}`; | ||
} | ||
// Escape special characters | ||
var iri = entity.value; | ||
let iri = entity.value; | ||
if (escape.test(iri)) | ||
iri = iri.replace(escapeAll, characterReplacer); | ||
// Try to represent the IRI as prefixed name | ||
var prefixMatch = this._prefixRegex.exec(iri); | ||
return !prefixMatch ? '<' + iri + '>' : | ||
const prefixMatch = this._prefixRegex.exec(iri); | ||
return !prefixMatch ? `<${iri}>` : | ||
(!prefixMatch[1] ? iri : this._prefixIRIs[prefixMatch[1]] + prefixMatch[2]); | ||
@@ -166,3 +166,3 @@ } | ||
// Escape special characters | ||
var value = literal.value; | ||
let value = literal.value; | ||
if (escape.test(value)) | ||
@@ -172,7 +172,7 @@ value = value.replace(escapeAll, characterReplacer); | ||
if (literal.language) | ||
return '"' + value + '"@' + literal.language; | ||
return `"${value}"@${literal.language}`; | ||
else if (literal.datatype.value !== xsd.string) | ||
return '"' + value + '"^^' + this._encodeIriOrBlank(literal.datatype); | ||
return `"${value}"^^${this._encodeIriOrBlank(literal.datatype)}`; | ||
else | ||
return '"' + value + '"'; | ||
return `"${value}"`; | ||
} | ||
@@ -226,3 +226,3 @@ | ||
addQuads(quads) { | ||
for (var i = 0; i < quads.length; i++) | ||
for (let i = 0; i < quads.length; i++) | ||
this.addQuad(quads[i]); | ||
@@ -233,3 +233,3 @@ } | ||
addPrefix(prefix, iri, done) { | ||
var prefixes = {}; | ||
const prefixes = {}; | ||
prefixes[prefix] = iri; | ||
@@ -241,5 +241,10 @@ this.addPrefixes(prefixes, done); | ||
addPrefixes(prefixes, done) { | ||
var prefixIRIs = this._prefixIRIs, hasPrefixes = false; | ||
for (var prefix in prefixes) { | ||
var iri = prefixes[prefix]; | ||
// Ignore prefixes if not supported by the serialization | ||
if (!this._prefixIRIs) | ||
return done && done(); | ||
// Write all new prefixes | ||
let hasPrefixes = false; | ||
for (let prefix in prefixes) { | ||
let iri = prefixes[prefix]; | ||
if (typeof iri !== 'string') | ||
@@ -254,15 +259,15 @@ iri = iri.value; | ||
// Store and write the prefix | ||
prefixIRIs[iri] = (prefix += ':'); | ||
this._write('@prefix ' + prefix + ' <' + iri + '>.\n'); | ||
this._prefixIRIs[iri] = (prefix += ':'); | ||
this._write(`@prefix ${prefix} <${iri}>.\n`); | ||
} | ||
// Recreate the prefix matcher | ||
if (hasPrefixes) { | ||
var IRIlist = '', prefixList = ''; | ||
for (var prefixIRI in prefixIRIs) { | ||
IRIlist += IRIlist ? '|' + prefixIRI : prefixIRI; | ||
prefixList += (prefixList ? '|' : '') + prefixIRIs[prefixIRI]; | ||
let IRIlist = '', prefixList = ''; | ||
for (const prefixIRI in this._prefixIRIs) { | ||
IRIlist += IRIlist ? `|${prefixIRI}` : prefixIRI; | ||
prefixList += (prefixList ? '|' : '') + this._prefixIRIs[prefixIRI]; | ||
} | ||
IRIlist = IRIlist.replace(/[\]\/\(\)\*\+\?\.\\\$]/g, '\\$&'); | ||
this._prefixRegex = new RegExp('^(?:' + prefixList + ')[^\/]*$|' + | ||
'^(' + IRIlist + ')([a-zA-Z][\\-_a-zA-Z0-9]*)$'); | ||
this._prefixRegex = new RegExp(`^(?:${prefixList})[^\/]*$|` + | ||
`^(${IRIlist})([a-zA-Z][\\-_a-zA-Z0-9]*)$`); | ||
} | ||
@@ -275,3 +280,3 @@ // End a prefix block with a newline | ||
blank(predicate, object) { | ||
var children = predicate, child, length; | ||
let children = predicate, child, length; | ||
// Empty blank node | ||
@@ -295,22 +300,22 @@ if (predicate === undefined) | ||
if (!(child.object instanceof SerializedTerm)) | ||
return new SerializedTerm('[ ' + this._encodePredicate(child.predicate) + ' ' + | ||
this._encodeObject(child.object) + ' ]'); | ||
return new SerializedTerm(`[ ${this._encodePredicate(child.predicate)} ${ | ||
this._encodeObject(child.object)} ]`); | ||
// Generate a multi-triple or nested blank node | ||
default: | ||
var contents = '['; | ||
let contents = '['; | ||
// Write all triples in order | ||
for (var i = 0; i < length; i++) { | ||
for (let i = 0; i < length; i++) { | ||
child = children[i]; | ||
// Write only the object is the predicate is the same as the previous | ||
if (child.predicate.equals(predicate)) | ||
contents += ', ' + this._encodeObject(child.object); | ||
contents += `, ${this._encodeObject(child.object)}`; | ||
// Otherwise, write the predicate and the object | ||
else { | ||
contents += (i ? ';\n ' : '\n ') + | ||
this._encodePredicate(child.predicate) + ' ' + | ||
this._encodeObject(child.object); | ||
contents += `${(i ? ';\n ' : '\n ') + | ||
this._encodePredicate(child.predicate)} ${ | ||
this._encodeObject(child.object)}`; | ||
predicate = child.predicate; | ||
} | ||
} | ||
return new SerializedTerm(contents + '\n]'); | ||
return new SerializedTerm(`${contents}\n]`); | ||
} | ||
@@ -321,6 +326,6 @@ } | ||
list(elements) { | ||
var length = elements && elements.length || 0, contents = new Array(length); | ||
for (var i = 0; i < length; i++) | ||
const length = elements && elements.length || 0, contents = new Array(length); | ||
for (let i = 0; i < length; i++) | ||
contents[i] = this._encodeObject(elements[i]); | ||
return new SerializedTerm('(' + contents.join(' ') + ')'); | ||
return new SerializedTerm(`(${contents.join(' ')})`); | ||
} | ||
@@ -339,3 +344,3 @@ | ||
// Try to end the underlying stream, ensuring done is called exactly one time | ||
var singleDone = done && function (error, result) { singleDone = null, done(error, result); }; | ||
let singleDone = done && ((error, result) => { singleDone = null, done(error, result); }); | ||
if (this._endStream) { | ||
@@ -352,3 +357,3 @@ try { return this._outputStream.end(singleDone); } | ||
// Replace a single character by its escaped version | ||
var result = escapedCharacters[character]; | ||
let result = escapedCharacters[character]; | ||
if (result === undefined) { | ||
@@ -355,0 +360,0 @@ // Replace a single character with its 4-bit unicode escape sequence |
262902
5596