From be7eab65b2022e6ed57644d763ca392b8d2bbb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Paczyn=CC=81ski?= Date: Tue, 3 Oct 2017 10:47:15 +0200 Subject: [PATCH] =?UTF-8?q?Brought=20back=20=E2=80=9Ccontains=E2=80=9D=20h?= =?UTF-8?q?elper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/helpers/contains.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 assets/js/helpers/contains.js diff --git a/assets/js/helpers/contains.js b/assets/js/helpers/contains.js new file mode 100644 index 0000000..cd9c53f --- /dev/null +++ b/assets/js/helpers/contains.js @@ -0,0 +1,29 @@ +/** + * Creates an array from list using \n as delimiter + * and checks if any element in list is contained in the url. + * + * @param url + * @param list + * @returns {boolean} + */ +function contains(url, list) { + var lines = list.split('\n'); + + for (var i = 0; i < lines.length; i ++) { + + // Trim all lines from the list one by one + var cleanLine = lines[i].trim(); + + // If by any chance one line in the list is empty, ignore it + if(cleanLine === '') continue; + + // If url contains the current line return true + if (url.indexOf(cleanLine) > -1) { + return true; + } + } + + return false; +} + +module.exports = contains;