From 6d97e5272b1b68ed377c5c0cdce9e7b1754a4c0a Mon Sep 17 00:00:00 2001 From: Deepak Date: Sun, 14 Jul 2019 15:14:50 +0530 Subject: [PATCH] Add support for async functions --- lib/type.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/type.js b/lib/type.js index cbec48f..6e5eff2 100644 --- a/lib/type.js +++ b/lib/type.js @@ -26,7 +26,7 @@ module.exports = exports = function (mongoose, opts) { if (!arg.length) return null; } - if ('string' == type && /^function\s*[^\(]*\(/.test(arg)) { + if ('string' == type && /^(async\s+)?function\s*[^\(]*\(/.test(arg)) { fn = toFunc(arg); } else if ('function' == type) { @@ -69,7 +69,7 @@ function toFunction (arg) { if (0 == arg.length) return null; // must start with "function" - if (!/^function\s*[^\(]*\(/.test(arg)) { + if (!/^(async\s+)?function\s*[^\(]*\(/.test(arg)) { throw error(arg); } @@ -84,7 +84,7 @@ function toFunction (arg) { */ function trim (arg) { - var match = arg.match(/^function\s*[^\(]*\([^\)]*\)\s*{/); + var match = arg.match(/^(async\s+)?function\s*[^\(]*\([^\)]*\)\s*{/); if (!match) throw error(arg); // we included the first "{" in our match