Skip to content

Commit

Permalink
feat: return prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Jan 1, 2023
1 parent 22c9693 commit ecd23af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
19 changes: 11 additions & 8 deletions __tests__/Conformance-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ describe('Testing each extended conformance file', () => {
const shaclc = fs.readFileSync(path.join(__dirname, 'extended', file)).toString();
const ttl = fs.readFileSync(path.join(__dirname, 'extended', file.replace('.shaclc', '.ttl'))).toString();

expect(
(new Parser()).parse(shaclc, { extendedSyntax: true })
).toBeRdfIsomorphic(
(new N3.Parser()).parse(ttl)
)
const res = (new Parser()).parse(shaclc, { extendedSyntax: true });

expect(
() => (new Parser()).parse(shaclc)
).toThrowError();
expect(res).toBeRdfIsomorphic((new N3.Parser()).parse(ttl))
expect(res.prefixes).toEqual({
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
sh: 'http://www.w3.org/ns/shacl#',
xsd: 'http://www.w3.org/2001/XMLSchema#',
ex: 'http://example.org/test#'
})

expect(() => (new Parser()).parse(shaclc)).toThrowError();
});
});
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export interface ParseOptions {
extendedSyntax?: boolean;
}

export declare function parse(str: string, options?: ParseOptions): Quad[];
export declare function parse(str: string, options?: ParseOptions): Quad[] & { prefixes: Record<string, string> };
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Parser {
const arr = []
this._parser.Parser.onQuad = (quad) => { arr.push(quad) };
this._parser.parse(str);
arr.prefixes = this._parser.Parser.prefixes;
return arr;
}
}
Expand Down

0 comments on commit ecd23af

Please sign in to comment.