@rdfjs/to-ntriples
Advanced tools
Comparing version 1.0.2 to 2.0.0
49
index.js
@@ -1,7 +0,46 @@ | ||
const quad = require('./lib/quad') | ||
const term = require('./lib/term') | ||
const blankNode = require('./lib/blankNode.js') | ||
const dataset = require('./lib/dataset.js') | ||
const defaultGraph = require('./lib/defaultGraph.js') | ||
const literal = require('./lib/literal.js') | ||
const namedNode = require('./lib/namedNode.js') | ||
const quad = require('./lib/quad.js') | ||
const variable = require('./lib/variable.js') | ||
module.exports = { | ||
quadToNTriples: quad, | ||
termToNTriples: term | ||
function toNT (term) { | ||
if (!term) { | ||
return null | ||
} | ||
if (term.termType === 'BlankNode') { | ||
return blankNode(term) | ||
} | ||
if (term.termType === 'DefaultGraph') { | ||
return defaultGraph() | ||
} | ||
if (term.termType === 'Literal') { | ||
return literal(term) | ||
} | ||
if (term.termType === 'NamedNode') { | ||
return namedNode(term) | ||
} | ||
// legacy quad support without .termType | ||
if (term.termType === 'Quad' || (term.subject && term.predicate && term.object && term.graph)) { | ||
return quad(term, toNT) | ||
} | ||
if (term.termType === 'Variable') { | ||
return variable(term) | ||
} | ||
if (term[Symbol.iterator]) { | ||
return dataset(term, toNT) | ||
} | ||
throw new Error(`unknown termType ${term.termType}`) | ||
} | ||
module.exports = toNT |
@@ -1,2 +0,2 @@ | ||
function defaultGraph (defaultGraph) { | ||
function defaultGraph () { | ||
return '' | ||
@@ -3,0 +3,0 @@ } |
@@ -1,5 +0,5 @@ | ||
const namedNode = require('./namedNode') | ||
const namedNode = require('./namedNode.js') | ||
const echarRegEx = new RegExp('["\\\\\n\r]') // eslint-disable-line no-control-regex | ||
const echarRegExAll = new RegExp('["\\\\\n\r]', 'g') // eslint-disable-line no-control-regex | ||
const echarRegEx = /["\\\\\n\r]/ | ||
const echarRegExAll = /["\\\\\n\r]/g | ||
@@ -6,0 +6,0 @@ const echarReplacement = { |
function namedNode (namedNode) { | ||
return '<' + namedNode.value + '>' // TODO: escape special chars | ||
return '<' + namedNode.value + '>' | ||
} | ||
module.exports = namedNode |
@@ -1,9 +0,7 @@ | ||
const term = require('./term') | ||
function quad (quad, toNT) { | ||
const subjectString = toNT(quad.subject) | ||
const predicateString = toNT(quad.predicate) | ||
const objectString = toNT(quad.object) | ||
const graphString = toNT(quad.graph) | ||
function quad (quad) { | ||
const subjectString = term(quad.subject) | ||
const predicateString = term(quad.predicate) | ||
const objectString = term(quad.object) | ||
const graphString = term(quad.graph) | ||
return `${subjectString} ${predicateString} ${objectString} ${graphString ? graphString + ' ' : ''}.` | ||
@@ -10,0 +8,0 @@ } |
function variable (variable) { | ||
return '?' + variable.value // TODO: escape special chars | ||
return '?' + variable.value | ||
} | ||
module.exports = variable |
{ | ||
"name": "@rdfjs/to-ntriples", | ||
"version": "1.0.2", | ||
"description": "Converts RDFJS Terms and Quads to N-Triple strings", | ||
"version": "2.0.0", | ||
"description": "Converts RDF/JS Terms, Quads and Datasets to N-Triple strings", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && mocha" | ||
"coverage": "codecov", | ||
"test": "stricter-standard && c8 --reporter=lcov --reporter=text mocha" | ||
}, | ||
@@ -27,9 +28,8 @@ "repository": { | ||
"devDependencies": { | ||
"@rdfjs/data-model": "^1.0.1", | ||
"mocha": "^5.2.0", | ||
"standard": "^11.0.1" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
"@rdfjs/data-model": "^1.3.0", | ||
"c8": "^7.7.3", | ||
"codecov": "^3.8.2", | ||
"mocha": "^9.0.1", | ||
"stricter-standard": "^0.2.0" | ||
} | ||
} |
@@ -7,2 +7,40 @@ # @rdfjs/to-ntriples | ||
Converts [RDFJS](http://rdf.js.org/) Terms and Quads to N-Triple strings. | ||
Converts [RDF/JS](http://rdf.js.org/) Terms, Quads and Datasets to N-Triple strings. | ||
## Examples | ||
```javascript | ||
const rdf = require('@rdfjs/data-model') | ||
const toNT = require('@rdfjs/to-ntriples') | ||
// convert a Term/Literal to a N-Triple string (output: "example"@en) | ||
console.log(toNT(rdf.literal('example', 'en'))) | ||
// convert a Quad to a N-Triple string (output: _:b1 <http://example.org/predicate> "example" .) | ||
console.log(toNT(rdf.quad( | ||
rdf.blankNode(), | ||
rdf.namedNode('http://example.org/predicate'), | ||
rdf.literal('example') | ||
))) | ||
/* | ||
convert an Array/Dataset to a N-Triple string | ||
output: | ||
_:b2 <http://example.org/predicate> "1" . | ||
_:b3 <http://example.org/predicate> "2" . | ||
Any object with Symbol.iterator is supported | ||
*/ | ||
console.log(toNT([ | ||
rdf.quad( | ||
rdf.blankNode(), | ||
rdf.namedNode('http://example.org/predicate'), | ||
rdf.literal('1') | ||
), | ||
rdf.quad( | ||
rdf.blankNode(), | ||
rdf.namedNode('http://example.org/predicate'), | ||
rdf.literal('2') | ||
) | ||
])) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9523
46
5
12
196
1