Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/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
10@validator
11def slug(value: str, /):
12 """Validate whether or not given value is valid slug.
14 Valid slug can contain only lowercase alphanumeric characters and hyphens.
15 It starts and ends with these lowercase alphanumeric characters.
17 Examples:
18 >>> slug('my-slug-2134')
19 # Output: True
20 >>> slug('my.slug')
21 # Output: ValidationError(func=slug, args={'value': 'my.slug'})
23 Args:
24 value: Slug string to validate.
26 Returns:
27 (Literal[True]): If `value` is a valid slug.
28 (ValidationError): If `value` is an invalid slug.
29 """
30 return re.match(r"^[a-z0-9]+(?:-[a-z0-9]+)*$", value) if value else False