aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
authorAustin Morton <austinpmorton@gmail.com>2019-08-23 12:35:43 -0400
committerAustin Morton <austinpmorton@gmail.com>2019-08-23 12:35:43 -0400
commit5e049bde76d07bc93aa30c2c0e11c82189efdc88 (patch)
tree3cacd720c223c1aaf273fafc16bb60c6fd359e22 /lib/utils.js
parent8c3491364e7dea6b77b26b3068bcd3804be23d09 (diff)
downloadcompiler-explorer-5e049bde76d07bc93aa30c2c0e11c82189efdc88.tar.gz
compiler-explorer-5e049bde76d07bc93aa30c2c0e11c82189efdc88.zip
Accept url options on all relevant routes and use toProperty to convert them
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js
index e625b8e2f..43d5dff98 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -197,3 +197,11 @@ function squashHorizontalWhitespace(line, atStart) {
}
exports.squashHorizontalWhitespace = squashHorizontalWhitespace;
+
+exports.toProperty = function toProperty(prop) {
+ if (prop === 'true' || prop === 'yes') return true;
+ if (prop === 'false' || prop === 'no') return false;
+ if (prop.match(/^-?(0|[1-9][0-9]*)$/)) return parseInt(prop);
+ if (prop.match(/^-?[0-9]*\.[0-9]+$/)) return parseFloat(prop);
+ return prop;
+};