@@ -8,6 +8,10 @@ const graphTypes = require('./graphTypes');
88const types = require ( './types' ) ;
99const util = require ( './util' ) ;
1010
11+ const {
12+ handleEvent : _handleEvent
13+ } = require ( './events' ) ;
14+
1115// constants
1216const {
1317 // RDF,
@@ -44,15 +48,16 @@ module.exports = api;
4448 */
4549api . fromRDF = async (
4650 dataset ,
47- {
48- useRdfType = false ,
49- useNativeTypes = false ,
50- rdfDirection = null
51- }
51+ options
5252) => {
5353 const defaultGraph = { } ;
5454 const graphMap = { '@default' : defaultGraph } ;
5555 const referencedOnce = { } ;
56+ const {
57+ useRdfType = false ,
58+ useNativeTypes = false ,
59+ rdfDirection = null
60+ } = options ;
5661
5762 for ( const quad of dataset ) {
5863 // TODO: change 'name' to 'graph'
@@ -87,7 +92,7 @@ api.fromRDF = async (
8792 continue ;
8893 }
8994
90- const value = _RDFToObject ( o , useNativeTypes , rdfDirection ) ;
95+ const value = _RDFToObject ( o , useNativeTypes , rdfDirection , options ) ;
9196 util . addValue ( node , p , value , { propertyIsArray : true } ) ;
9297
9398 // object may be an RDF list/partial list node but we can't know easily
@@ -275,10 +280,12 @@ api.fromRDF = async (
275280 *
276281 * @param o the RDF triple object to convert.
277282 * @param useNativeTypes true to output native types, false not to.
283+ * @param rdfDirection text direction mode [null, i18n-datatype]
284+ * @param options top level API options
278285 *
279286 * @return the JSON-LD object.
280287 */
281- function _RDFToObject ( o , useNativeTypes , rdfDirection ) {
288+ function _RDFToObject ( o , useNativeTypes , rdfDirection , options ) {
282289 // convert NamedNode/BlankNode object to JSON-LD
283290 if ( o . termType . endsWith ( 'Node' ) ) {
284291 return { '@id' : o . value } ;
@@ -334,7 +341,17 @@ function _RDFToObject(o, useNativeTypes, rdfDirection) {
334341 if ( language . length > 0 ) {
335342 rval [ '@language' ] = language ;
336343 if ( ! language . match ( REGEX_BCP47 ) ) {
337- console . warn ( `@language must be valid BCP47: ${ language } ` ) ;
344+ _handleEvent ( {
345+ event : {
346+ code : 'invalid @language value' ,
347+ level : 'warning' ,
348+ message : '@language value must be valid BCP47.' ,
349+ details : {
350+ language
351+ }
352+ } ,
353+ options
354+ } ) ;
338355 }
339356 }
340357 rval [ '@direction' ] = direction ;
0 commit comments