Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/validators/slug.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Slug."""
3# standard
4import re
6# local
7from .utils import validator
9_SLUG_REGEXP = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
12@validator
13def slug(value: str, /):
14 """Validate whether or not given value is valid slug.
16 Valid slug can contain only lowercase alphanumeric characters and hyphens.
17 It starts and ends with these lowercase alphanumeric characters.
19 Examples:
20 >>> slug('my-slug-2134')
21 True
22 >>> slug('my.slug')
23 ValidationError(func=slug, args={'value': 'my.slug'})
25 Args:
26 value: Slug string to validate.
28 Returns:
29 (Literal[True]): If `value` is a valid slug.
30 (ValidationError): If `value` is an invalid slug.
31 """
32 return _SLUG_REGEXP.fullmatch(value) is not None