summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/lib/utils/getLimit.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--fastify-busboy/lib/utils/getLimit.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/fastify-busboy/lib/utils/getLimit.js b/fastify-busboy/lib/utils/getLimit.js
new file mode 100644
index 0000000..cb64fd6
--- /dev/null
+++ b/fastify-busboy/lib/utils/getLimit.js
@@ -0,0 +1,16 @@
+'use strict'
+
+module.exports = function getLimit (limits, name, defaultLimit) {
+ if (
+ !limits ||
+ limits[name] === undefined ||
+ limits[name] === null
+ ) { return defaultLimit }
+
+ if (
+ typeof limits[name] !== 'number' ||
+ isNaN(limits[name])
+ ) { throw new TypeError('Limit ' + name + ' is not a valid number') }
+
+ return limits[name]
+}