shlogg · Early preview
Justin Poehnelt @jpoehnelt

Converting UUIDs To User-Friendly Slugs In SvelteKit Stores

Convert UUIDs to slugs and back with SvelteKit store, using base64 encoding and regex pattern matching for 22 char slugs ending in 'Id' or 'id'.

Sometimes UUIDs are used as unique identifiers in URLs, but their length is not very user-friendly. A common pattern is to use a string encoding of the UUID to shorten the URL. This post will show how to apply that conversion in a SvelteKit store.
URL safe base 64 encoding uses the following characters: A-Z, a-z, 0-9, -, and _. The padding character = is not used and the characters + and / are replaced with - and _ respectively. See RFC 4648, sec. 5.

  
  
  UUID to Slug and Slug to UUID

Here is a simple implementation of the conversion functions. The uuid package is used to parse and string...