@hero-page/hero-regex

1.0.0 • Public • Published

This entire repository was created completely with AI, using the hero-ai-package-creator, which is open-source, uses GPT-4, and is written & maintained by Sam Chahine ❣️🧞‍♀️

hero-regex

A set of utility functions for working with regular expressions, such as finding and replacing text patterns and validating user input.

Functions

findPattern

Finds the occurrences of a pattern in a given string. Test cases include matching plain text, case-insensitive matches, and ignoring whitespace. Extreme cases to handle are very long strings and patterns with nested groups. Ignore cases where the pattern is an empty string.

replacePattern

Replaces all occurrences of a pattern in a given string with a new value. Test cases include replacing plain text, case-insensitive matches, and preserving original capitalization. Extreme cases to handle are very long strings and replacing with an empty value. Ignore cases where the pattern is an empty string.

matchExact

Checks if a given string exactly matches a given pattern. Test cases include matching plain text, case-insensitive matches, and complex patterns with nested groups. Extreme cases to handle are very long strings and patterns. Ignore cases where the pattern is an empty string.

isEmail

Validates if a given string is a valid email address. Test cases include typical email formats, case-insensitive matches, and various domain extensions. Extreme cases to handle are long email addresses and internationalized domain names. Ignore cases with obvious invalid input such as empty strings or whitespace.

isURL

Validates if a given string is a valid URL. Test cases include typical URL formats, case-insensitive matches, and various domain extensions. Extreme cases to handle are long URLs and internationalized domain names. Ignore cases with obvious invalid input such as empty strings or whitespace.

hasDigits

Checks if a given string contains at least n digits. Test cases include varying lengths of digits, digits interspersed with non-digit characters, and strings with no digits. Extreme cases to handle are very long strings and n=0 (expect true for any input). Ignore cases with empty strings if n > 0.

hasUpperCase

Checks if a given string contains at least n uppercase characters. Test cases include varying lengths of uppercase characters, uppercase characters interspersed with lowercase characters, and strings with no uppercase characters. Extreme cases to handle are very long strings and n=0 (expect true for any input). Ignore cases with empty strings if n > 0.

hasLowerCase

Checks if a given string contains at least n lowercase characters. Test cases include varying lengths of lowercase characters, lowercase characters interspersed with uppercase characters, and strings with no lowercase characters. Extreme cases to handle are very long strings and n=0 (expect true for any input). Ignore cases with empty strings if n > 0.

hasSpecialChars

Checks if a given string contains at least n special (non-alphanumeric) characters. Test cases include varying lengths of special characters, special characters interspersed with alphanumeric characters, and strings with no special characters. Extreme cases to handle are very long strings and n=0 (expect true for any input). Ignore cases with empty strings if n > 0.

isLengthBetween

Checks if the length of a given string is between min and max values inclusive. Test cases include varying lengths of strings, strings exactly at min or max values, and strings with mixed character types. Extreme cases to handle are very long strings and min/max values close to or equal to JavaScript's maximum string length. Ignore cases with empty strings if min > 0.

isPalindrome

Checks if a given string is a palindrome, ignoring whitespace and case. Test cases include various palindromes, strings with spaces and special characters, and non-palindrome strings. Extreme cases to handle are long palindromes and palindromes with a large amount of whitespace. Ignore cases with only whitespace and/or empty strings.

countWords

Counts the number of words in a given string, delimited by whitespace. Test cases include strings with varying numbers of words, strings with punctuation, and strings with consecutive whitespace characters. Extreme cases to handle are very long strings and strings with large blocks of whitespace. Ignore cases with only whitespace and/or empty strings.

isPhoneNumber

Validates if a given string is a valid phone number. Test cases include various formats for phone numbers, international phone numbers, and numbers with special characters such as hyphens or parentheses. Extreme cases to handle are long phone numbers and phone numbers with many special characters. Ignore cases with obvious invalid input such as empty strings or whitespace.

isDate

Validates if a given string is a valid date. Test cases include various date formats (e.g. MM/DD/YYYY, YYYY-MM-DD), leap years, and different date ranges. Extreme cases to handle are dates near the minimum and maximum JavaScript date values. Ignore cases with obvious invalid input such as empty strings or whitespace.

isTime

Validates if a given string is a valid time. Test cases include various time formats (e.g. HH:mm, HH:mm:ss, hh:mm A), 12-hour and 24-hour formats, and different time ranges. Extreme cases to handle are times with uncommon formats, such as 2-digit hours in a 12-hour format. Ignore cases with obvious invalid input such as empty strings or whitespace.

isPostalCode

Validates if a given string is a valid postal code for a specific country. Test cases include various postal code formats for different countries, case-insensitive matches, and postal codes with special characters. Extreme cases to handle are postal codes with non-standard formats for their country. Ignore cases with obvious invalid input such as empty strings or whitespace.

isSSN

Validates if a given string is a valid U.S. Social Security Number (SSN). Test cases include various SSN formats, case-insensitive matches, and SSNs with special characters such as hyphens. Extreme cases to handle are SSNs with non-standard formats. Ignore cases with obvious invalid input such as empty strings or whitespace.

isCreditCard

Validates if a given string is a valid credit card number. Test cases include various credit card formats, case-insensitive matches, and credit card numbers with special characters such as spaces or hyphens. Extreme cases to handle are credit card numbers with non-standard formats. Ignore cases with obvious invalid input such as empty strings or whitespace.

isIBAN

Validates if a given string is a valid International Bank Account Number (IBAN). Test cases include various IBAN formats, case-insensitive matches, and IBANs with special characters such as spaces or hyphens. Extreme cases to handle are IBANs with non-standard formats. Ignore cases with obvious invalid input such as empty strings or whitespace.

isIP

Validates if a given string is a valid IP address (both IPv4 and IPv6). Test cases include various IP address formats, case-insensitive matches, and IPs with special characters. Extreme cases to handle are IPs with non-standard or deprecated formats. Ignore cases with obvious invalid input such as empty strings or whitespace.


Sam Chahine, at Hero

Tests for countWords

countWords

Tests for hasSpecialChars

hasSpecialChars

Tests for hasUpperCase

hasUpperCase

Tests for isCreditCard

isCreditCard

Tests for isDate

isDate

Tests for isEmail

isEmail

Tests for isIBAN

isIBAN

Tests for isIP

isIP

Tests for isLengthBetween

isLengthBetween

Tests for isPalindrome

isPalindrome

Tests for isPhoneNumber

isPhoneNumber

Tests for isPostalCode

isPostalCode

Tests for isSSN

isSSN

Tests for isTime

isTime

Tests for isURL

isURL

Tests for matchExact

matchExact

Tests for replacePattern

replacePattern

Tests for hasDigits

hasDigits

Tests for hasLowerCase

hasLowerCase

Tests for findPattern

findPattern

Package Sidebar

Install

npm i @hero-page/hero-regex

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

85.2 kB

Total Files

44

Last publish

Collaborators

  • hero-page