From 124d95984f4b825b1f2afc709392172cdc42a29c Mon Sep 17 00:00:00 2001 From: mohammadKhalafi <77299737+mohammadKhalafi@users.noreply.github.com> Date: Thu, 12 Jan 2023 21:42:20 +0330 Subject: [PATCH 1/4] Update functions.js --- src/functions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/functions.js b/src/functions.js index dbe8fb32..d5abdf05 100644 --- a/src/functions.js +++ b/src/functions.js @@ -609,14 +609,14 @@ var _ = Mavo.Functions = { between: $.extend((haystack, from, to, tight) => { [haystack, from, to] = [str(haystack), str(from), str(to)]; - var i1 = from? haystack[tight? "lastIndexOf" : "indexOf"](from) : -1; - var i2 = haystack[tight? "indexOf" : "lastIndexOf"](to); + const fromIndex = haystack[tight? "lastIndexOf" : "indexOf"](from); + const toIndex = haystack[tight? "indexOf" : "lastIndexOf"](to); - if (from && i1 === -1 || i2 === -1) { + if (fromIndex === -1 || toIndex === -1) { return ""; } - return haystack.slice(i1 + 1, i2 === -1 || !to? haystack.length : i2); + return haystack.slice(from ? fromIndex + from.length : 0, to ? toIndex : haystack.length); }, { multiValued: true }), From aad4b0833d563ad6d18503e2163244545313962b Mon Sep 17 00:00:00 2001 From: mohammadKhalafi <77299737+mohammadKhalafi@users.noreply.github.com> Date: Fri, 13 Jan 2023 04:24:00 +0330 Subject: [PATCH 2/4] tight problem fixed! --- src/functions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/functions.js b/src/functions.js index d5abdf05..3b5a467e 100644 --- a/src/functions.js +++ b/src/functions.js @@ -609,14 +609,18 @@ var _ = Mavo.Functions = { between: $.extend((haystack, from, to, tight) => { [haystack, from, to] = [str(haystack), str(from), str(to)]; - const fromIndex = haystack[tight? "lastIndexOf" : "indexOf"](from); - const toIndex = haystack[tight? "indexOf" : "lastIndexOf"](to); + let fromIndex = haystack[tight? "lastIndexOf" : "indexOf"](from); + let toIndex = haystack[tight? "indexOf" : "lastIndexOf"](to); if (fromIndex === -1 || toIndex === -1) { return ""; } - return haystack.slice(from ? fromIndex + from.length : 0, to ? toIndex : haystack.length); + if (tight && toIndex <= fromIndex){ + return haystack.slice(toIndex + to.length, fromIndex); + } + + return haystack.slice(fromIndex + from.length, toIndex); }, { multiValued: true }), From 1d445b3fe21a1c8859c3d7a1f3cf7e1197bc9494 Mon Sep 17 00:00:00 2001 From: mohammadKhalafi <77299737+mohammadKhalafi@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:31:13 +0330 Subject: [PATCH 3/4] handle empty strings --- src/functions.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions.js b/src/functions.js index 3b5a467e..be3d3ee5 100644 --- a/src/functions.js +++ b/src/functions.js @@ -609,8 +609,8 @@ var _ = Mavo.Functions = { between: $.extend((haystack, from, to, tight) => { [haystack, from, to] = [str(haystack), str(from), str(to)]; - let fromIndex = haystack[tight? "lastIndexOf" : "indexOf"](from); - let toIndex = haystack[tight? "indexOf" : "lastIndexOf"](to); + let fromIndex = from ? haystack[tight? "lastIndexOf" : "indexOf"](from) : 0; + let toIndex = to ? haystack[tight? "indexOf" : "lastIndexOf"](to) : haystack.length; if (fromIndex === -1 || toIndex === -1) { return ""; @@ -621,6 +621,7 @@ var _ = Mavo.Functions = { } return haystack.slice(fromIndex + from.length, toIndex); + }, { multiValued: true }), From d8527687c17c1f1e5d81e818376f253ade0c45d3 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Fri, 13 Jan 2023 18:58:10 +0100 Subject: [PATCH 4/4] A tiny code style fix --- src/functions.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/functions.js b/src/functions.js index be3d3ee5..9d785086 100644 --- a/src/functions.js +++ b/src/functions.js @@ -609,8 +609,8 @@ var _ = Mavo.Functions = { between: $.extend((haystack, from, to, tight) => { [haystack, from, to] = [str(haystack), str(from), str(to)]; - let fromIndex = from ? haystack[tight? "lastIndexOf" : "indexOf"](from) : 0; - let toIndex = to ? haystack[tight? "indexOf" : "lastIndexOf"](to) : haystack.length; + let fromIndex = from? haystack[tight? "lastIndexOf" : "indexOf"](from) : 0; + let toIndex = to? haystack[tight? "indexOf" : "lastIndexOf"](to) : haystack.length; if (fromIndex === -1 || toIndex === -1) { return ""; @@ -621,7 +621,6 @@ var _ = Mavo.Functions = { } return haystack.slice(fromIndex + from.length, toIndex); - }, { multiValued: true }),