@@ -523,33 +523,39 @@ jsonld.link = async function(input, ctx, options) {
523523/**
524524 * Performs RDF dataset normalization on the given input. The input is JSON-LD
525525 * unless the 'inputFormat' option is used. The output is an RDF dataset
526- * unless the 'format' option is used.
526+ * unless a non-null 'format' option is used.
527527 *
528528 * Note: Canonicalization sets `safe` to `true` and `base` to `null` by
529529 * default in order to produce safe outputs and "fail closed" by default. This
530530 * is different from the other API transformations in this version which
531531 * allow unsafe defaults (for cryptographic usage) in order to comply with the
532532 * JSON-LD 1.1 specification.
533533 *
534- * @param input the input to normalize as JSON-LD or as a format specified by
535- * the 'inputFormat' option.
534+ * @param input the input to normalize as JSON-LD given as an RDF dataset or as
535+ * a format specified by the 'inputFormat' option.
536536 * @param [options] the options to use:
537- * [algorithm] the normalization algorithm to use, `URDNA2015` or
538- * `URGNA2012` (default: `URDNA2015`).
539537 * [base] the base IRI to use (default: `null`).
540538 * [expandContext] a context to expand with.
541539 * [skipExpansion] true to assume the input is expanded and skip
542540 * expansion, false not to, defaults to false. Some well-formed
543541 * and safe-mode checks may be omitted.
544- * [inputFormat] the format if input is not JSON-LD:
545- * 'application/n-quads' for N-Quads.
546- * [format] the format if output is a string:
547- * 'application/n-quads' for N-Quads.
542+ * [inputFormat] the input format. null for a JSON-LD object,
543+ * 'application/n-quads' for N-Quads. (default: null)
544+ * [format] the output format. null for an RDF dataset,
545+ * 'application/n-quads' for an N-Quads string. (default: N-Quads)
548546 * [documentLoader(url, options)] the document loader.
549- * [useNative] true to use a native canonize algorithm
550547 * [rdfDirection] null or 'i18n-datatype' to support RDF
551548 * transformation of @direction (default: null).
552549 * [safe] true to use safe mode. (default: true).
550+ * [canonizeOptions] options to pass to rdf-canonize canonize(). See
551+ * rdf-canonize for more details. Commonly used options, and their
552+ * defaults, are:
553+ * algorithm="RDFC-1.0",
554+ * messageDigestAlgorithm="sha256",
555+ * canonicalIdMap,
556+ * maxWorkFactor=1,
557+ * maxDeepIterations=-1,
558+ * and signal=null.
553559 * [contextResolver] internal use only.
554560 *
555561 * @return a Promise that resolves to the normalized output.
@@ -559,15 +565,19 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
559565 throw new TypeError ( 'Could not canonize, too few arguments.' ) ;
560566 }
561567
562- // set default options
568+ // set toRDF options
563569 options = _setDefaults ( options , {
564- base : _isString ( input ) ? input : null ,
565- algorithm : 'URDNA2015' ,
566570 skipExpansion : false ,
567571 safe : true ,
568572 contextResolver : new ContextResolver (
569573 { sharedCache : _resolvedContextCache } )
570574 } ) ;
575+
576+ // set canonize options
577+ const canonizeOptions = Object . assign ( { } , {
578+ algorithm : 'RDFC-1.0'
579+ } , options . canonizeOptions || null ) ;
580+
571581 if ( 'inputFormat' in options ) {
572582 if ( options . inputFormat !== 'application/n-quads' &&
573583 options . inputFormat !== 'application/nquads' ) {
@@ -579,17 +589,18 @@ jsonld.normalize = jsonld.canonize = async function(input, options) {
579589 const parsedInput = NQuads . parse ( input ) ;
580590
581591 // do canonicalization
582- return canonize . canonize ( parsedInput , options ) ;
592+ return canonize . canonize ( parsedInput , canonizeOptions ) ;
583593 }
584594
585595 // convert to RDF dataset then do normalization
586596 const opts = { ...options } ;
587597 delete opts . format ;
598+ delete opts . canonizeOptions ;
588599 opts . produceGeneralizedRdf = false ;
589600 const dataset = await jsonld . toRDF ( input , opts ) ;
590601
591602 // do canonicalization
592- return canonize . canonize ( dataset , options ) ;
603+ return canonize . canonize ( dataset , canonizeOptions ) ;
593604} ;
594605
595606/**
@@ -653,8 +664,8 @@ jsonld.fromRDF = async function(dataset, options) {
653664 * [skipExpansion] true to assume the input is expanded and skip
654665 * expansion, false not to, defaults to false. Some well-formed
655666 * and safe-mode checks may be omitted.
656- * [format] the format to use to output a string:
657- * 'application/n-quads' for N-Quads.
667+ * [format] the output format. null for an RDF dataset,
668+ * 'application/n-quads' for an N-Quads string. (default: null)
658669 * [produceGeneralizedRdf] true to output generalized RDF, false
659670 * to produce only standard RDF (default: false).
660671 * [documentLoader(url, options)] the document loader.
@@ -672,7 +683,6 @@ jsonld.toRDF = async function(input, options) {
672683
673684 // set default options
674685 options = _setDefaults ( options , {
675- base : _isString ( input ) ? input : '' ,
676686 skipExpansion : false ,
677687 contextResolver : new ContextResolver (
678688 { sharedCache : _resolvedContextCache } )
0 commit comments