Skip to content

Commit 1fae88f

Browse files
dlongleydavidlehn
authored andcommitted
Add skipExpansion flag to toRdf and canonize.
1 parent 7067eb9 commit 1fae88f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# jsonld ChangeLog
22

3+
### Added
4+
- Add `skipExpansion` flag to `toRdf` and `canonize`.
5+
36
## 1.0.4 - 2018-08-17
47

58
### Fixed

lib/jsonld.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ jsonld.link = util.callbackify(async function(input, ctx, options) {
516516
* `URGNA2012` (default: `URGNA2012`).
517517
* [base] the base IRI to use.
518518
* [expandContext] a context to expand with.
519+
* [skipExpansion] true to assume the input is expanded and skip
520+
* expansion, false not to, defaults to false.
519521
* [inputFormat] the format if input is not JSON-LD:
520522
* 'application/n-quads' for N-Quads.
521523
* [format] the format if output is a string:
@@ -534,7 +536,8 @@ jsonld.normalize = jsonld.canonize = util.callbackify(async function(
534536
// set default options
535537
options = _setDefaults(options, {
536538
base: _isString(input) ? input : '',
537-
algorithm: 'URDNA2015'
539+
algorithm: 'URDNA2015',
540+
skipExpansion: false
538541
});
539542
if('inputFormat' in options) {
540543
if(options.inputFormat !== 'application/n-quads' &&
@@ -639,6 +642,8 @@ jsonld.fromRDF = util.callbackify(async function(dataset, options) {
639642
* @param [options] the options to use:
640643
* [base] the base IRI to use.
641644
* [expandContext] a context to expand with.
645+
* [skipExpansion] true to assume the input is expanded and skip
646+
* expansion, false not to, defaults to false.
642647
* [format] the format to use to output a string:
643648
* 'application/n-quads' for N-Quads.
644649
* [produceGeneralizedRdf] true to output generalized RDF, false
@@ -655,13 +660,18 @@ jsonld.toRDF = util.callbackify(async function(input, options) {
655660

656661
// set default options
657662
options = _setDefaults(options, {
658-
base: _isString(input) ? input : ''
663+
base: _isString(input) ? input : '',
664+
skipExpansion: false
659665
});
660666

661667
// TODO: support toRDF custom map?
662-
663-
// expand input
664-
const expanded = await jsonld.expand(input, options);
668+
let expanded;
669+
if(options.skipExpansion) {
670+
expanded = input;
671+
} else {
672+
// expand input
673+
expanded = await jsonld.expand(input, options);
674+
}
665675

666676
// output RDF dataset
667677
const dataset = _toRDF(expanded, options);

0 commit comments

Comments
 (0)