diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-10-02 19:39:23 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-10-07 11:48:33 +0200 |
commit | 1154e755f1195d89fd5af7943c0281f6e2d3df7a (patch) | |
tree | afac23dfa2d97b23c53f0435303e0239313408cb | |
parent | 95ea1e67fe29a1778d161dce15ea57205b07c85d (diff) |
luci-base: luci.js: add resolveDefault() helper
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/luci.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index cad720853..3f4707d4e 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -1852,6 +1852,27 @@ return s.split(/\s+/); }, + /** + * Returns a promise resolving with either the given value or or with + * the given default in case the input value is a rejecting promise. + * + * @instance + * @memberof LuCI + * + * @param {*} value + * The value to resolve the promise with. + * + * @param {*} defvalue + * The default value to resolve the promise with in case the given + * input value is a rejecting promise. + * + * @returns {Promise<*>} + * Returns a new promise resolving either to the given input value or + * to the given default value on error. + */ + resolveDefault: function(value, defvalue) { + return Promise.resolve(value).catch(function() { return defvalue }); + }, /** * The request callback function is invoked whenever an HTTP |