Skip to main content

New Comparators in Config V2

· 4 min read
Alex G. Mircean
Chavez Harris

Config V2 introduces New Comparators that make it much easier to create precise Targeting Rules by facilitating seamless comparison of texts, arrays, and dates.

New Comparators

Overview

The latest release showcases a variety of new comparators, each designed to offer specific functionalities for handling texts, arrays, and dates.

In this post, we'll illustrate these comparators with various examples.

New Text Comparators

In Config V2, we're introducing new text comparators, expanding your toolkit with options like EQUALS, NOT EQUALS, STARTS WITH ANY OF, NOT STARTS WITH ANY OF, ENDS WITH ANY OF, and NOT ENDS WITH ANY OF. Let's see them one by one.

EQUALS

Check if a given string exactly matches the specified value. For example:

"userType" EQUALS "admin"
Equals

Ensures only users with the type 'admin' are targeted.

NOT EQUALS

Determines if a string does not match the provided value. For example:

"Country" NOT EQUALS "Canada"
Not equals

Targets all users outside Canada.

STARTS WITH ANY OF

Tests if a string starts with any of the specified substrings. For example:

"Email" STARTS WITH ANY OF ["info@", "support@"]
Starts with any of

Would target emails starting with 'info@' or 'support@'.

NOT STARTS WITH ANY OF

Ensures a string does not start with any of the specified prefixes. For example:

"username" NOT STARTS WITH ANY OF ["temp", "guest"]
Not starts with any of

Excludes users with 'temp' or 'guest'.

ENDS WITH ANY OF

Check if a string ends with any of the given substrings. For example:

"file" ENDS WITH ANY OF [".pdf", ".docx"]
Ends with any of

Targets only files ending in .pdf or .docx.

NOT ENDS WITH ANY OF

Confirms a string does not end with any of the listed suffixes. For example:

"image" NOT ENDS WITH ANY OF [".png", ".jpg"]
Not ends with any of

Excludes images ending in .png or .jpg.

Date & Time Comparators

ConfigCat now includes Date and Time comparators, namely BEFORE and AFTER, making feature flag management simpler than ever. These comparators are perfect for managing time-specific campaigns like summer sales, Black Friday events, Christmas promotions, and more. They help you easily control when your promotions start and end, making it simple to run successful marketing campaigns.

BEFORE

Compares if a date is earlier than the specified date. For example:

"expiryDate" BEFORE "2022-12-31"
Date & Time before

Targets all items that expire before January 1, 2023.

AFTER

Determines if a date is later than the provided date. For example:

"startDate" AFTER "2023-01-01"
Date & Time after

Would target items starting from January 2, 2023.

Array Comparators

When it comes to managing arrays of strings, Config V2 offers powerful tools known as Array Comparators. These comparators are designed to handle arrays efficiently, simplifying complex comparisons.

ARRAY CONTAINS ANY OF

Verifies if any element of the array matches any of the specified values. For example:

"tags" ARRAY CONTAINS ANY OF ["urgent", "high-priority"]
Array contains any of

Targets items tagged as 'urgent' or 'high-priority'.

ARRAY NOT CONTAINS ANY OF

Check if the array does not contain any of the specified elements. For example:

"features" ARRAY NOT CONTAINS ANY OF ["beta"]
Array not contains any of

Targets all feature sets that do not include 'beta'.

Conclusion

What sets Config V2 apart is the ability to mix and match these comparators, empowering you to precisely tailor your Targeting Rules according to your desired user base. By implementing these comparators for texts, dates, and arrays, you ensure that your features reach the right users at the right time, enhancing both functionality and user satisfaction.

For more insights and updates on our latest tools, follow ConfigCat on X, Facebook, LinkedIn, and GitHub.