···1313import gleam/regexp
1414import gleam/result
15151616-const pattern = "^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$"
1616+pub const pattern = "^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$"
17171818pub type DidError {
1919 InvalidRegexPattern(pattern: String)
···46464747/// Return the DID identifier.
4848///
4949-/// This function does convert the value to a valid DID format, for that
5050-/// use `to_string`.
4949+/// This function **does not** convert the value into a valid DID format,
5050+/// for that use `to_string`.
5151///
5252/// ## Examples
5353///
5454/// ```gleam
5555+/// import possum/did
5656+///
5557/// let identifier =
5658/// Did(Plc, "k5vecqzf4d5mdvkcu3mx6l5g")
5759/// |> did.identifier
···6769/// ## Examples
6870///
6971/// ```gleam
7272+/// import possum/did
7373+///
7074/// let string =
7175/// Did(Plc, "k5vecqzf4d5mdvkcu3mx6l5g")
7276/// |> did.to_string
···111115 Web
112116}
113117118118+/// Parse a string into a valid `Did` type
119119+/// If the value is not a valid string then an error is returned.
120120+///
121121+/// ## Examples
122122+///
123123+/// ```gleam
124124+/// import possum/did
125125+///
126126+/// let string = "did:plc:k5vecqzf4d5mdvkcu3mx6l5g"
127127+/// let assert Ok(did) = did.parse(string)
128128+/// ```
114129pub fn parse(content: String) -> Result(Did, DidError) {
115130 use with <- result.try(
116131 regexp.from_string(pattern)