graph-environment.js
/**
   Accept a context designator, retrieve if necessary, expand all definitions,
   and bind the environment's context property to it.
   @param {(string|URL|Context)} context - The context to resolve.
   */
Accept a context designator, retrieve if necessary, expand all definitions,
and bind the environment's context property to it.
Accept a context designator retrieve if necessary expand all definitions and bind the environment ' s context property to it .
resolveContext(context) {
    var thisEnv = this;
    var expandContext = function(context) {
      var base = context['@base'];
      Object.values(context).forEach(function(def) {
        var uri = def['@id'];
        if (uri) {
          def['@id'] = (base ? new URL(uri, base).href: new URL(uri).href);
        }
      });
      return (context);
    }
    var fetchContext = function(context) {
      fetch(context).then(function(response) {
        thisEnv.context = expandContext(response.json());
      })
    }
    if (context) {
      switch (typeof(context)) {
      case 'object':
        if (context instanceof URL) {
          fetchContext(context.href);
        } else {
          this.context = expandContext(context);
        }
        break;
      case 'string':
        fetchContext(context);
        break;
      default:
        throw (new TypeError(`resolveContext: invalid context: ${context}` ) );
      }
    } else {
      this.context = {};
    }
  }
resolveContext ( context ) { var thisEnv = this ; var expandContext = function ( context ) { var base = context [ '@base' ] ; Object . values ( context ) . forEach ( function ( def ) { var uri = def [ '@id' ] ; if ( uri ) { def [ '@id' ] = ( base ? new URL ( uri , base ) . href : new URL ( uri ) . href ) ; } } ) ; return ( context ) ; } var fetchContext = function ( context ) { fetch ( context ) . then ( function ( response ) { thisEnv . context = expandContext ( response . json ( ) ) ; } ) } if ( context ) { switch ( typeof ( context ) ) { case 'object' : if ( context instanceof URL ) { fetchContext ( context . href ) ; } else { this . context = expandContext ( context ) ; } break ; case 'string' : fetchContext ( context ) ; break ; default : throw ( new TypeError ( ` ${ context } ` ) ) ; } } else { this . context = { } ; } }
Accept a context designator, retrieve if necessary, expand all definitions,
and bind the environment's context property to it.
Accept a context designator retrieve if necessary expand all definitions and bind the environment ' s context property to it .