rdf-environment.js
/**
   The function toLiteral accepts an native object and coerces it to a Literal instance.
   It distinguishes between Object specializations and primitive data.
   In those cases, use the type to compute a converter and delegate to that.
   Return unmodified any data which is already a Term.
   
   from rdflib.js
      https://github.com/linkeddata/rdflib.js/blob/master/src/literal.js
    */
The function toLiteral accepts an native object and coerces it to a Literal instance.
It distinguishes between Object specializations and primitive data.
In those cases, use the type to compute a converter and delegate to that.
Return unmodified any data which is already a Term.


The function toLiteral accepts an native object and coerces it to a Literal instance . It distinguishes between Object specializations and primitive data . In those cases use the type to compute a converter and delegate to that . Return unmodified any data which is already a Term .
toLiteral(value) {
    if (typeof value === 'undefined' || value === null) {
      throw (new Error(`RDFEnvironment.toLiteral: invalid value: '${value}' of type '${typeof value}'`));
    } else if (value instanceof Term) {  
      return (value);
    } else {
      var type = typeof(value);
      var converter = null;
      switch (type) {
      case 'object':
        converter = Literal.toLiteral[value.constructor.name];
        if (converter) {
          return (converter(value));
        }
        break;
      default:
        converter = Literal.toLiteral[type];
        if (converter) {
          var literal = converter(value);
          return (literal);
        }
      }
      throw (new Error(`RDFEnvironment.toLiteral: invalid value: '${value}' of type '${typeof value}'`));
    }
  }
toLiteral ( value ) { if ( typeof value === 'undefined' || value === null ) { throw ( new Error ( ` ${ value } ${ typeof value } ` ) ) ; } else if ( value instanceof Term ) { return ( value ) ; } else { var type = typeof ( value ) ; var converter = null ; switch ( type ) { case 'object' : converter = Literal . toLiteral [ value . constructor . name ] ; if ( converter ) { return ( converter ( value ) ) ; } break ; default : converter = Literal . toLiteral [ type ] ; if ( converter ) { var literal = converter ( value ) ; return ( literal ) ; } } throw ( new Error ( ` ${ value } ${ typeof value } ` ) ) ; } }
The function toLiteral accepts an native object and coerces it to a Literal instance.
The function toLiteral accepts an native object and coerces it to a Literal instance .
// this is already a Term instance