(patch) Enable pre-commit.
Some checks failed
/ Build and Test Library Snapshot (pull_request) Failing after 43s
Some checks failed
/ Build and Test Library Snapshot (pull_request) Failing after 43s
This commit is contained in:
parent
117f9fa6e6
commit
87c9e6b94f
3 changed files with 20 additions and 19 deletions
|
@ -2,16 +2,15 @@ package gs.slug.v0
|
|||
|
||||
import scala.util.matching.Regex
|
||||
|
||||
/**
|
||||
* Restricted string intended to be used as a unique, URL-safe identifier
|
||||
/** Restricted string intended to be used as a unique, URL-safe identifier
|
||||
* within some specific context (not a globally unique identifier). This type
|
||||
* adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$`
|
||||
*
|
||||
* Essentially, Slugs follow these rules:
|
||||
*
|
||||
* - Segments are defined as lowercase alphanumeric ASCII strings.
|
||||
* - Segments are separated by exactly one `-` character.
|
||||
* - At least one segment is required.
|
||||
* - Segments are defined as lowercase alphanumeric ASCII strings.
|
||||
* - Segments are separated by exactly one `-` character.
|
||||
* - At least one segment is required.
|
||||
*
|
||||
* If you need full unicode support, more characters, fewer constraints, etc.
|
||||
* don't use this type.
|
||||
|
@ -22,21 +21,22 @@ object Slug:
|
|||
|
||||
val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r
|
||||
|
||||
/**
|
||||
* Instantiate a [[Slug]] by validating the candidate input.
|
||||
*
|
||||
* @param candidate The candidate string used to create the [[Slug]].
|
||||
* @return The [[Slug]], or `None` if the candidate is invalid.
|
||||
*/
|
||||
/** Instantiate a [[Slug]] by validating the candidate input.
|
||||
*
|
||||
* @param candidate
|
||||
* The candidate string used to create the [[Slug]].
|
||||
* @return
|
||||
* The [[Slug]], or `None` if the candidate is invalid.
|
||||
*/
|
||||
def validate(candidate: String): Option[Slug] =
|
||||
if SlugPattern.matches(candidate) then Some(candidate) else None
|
||||
|
||||
given CanEqual[Slug, Slug] = CanEqual.derived
|
||||
|
||||
extension (slug: Slug)
|
||||
/**
|
||||
* Render this [[Slug]] as a string.
|
||||
*
|
||||
* @return The string representation of this [[Slug]].
|
||||
*/
|
||||
/** Render this [[Slug]] as a string.
|
||||
*
|
||||
* @return
|
||||
* The string representation of this [[Slug]].
|
||||
*/
|
||||
def str(): String = slug
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package gs.slug.v0
|
||||
|
||||
class SlugTests extends munit.FunSuite:
|
||||
|
||||
test("should instantiate valid slugs") {
|
||||
('a' to 'z').foreach(c => assertValidSlug(c.toString()))
|
||||
('0' to '9').foreach(c => assertValidSlug(c.toString()))
|
||||
|
|
Loading…
Add table
Reference in a new issue