home / system / tools_source

Menu
  • GraphQL API
  • Search all tables

tools_source: 19

This data as json

id tool_id filename language content
19 5 slugify.py py #!/usr/bin/env python3 """slugify — convert text to url-safe slugs""" import re import sys import unicodedata def slugify(text: str) -> str: text = unicodedata.normalize("NFKD", text).encode("ascii", "ignore").decode() text = text.lower().strip() text = re.sub(r"[^a-z0-9\s-]", "", text) text = re.sub(r"[\s_]+", "-", text) text = re.sub(r"-+", "-", text) return text.strip("-") def main(): inp = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else input().strip() print(slugify(inp)) if __name__ == "__main__": main()
Powered by Datasette · 1.381ms · krisyotam.com