
function grant ({handler, ...rest}) {
  if (handler === 'express') {
    var version = 4
  }
  else if (handler === 'koa') {
    var version =
      parseInt(require('koa/package.json').version.split('.')[0]) >= 2 ? 2 : 1
  }
  else if (handler === 'hapi') {
    try {
      var pkg = require('@hapi/hapi/package.json')
    }
    catch (err) {
      var pkg = require('hapi/package.json')
    }
    var version = parseInt(pkg.version.split('.')[0]) >= 17 ? 17 : 16
  }

  if (/^(?:express|koa|hapi)$/.test(handler)) {
    return require(`./lib/handler/${handler}-${version}`)(rest)
  }
  else {
    return require(`./lib/handler/${handler}`)(rest)
  }
}

grant.express = (options) => {
  var handler = 'express'
  var version = 4
  return options
    ? require(`./lib/handler/${handler}-${version}`)(options)
    : require(`./lib/handler/${handler}-${version}`)
}

grant.koa = (options) => {
  var handler = 'koa'
  var version =
    parseInt(require('koa/package.json').version.split('.')[0]) >= 2 ? 2 : 1
  return options
    ? require(`./lib/handler/${handler}-${version}`)(options)
    : require(`./lib/handler/${handler}-${version}`)
}

grant.hapi = (options) => {
  var handler = 'hapi'
  try {
    var pkg = require('@hapi/hapi/package.json')
  }
  catch (err) {
    var pkg = require('hapi/package.json')
  }
  var version = parseInt(pkg.version.split('.')[0]) >= 17 ? 17 : 16
  return options
    ? require(`./lib/handler/${handler}-${version}`)(options)
    : require(`./lib/handler/${handler}-${version}`)
}

grant.node = (options) => {
  var handler = 'node'
  return options
    ? require(`./lib/handler/${handler}`)(options)
    : require(`./lib/handler/${handler}`)
}

grant.aws = (options) => {
  var handler = 'aws'
  return options
    ? require(`./lib/handler/${handler}`)(options)
    : require(`./lib/handler/${handler}`)
}

grant.vercel = (options) => {
  var handler = 'vercel'
  return options
    ? require(`./lib/handler/${handler}`)(options)
    : require(`./lib/handler/${handler}`)
}

module.exports = grant

@@ -467,67 +467,30 @@
   %7D%0A
-%0A
   
-if (/%5E(?:express%7Ckoa%7Chapi)$/.test(handler)) %7B%0A    return
+return version%0A    ?
  req
@@ -545,29 +545,11 @@
 )%0A  
-%7D%0A  else %7B%0A    return
+  :
  req
@@ -587,20 +587,16 @@
 )(rest)%0A
-  %7D%0A
 %7D%0A%0Agrant
@@ -631,68 +631,35 @@
 var 
-handler = 'express'%0A  var version = 4%0A  return options%0A    ?
+version = 4%0A  var handler =
  req
@@ -674,34 +674,31 @@
 lib/handler/
-$%7Bhandler%7D
+express
 -$%7Bversion%7D%60
@@ -702,70 +702,54 @@
 n%7D%60)
-(options)%0A    : require(%60./lib/handler/$%7Bhandler%7D-$%7Bversion%7D%60)
+%0A  return options ? handler(options) : handler
 %0A%7D%0A%0A
@@ -779,30 +779,8 @@
 %3E %7B%0A
-  var handler = 'koa'%0A
   va
@@ -870,36 +870,29 @@
 2 : 1%0A  
-return options%0A    ?
+var handler =
  require
@@ -903,34 +903,27 @@
 lib/handler/
-$%7Bhandler%7D
+koa
 -$%7Bversion%7D%60
@@ -927,70 +927,54 @@
 n%7D%60)
-(options)%0A    : require(%60./lib/handler/$%7Bhandler%7D-$%7Bversion%7D%60)
+%0A  return options ? handler(options) : handler
 %0A%7D%0A%0A
@@ -1005,31 +1005,8 @@
 %3E %7B%0A
-  var handler = 'hapi'%0A
   tr
@@ -1195,36 +1195,29 @@
  : 16%0A  
-return options%0A    ?
+var handler =
  require
@@ -1228,34 +1228,28 @@
 lib/handler/
-$%7Bhandler%7D
+hapi
 -$%7Bversion%7D%60
@@ -1253,70 +1253,54 @@
 n%7D%60)
-(options)%0A    : require(%60./lib/handler/$%7Bhandler%7D-$%7Bversion%7D%60)
+%0A  return options ? handler(options) : handler
 %0A%7D%0A%0A
@@ -1347,14 +1347,37 @@
 r = 
-'
+require('./lib/handler/
 node'
+)
 %0A  r
@@ -1393,101 +1393,37 @@
 ions
-%0A    ? require(%60./lib/handler/$%7Bhandler%7D%60)(options)%0A    : require(%60./lib/handler/$%7B
+ ? handler(options) : 
 handler
-%7D%60)
 %0A%7D%0A%0A
@@ -1428,19 +1428,22 @@
 %0A%0Agrant.
-aws
+vercel
  = (opti
@@ -1472,123 +1472,85 @@
 r = 
-'aws'%0A  return options%0A    ? require(%60./lib/handler/$%7Bhandler%7D%60)(options)%0A    : require(%60./lib/handler/$%7Bhandler%7D%60)
+require('./lib/handler/vercel')%0A  return options ? handler(options) : handler
 %0A%7D%0A%0A
@@ -1547,38 +1547,35 @@
 andler%0A%7D%0A%0Agrant.
-vercel
+aws
  = (options) =%3E 
@@ -1596,126 +1596,82 @@
 r = 
-'vercel'%0A  return options%0A    ? require(%60./lib/handler/$%7Bhandler%7D%60)(options)%0A    : require(%60./lib/handler/$%7Bhandler%7D%60)
+require('./lib/handler/aws')%0A  return options ? handler(options) : handler
 %0A%7D%0A%0A

Refactor entrypoints