Skip to content

v5.0.0

Latest

Choose a tag to compare

@lithammer lithammer released this 26 Aug 20:37
1265b4a

v5.0.0

What’s Changed

  • Add explicit UUID generation with NewV4, NewV5, and NewV7, including time-sortable short UUIDs, by @lithammer in #84
  • Add UUIDv5 and the standard DNS, URL, OID, and X.500 namespace IDs by @lithammer in #84
  • Add reusable custom-alphabet encoders with NewEncoder by @lithammer in #84
  • Replace github.com/google/uuid with Go’s standard library uuid package, leaving shortuuid with no dependencies, by @lithammer in #84
  • Speed up reusable custom-alphabet encoding and decoding by precomputing lookup tables by @lithammer in #86

Migrating from v4

v5 requires Go 1.27 and uses the module path:

import "github.com/lithammer/shortuuid/v5"

Custom Encoder implementations must use the standard library uuid.UUID type instead of github.com/google/uuid.UUID. Both types have the same [16]byte representation, so values can be converted directly.

NewWithNamespace, NewWithEncoder, and NewWithAlphabet still work but are deprecated. Prefer explicit versions and reusable encoders:

shortuuid.NewV5(shortuuid.NameSpaceDNS, "example.com")

enc := shortuuid.NewEncoder(alphabet)
enc.Encode(uuid.NewV7())

Existing encoding and deterministic ID outputs remain unchanged. New also keeps its current v4 behavior.

On an Apple M2 with Go 1.27, reusable custom-alphabet benchmarks took 21% less time for base16 encoding, 49% less for multibyte base16 encoding, and 52% less for multibyte decoding compared with v4.3.0. The deprecated NewWithAlphabet took 26% longer with a multibyte alphabet because it rebuilds the new lookup tables on every call; build one NewEncoder and reuse it.

Full Changelog: v4.3.0...v5.0.0