aboutsummaryrefslogtreecommitdiffstats
path: root/lib/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util.js')
-rw-r--r--lib/util.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js
index b6691af..3ce50c5 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -50,6 +50,28 @@ var isInList = exports.isInList = function isInList(mbr, list) {
};
/**
+ * select element of the array where regexp in the first element matches second
+ * parameter of this function
+ *
+ * @param list Array with regexps and return values
+ * @param chosingMark String by which the element of array is to be matched
+ * @return Object chosen element
+ */
+exports.filterByRegexp = function filterByRegexp(list, chosingMark) {
+ let chosenPair = [];
+ if (list.length > 0) {
+ chosenPair = list.filter(function(pair) {
+ return new RegExp(pair.regexp, "i").test(chosingMark);
+ });
+ }
+ if (chosenPair.length > 0) {
+ return chosenPair[0].addr;
+ } else {
+ return "";
+ }
+};
+
+/**
* format date to be in ISO format (just day part)
*
* @param date