@@ -35,7 +35,9 @@ export default class N3Writer {
3535      options  =  outputStream ,  outputStream  =  null ; 
3636    options  =  options  ||  { } ; 
3737    this . _lists  =  options . lists ; 
38-     this . _graphs  =  options . graphs  ||  'keep' ; 
38+     this . _keepGraphs  =  ! options . graphs  ||  options . graphs  ===  'keep' ; 
39+     this . _errorOnGraphs  =  options . graphs  ===  'error' ; 
40+ 
3941
4042    // If no output stream given, send the output as string through the end callback 
4143    if  ( ! outputStream )  { 
@@ -85,11 +87,11 @@ export default class N3Writer {
8587  // ### `_writeQuad` writes the quad to the output stream 
8688  _writeQuad ( subject ,  predicate ,  object ,  graph ,  done )  { 
8789    try  { 
88-       if  ( this . _graphs   ===   'error'  &&  ! DEFAULTGRAPH . equals ( graph ) )  { 
89-         done ( new  Error ( 'Encountered graph name, this is forbidden .' ) ) ; 
90+       if  ( this . _errorOnGraphs  &&  ! DEFAULTGRAPH . equals ( graph ) )  { 
91+         done ( new  Error ( 'The chosen serialization settings do not support triples in a non-default graph .' ) ) ; 
9092      } 
9193      // Write the graph's label if it has changed 
92-       if  ( this . _graphs   ===   'keep'  &&  ! graph . equals ( this . _graph ) )  { 
94+       if  ( this . _keepGraphs  &&  ! graph . equals ( this . _graph ) )  { 
9395        // Close the previous graph and start the new one 
9496        this . _write ( ( this . _subject  ===  null  ? ''  : ( this . _inDefaultGraph  ? '.\n'  : '\n}\n' ) )  + 
9597                    ( DEFAULTGRAPH . equals ( graph )  ? ''  : `${ this . _encodeIriOrBlank ( graph ) }   {\n` ) ) ; 
@@ -126,15 +128,15 @@ export default class N3Writer {
126128
127129  // ### `quadToString` serializes a quad as a string 
128130  quadToString ( subject ,  predicate ,  object ,  graph ,  done )  { 
129-     if  ( this . _graphs   ===   'error'  &&  ! DEFAULTGRAPH . equals ( graph ) )  { 
130-       const  err  =  new  Error ( 'Encountered graph name, this is forbidden .' ) ; 
131-       if  ( done )  return  done ( err ) ; 
132-       throw  err ; 
131+     if  ( this . _errorOnGraphs  &&  ! DEFAULTGRAPH . equals ( graph ) )  { 
132+       const  error  =  new  Error ( 'The chosen serialization settings do not support triples in a non-default graph .' ) ; 
133+       if  ( done )  return  done ( error ) ; 
134+       throw  error ; 
133135    } 
134136    return   `${ this . _encodeSubject ( subject ) }   ${  
135137            this . _encodeIriOrBlank ( predicate ) }   ${ 
136138            this . _encodeObject ( object )  
137-              }  ${ this . _graphs   ===   'keep'  &&  graph  &&  graph . value  ? ` ${ this . _encodeIriOrBlank ( graph ) }   .\n`  : ' .\n' }  `; 
139+           }  ${ this . _keepGraphs  &&  graph  &&  graph . value  ? ` ${ this . _encodeIriOrBlank ( graph ) }   .\n`  : ' .\n' }  `; 
138140  } 
139141
140142  // ### `quadsToString` serializes an array of quads as a string 
0 commit comments