A Lua implementation of skeddles/sluggify for generating URL slugs
The following manipluations are performed in this order:
- replace slashes
/\and spaceswith dashes- - replace any accented characters with their closest non-accented equvalent, e.g.
ébecomese - remove all non-alphanumeric characters (anything other than
A-Z,a-z,0-9, and-) - replace multiple consecutive dashes
---with a single dash- - remove leading dashes, e.g.
-Gengar-becomesGengar- - remove trailing dashes, e.g.
Gengar-becomesGengar - convert to lowercase, e.g.
Gengarbecomesgengar
This module relies on the Lua utf-8 library which should be built into Lua, but isn't always. You've been warned!
local sluggify = require("sluggify")
local slug = sluggify.sluggify("Pokémon Blue!")
print(slug)
assert(slug == "pokemon-blue") -- expected outputpokemon-blueThis was originally written for my Lospec Palette Importer Aseprite extension, but I thought it might be useful on its own.
Thanks to Sam Keddy for the inspiration!