# \[Feature Request\]Additional tests in switch node

**URL:** <https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195>\
**Category:** Feature Requests\
**Created:** [26 November 2023 12:08 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195 "2023-11-26T12:08:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [26 November 2023 12:08 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/1 "2023-11-26T12:08:53Z")

</div>

The switch node has a number of tests and the opposite of them  
e.g  
== and !=  
\< \> \>= \<= etc  
is true and is false  
is null and is not null  
is empty and is not empty

but there are others with just one method  
has key  
is between  
contains  
matches regex  
is of type

I'm often wanting "not contains" and either end up with an empty output wire by using contains first and stopping on 1st match (visually jarring) or a bit of JSONata

Are others finding they need opposites of any of the others?

I'm thinking if its just me 🙂 its just a little FR but maybe a floodgate would be opened 🙂

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 November 2023 12:44 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/2 "2023-11-26T12:44:53Z")

</div>

> [@cymplecy](#):
>
> has key  
> is between  
> contains  
> matches regex  
> is of type

Completely reasonable imo.  
Pretty sure there is/was a thread around this already.  
And yes, I've occasionally wished for these.

  

My thoughts were rather than make a long list even longer (which if memory serves was the reason it got no traction) would be to not add the opposites but instead, offer hem with a dropdown preceding the input

E.g.

[Has/Does not have] key  
[Is / is not] between  
[Does / Does not] contain  
[Does / Does not] match regex

Or perhaps simpler (but less friendly) just an " invert" option alongside them.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [26 November 2023 15:07 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/3 "2023-11-26T15:07:59Z")

</div>

> [@Steve-Mcl](#):
>
> [Has/Does not have] key  
> [Is / is not] between  
> [Does / Does not] contain  
> [Does / Does not] match regex

It think this is more desirable as it is less unambigious than an "invert" option, which could introduce confusing side affects.

Although I have to say that I am sometimes confused by the false/null/empty - as javascript is the worst for dealing with these types.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 November 2023 15:28 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/4 "2023-11-26T15:28:22Z")

</div>

> [@Steve-Mcl](#):
>
> My thoughts were rather than make a long list even longer (which if memory serves was the reason it got no traction) would be to not add the opposites but instead, offer them with a dropdown preceding the input

I think the invert option would add to the confusion. Invert matches regex, invert is between...

Some options are only applicable to a particular datatype. Has key only for objects, contains & regex only for string, Is true only for boolean, etc.

Would it be possible for the type specific options to be presented as a second dropdown, only when is of type selected and when relevant ?

- Is of type boolean AND is true
- Is of type object AND is empty
- Is of type string AND matches regex

I am not at all sure if this could be coded as a non-breaking change.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [27 November 2023 09:17 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/5 "2023-11-27T09:17:16Z")

</div>

I see a lot of suggestions that they all could do with doing but has anyone ever actually wanted one that was missing apart from me and the contains one 🙂

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 November 2023 09:22 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/6 "2023-11-27T09:22:47Z")

</div>

> [@cymplecy](#):
>
> but has anyone ever actually wanted one that was missing apart from me

at least one 👇

> [@Steve-Mcl](#):
>
> And yes, I've occasionally wished for these.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [27 November 2023 09:37 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/7 "2023-11-27T09:37:24Z")

</div>

Wish isn't wanted - we all wish for stuff in NR 🙂

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 November 2023 09:42 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/8 "2023-11-27T09:42:08Z")

</div>

Jeeez man. yes Yes YES there have been times I have wanted (needed) and ACTUALLY done the whole "has key =\> no wire, otherwise =\> wire" and the contain and the regex too. (but not the between)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 November 2023 19:57 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/9 "2023-11-27T19:57:42Z")

</div>

Looking/using your first post for my reply.

Where you want "not contains".  
Why not do this:

`contains` (what ever it is)  
`otherwise`

and use the `otherwise` output?

Just a thought.

Yes it would get messy if you have a lot of that type of filtering/switching to do as each would then require their own `switch` node.  
But just mentioning.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [27 November 2023 20:00 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/10 "2023-11-27T20:00:36Z")

</div>

> [@cymplecy](#):
>
> I'm often wanting "not contains" and either end up with an empty output wire by using contains first and stopping on 1st match (visually jarring)

I want to avoid an empty output just sitting there

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 November 2023 20:02 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/11 "2023-11-27T20:02:12Z")

</div>

Yeah fair enough.

't was just a thought. 😉

I really need to read things more than once before replying.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 January 2024 20:03 UTC](https://discourse.nodered.org/t/feature-request-additional-tests-in-switch-node/83195/12 "2024-01-26T20:03:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
