tasks/jsonld/js/request.js
function _typedParse(loc, type, data, callback) {
  switch(type.toLowerCase()) {
    case 'text':
    case 'plain':
    case 'text/plain':
      callback(null, data);
      break;
    case 'json':
    case 'jsonld':
    case 'json-ld':
    case 'ld+json':
    case 'application/json':
    case 'application/ld+json':
      try {
        callback(null, JSON.parse(data));
      }
      catch(ex) {
        callback({
          message: 'Error parsing JSON.',
          contentType: type,
          url: loc,
          exception: ex.toString()
        });
      }
      break;
    case 'xml':
    case 'html':
    case 'xhtml':
    case 'text/html':
    case 'application/xhtml+xml':
      if(typeof jsdom === 'undefined') {
        callback({
          message: 'jsdom module not found.',
          contentType: type,
          url: loc
        });
        break;
      }
      if(typeof RDFa === 'undefined') {
        callback({
          message: 'RDFa module not found.',
          contentType: type,
          url: loc
        });
        break;
      }
      // input is RDFa
      try {
        jsdom.env({
          html: data,
          done: function(errors, window) {
            if(errors && errors.length > 0) {
              return callback({
                message: 'DOM Errors:',
                errors: errors,
                url: loc
              });
            }

            try {
              // extract JSON-LD from RDFa
              RDFa.attach(window.document);
              jsonld.fromRDF(window.document.data,
                {format: 'rdfa-api'}, callback);
            }
            catch(ex) {
              // FIXME: expose RDFa/jsonld ex?
              callback({
                message: 'RDFa extraction error.',
                contentType: type,
                url: loc
              });
            }
          }
        });
      }
      catch(ex) {
        // FIXME: expose jsdom(?) ex?
        callback({
          message: 'jsdom error.',
          contentType: type,
          url: loc
        });
      }
      break;
    default:
      callback({
        message: 'Unknown Content-Type.',
        contentType: type,
        url: loc
      });
  }
}
function _typedParse(loc, type, data, callback) {
  switch(type.toLowerCase()) {
    case 'text':
    case 'plain':
    case 'text/plain':
      callback(null, data);
      break;
    case 'json':
    case 'jsonld':
    case 'json-ld':
    case 'ld+json':
    case 'application/json':
    case 'application/ld+json':
      try {
        callback(null, JSON.parse(data));
      }
      catch(ex) {
        callback({
          message: 'Error parsing JSON.',
          contentType: type,
          url: loc,
          exception: ex.toString()
        });
      }
      break;
    case 'xml':
    case 'html':
    case 'xhtml':
    case 'text/html':
    case 'application/xhtml+xml':
      if(typeof jsdom === 'undefined') {
        callback({
          message: 'jsdom module not found.',
          contentType: type,
          url: loc
        });
        break;
      }
      if(typeof RDFa === 'undefined') {
        callback({
          message: 'RDFa module not found.',
          contentType: type,
          url: loc
        });
        break;
      }
      // input is RDFa
      try {
        jsdom.env({
          html: data,
          done: function(errors, window) {
            if(errors && errors.length > 0) {
              return callback({
                message: 'DOM Errors:',
                errors: errors,
                url: loc
              });
            }

            try {
              // extract JSON-LD from RDFa
              RDFa.attach(window.document);
              jsonld.fromRDF(window.document.data,
                {format: 'rdfa-api'}, callback);
            }
            catch(ex) {
              // FIXME: expose RDFa/jsonld ex?
              callback({
                message: 'RDFa extraction error.',
                contentType: type,
                url: loc
              });
            }
          }
        });
      }
      catch(ex) {
        // FIXME: expose jsdom(?) ex?
        callback({
          message: 'jsdom error.',
          contentType: type,
          url: loc
        });
      }
      break;
    default:
      callback({
        message: 'Unknown Content-Type.',
        contentType: type,
        url: loc
      });
  }
}
function _typedParse ( loc , type , data , callback ) { switch ( type . toLowerCase ( ) ) { case 'text' : case 'plain' : case 'text/plain' : callback ( null , data ) ; break ; case 'json' : case 'jsonld' : case 'json-ld' : case 'ld+json' : case 'application/json' : case 'application/ld+json' : try { callback ( null , JSON . parse ( data ) ) ; } catch ( ex ) { callback ( { message : 'Error parsing JSON.' , contentType : type , url : loc , exception : ex . toString ( ) } ) ; } break ; case 'xml' : case 'html' : case 'xhtml' : case 'text/html' : case 'application/xhtml+xml' : if ( typeof jsdom === 'undefined' ) { callback ( { message : 'jsdom module not found.' , contentType : type , url : loc } ) ; break ; } if ( typeof RDFa === 'undefined' ) { callback ( { message : 'RDFa module not found.' , contentType : type , url : loc } ) ; break ; } // input is RDFa try { jsdom . env ( { html : data , done : function ( errors , window ) { if ( errors && errors . length > 0 ) { return callback ( { message : 'DOM Errors:' , errors : errors , url : loc } ) ; } try { // extract JSON-LD from RDFa RDFa . attach ( window . document ) ; jsonld . fromRDF ( window . document . data , { format : 'rdfa-api' } , callback ) ; } catch ( ex ) { // FIXME: expose RDFa/jsonld ex? callback ( { message : 'RDFa extraction error.' , contentType : type , url : loc } ) ; } } } ) ; } catch ( ex ) { // FIXME: expose jsdom(?) ex? callback ( { message : 'jsdom error.' , contentType : type , url : loc } ) ; } break ; default : callback ( { message : 'Unknown Content-Type.' , contentType : type , url : loc } ) ; } }
Parse data with given type.

@param loc location string came from
@param type content type of the string
@param data the data string or buffer
@param callback function(err, data) called with errors and result data
Parse data with given type .