tasks/jsonld/js/jsonld.js
function cleanup(err, compacted, activeCtx, options) {
    if(err) {
      return callback(err);
    }

    if(options.compactArrays && !options.graph && _isArray(compacted)) {
      // simplify to a single item
      if(compacted.length === 1) {
        compacted = compacted[0];
      }
      // simplify to an empty object
      else if(compacted.length === 0) {
        compacted = {};
      }
    }
    // always use array if graph option is on
    else if(options.graph && _isObject(compacted)) {
      compacted = [compacted];
    }

    // follow @context key
    if(_isObject(ctx) && '@context' in ctx) {
      ctx = ctx['@context'];
    }

    // build output context
    ctx = _clone(ctx);
    if(!_isArray(ctx)) {
      ctx = [ctx];
    }
    // remove empty contexts
    var tmp = ctx;
    ctx = [];
    for(var i = 0; i < tmp.length; ++i) {
      if(!_isObject(tmp[i]) || Object.keys(tmp[i]).length > 0) {
        ctx.push(tmp[i]);
      }
    }

    // remove array if only one context
    var hasContext = (ctx.length > 0);
    if(ctx.length === 1) {
      ctx = ctx[0];
    }

    // add context and/or @graph
    if(_isArray(compacted)) {
      // use '@graph' keyword
      var kwgraph = _compactIri(activeCtx, '@graph');
      var graph = compacted;
      compacted = {};
      if(hasContext) {
        compacted['@context'] = ctx;
      }
      compacted[kwgraph] = graph;
    }
    else if(_isObject(compacted) && hasContext) {
      // reorder keys so @context is first
      var graph = compacted;
      compacted = {'@context': ctx};
      for(var key in graph) {
        compacted[key] = graph[key];
      }
    }

    callback(null, compacted, activeCtx);
  }
function cleanup(err, compacted, activeCtx, options) {
    if(err) {
      return callback(err);
    }

    if(options.compactArrays && !options.graph && _isArray(compacted)) {
      // simplify to a single item
      if(compacted.length === 1) {
        compacted = compacted[0];
      }
      // simplify to an empty object
      else if(compacted.length === 0) {
        compacted = {};
      }
    }
    // always use array if graph option is on
    else if(options.graph && _isObject(compacted)) {
      compacted = [compacted];
    }

    // follow @context key
    if(_isObject(ctx) && '@context' in ctx) {
      ctx = ctx['@context'];
    }

    // build output context
    ctx = _clone(ctx);
    if(!_isArray(ctx)) {
      ctx = [ctx];
    }
    // remove empty contexts
    var tmp = ctx;
    ctx = [];
    for(var i = 0; i < tmp.length; ++i) {
      if(!_isObject(tmp[i]) || Object.keys(tmp[i]).length > 0) {
        ctx.push(tmp[i]);
      }
    }

    // remove array if only one context
    var hasContext = (ctx.length > 0);
    if(ctx.length === 1) {
      ctx = ctx[0];
    }

    // add context and/or @graph
    if(_isArray(compacted)) {
      // use '@graph' keyword
      var kwgraph = _compactIri(activeCtx, '@graph');
      var graph = compacted;
      compacted = {};
      if(hasContext) {
        compacted['@context'] = ctx;
      }
      compacted[kwgraph] = graph;
    }
    else if(_isObject(compacted) && hasContext) {
      // reorder keys so @context is first
      var graph = compacted;
      compacted = {'@context': ctx};
      for(var key in graph) {
        compacted[key] = graph[key];
      }
    }

    callback(null, compacted, activeCtx);
  }
function cleanup ( err , compacted , activeCtx , options ) { if ( err ) { return callback ( err ) ; } if ( options . compactArrays && ! options . graph && _isArray ( compacted ) ) { // simplify to a single item if ( compacted . length === 1 ) { compacted = compacted [ 0 ] ; } // simplify to an empty object else if ( compacted . length === 0 ) { compacted = { } ; } } // always use array if graph option is on else if ( options . graph && _isObject ( compacted ) ) { compacted = [ compacted ] ; } // follow @context key if ( _isObject ( ctx ) && '@context' in ctx ) { ctx = ctx [ '@context' ] ; } // build output context ctx = _clone ( ctx ) ; if ( ! _isArray ( ctx ) ) { ctx = [ ctx ] ; } // remove empty contexts var tmp = ctx ; ctx = [ ] ; for ( var i = 0 ; i < tmp . length ; ++ i ) { if ( ! _isObject ( tmp [ i ] ) || Object . keys ( tmp [ i ] ) . length > 0 ) { ctx . push ( tmp [ i ] ) ; } } // remove array if only one context var hasContext = ( ctx . length > 0 ) ; if ( ctx . length === 1 ) { ctx = ctx [ 0 ] ; } // add context and/or @graph if ( _isArray ( compacted ) ) { // use '@graph' keyword var kwgraph = _compactIri ( activeCtx , '@graph' ) ; var graph = compacted ; compacted = { } ; if ( hasContext ) { compacted [ '@context' ] = ctx ; } compacted [ kwgraph ] = graph ; } else if ( _isObject ( compacted ) && hasContext ) { // reorder keys so @context is first var graph = compacted ; compacted = { '@context' : ctx } ; for ( var key in graph ) { compacted [ key ] = graph [ key ] ; } } callback ( null , compacted , activeCtx ) ; }
performs clean up after compaction
performs clean up after compaction