index.js
function deserialiseRequest (serialised) {
  var options
  var url

  if (typeof serialised === 'string') {
    options = JSON.parse(serialised)
    url = options.url
  } else if (typeof serialised === 'object') {
    options = serialised
    url = options.url
  } else {
    throw new Error('Expecting serialised request to be a string or object')
  }

  const request = new Request(url, options)

  const properties = {
    context: {
      enumerable: true,
      value: options.context
    }
  }

  const methods = Object.keys(BodyTypes).reduce(function (obj, key) {
    const methodName = BodyMethods[key]
    obj[methodName] = {
      enumerable: true,
      value: function () {
        if (request.bodyUsed) {
          return Promise.reject(new TypeError('Already used'))
        }
        request.bodyUsed = true
        return Promise.resolve(remakeBody(options.__body, key))
      }
    }
    return obj
  }, properties)

  Object.defineProperties(request, methods)

  return request
}
function deserialiseRequest (serialised) {
  var options
  var url

  if (typeof serialised === 'string') {
    options = JSON.parse(serialised)
    url = options.url
  } else if (typeof serialised === 'object') {
    options = serialised
    url = options.url
  } else {
    throw new Error('Expecting serialised request to be a string or object')
  }

  const request = new Request(url, options)

  const properties = {
    context: {
      enumerable: true,
      value: options.context
    }
  }

  const methods = Object.keys(BodyTypes).reduce(function (obj, key) {
    const methodName = BodyMethods[key]
    obj[methodName] = {
      enumerable: true,
      value: function () {
        if (request.bodyUsed) {
          return Promise.reject(new TypeError('Already used'))
        }
        request.bodyUsed = true
        return Promise.resolve(remakeBody(options.__body, key))
      }
    }
    return obj
  }, properties)

  Object.defineProperties(request, methods)

  return request
}
function deserialiseRequest ( serialised ) { var options var url if ( typeof serialised === 'string' ) { options = JSON . parse ( serialised ) url = options . url } else if ( typeof serialised === 'object' ) { options = serialised url = options . url } else { throw new Error ( 'Expecting serialised request to be a string or object' ) } const request = new Request ( url , options ) const properties = { context : { enumerable : true , value : options . context } } const methods = Object . keys ( BodyTypes ) . reduce ( function ( obj , key ) { const methodName = BodyMethods [ key ] obj [ methodName ] = { enumerable : true , value : function ( ) { if ( request . bodyUsed ) { return Promise . reject ( new TypeError ( 'Already used' ) ) } request . bodyUsed = true return Promise . resolve ( remakeBody ( options . __body , key ) ) } } return obj } , properties ) Object . defineProperties ( request , methods ) return request }
Deserialise a Request from a string or object.
@param {Object|String} serialised
@returns {Request}
Deserialise a Request from a string or object .