Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New factory functions with configurable regular expression for EmailAddress #388

Closed
2 of 5 tasks
LVMVRQUXL opened this issue Jan 28, 2024 · 3 comments
Closed
2 of 5 tasks
Labels
common Item related to all platforms. feature New feature or request.

Comments

@LVMVRQUXL
Copy link
Contributor

LVMVRQUXL commented Jan 28, 2024

📝 Description

We would like to introduce the following experimental factory functions with configurable regular expression for the EmailAddress type:

fun EmailAddress.Companion.create(
    text: String,
    configuration: EmailAddress.RegexConfiguration.() -> Unit
): EmailAddress

fun EmailAddress.Companion.createOrNull(
    text: String,
    configuration: EmailAddress.RegexConfiguration.() -> Unit
): EmailAddress?

interface EmailAddress.RegexConfiguration {
    var localPart: Regex
    var domain: Regex
}

Here's an example of calling the create(String, EmailAddress.RegexConfiguration.() -> Unit) function from Kotlin code:

val address: EmailAddress = EmailAddress.create("[email protected]") {
    localPart = Regex("[a-z]+") // the local part now only accepts 1 or more lowercase letters
    domain = Regex("[a-z]+\.[a-z]+") // the domain now only accepts lowercase letters
    // The regular expression used for validating the text input now looks like this: ^[a-z]+@[a-z]+\.[a-z]+$
}
println(address) // [email protected]

🔗 Dependencies

This issue is blocked by the following ones:

✅ Checklist

  • Add the create(String, EmailAddress.RegexConfiguration.() -> Unit) function, test its behavior with Kotlin and its compatibility with Java, update the public API binaries and update the unreleased changelog.
  • Add the createOrNull(String, EmailAddress.RegexConfiguration.() -> Unit) function, test its behavior with Kotlin and its compatibility with Java, update the public API binaries and update the unreleased changelog.
  • Close this issue as completed and update tracking ones if present.
@LVMVRQUXL LVMVRQUXL added feature New feature or request. common Item related to all platforms. labels Jan 28, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.5.0 milestone Jan 28, 2024
@LVMVRQUXL
Copy link
Contributor Author

LVMVRQUXL commented Jan 29, 2024

The DSL for setting the domain property should always include the dot (.) between labels.

Here's an example for configuring the domain name's regular expression from Kotlin code:

EmailAddress.create("[email protected]") {
    domain {
        topLevel = Regex("[a-z]+")
        secondLevel = firstLabel
    }
}

@LVMVRQUXL LVMVRQUXL removed this from the 4.5.0 milestone Jan 29, 2024
@LVMVRQUXL LVMVRQUXL added this to the 4.6.0 milestone Feb 8, 2024
@LVMVRQUXL LVMVRQUXL changed the title New factory functions with configurable regular expression for EmailAddress ✨ New factory functions with configurable regular expression for EmailAddress Feb 23, 2024
@LVMVRQUXL
Copy link
Contributor Author

We should take more time to design this solution according to the validation of the regular expression received from users.

@LVMVRQUXL LVMVRQUXL removed this from the 4.6.0 ✨ milestone Feb 27, 2024
@LVMVRQUXL
Copy link
Contributor Author

Another implementation of the EmailAddress type will be available after resolving #635.

@LVMVRQUXL LVMVRQUXL closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Item related to all platforms. feature New feature or request.
Projects
None yet
Development

No branches or pull requests

1 participant