Skip to content

Commit e37b4df

Browse files
MPvHarmelenRubenVerborgh
authored andcommitted
Support passing NamedNode to prefix function.
Closes #247.
1 parent c26a5ba commit e37b4df

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/N3Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function inDefaultGraph(quad) {
3434

3535
// Creates a function that prepends the given IRI to a local name
3636
export function prefix(iri, factory) {
37-
return prefixes({ '': iri }, factory)('');
37+
return prefixes({ '': iri.value || iri }, factory)('');
3838
}
3939

4040
// Creates a function that allows registering and expanding prefixes

test/N3Util-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ describe('Util', () => {
190190
expect(rdfs('label')).to.deep.equal(namedNode('http://www.w3.org/2000/01/rdf-schema#label'));
191191
});
192192

193+
it('should expand a NamedNode prefix', () => {
194+
const rdfs = Util.prefix(namedNode('http://www.w3.org/2000/01/rdf-schema#'));
195+
expect(rdfs('label')).to.deep.equal(namedNode('http://www.w3.org/2000/01/rdf-schema#label'));
196+
});
197+
198+
it('should expand a Literal prefix', () => {
199+
const rdfs = Util.prefix(literal('http://www.w3.org/2000/01/rdf-schema#'));
200+
expect(rdfs('label')).to.deep.equal(namedNode('http://www.w3.org/2000/01/rdf-schema#label'));
201+
});
202+
193203
it('should use a custom factory when specified', () => {
194204
const factory = { namedNode: function (s) { return `n-${s}`; } };
195205
const rdfs = Util.prefix('http://www.w3.org/2000/01/rdf-schema#', factory);

0 commit comments

Comments
 (0)