Swiftpack.co - skytoup/shortuuid as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by skytoup.
skytoup/shortuuid 1.0.1
A generator library for concise, unambiguous and URL-safe UUIDs.
⭐️ 2
🕓 2 years ago
.package(url: "https://github.com/skytoup/shortuuid.git", from: "1.0.1")

ShortUUID

A Swift library that generates concise, unambiguous, URL-safe UUIDs. Based on and compatible with the Python library shortuuid and Go library shortuuid.

Usage

import ShortUUID

let su = ShortUUID()

You can then generate a short UUID

su.uuid() // vytxeTZskVKR7C7WgdSP3d

If you prefer a version 5 UUID, you can pass a name (DNS or URL) to the call and it will be used as a namespace (uuid.NAMESPACE_DNS or uuid.NAMESPACE_URL) for the resulting UUID:

su.uuid(name: "example.com") // wpsWLdLt9nscn2jbTD3uxe
su.uuid(name: "http://example.com") // c8sh5y9hdSMS6zVnrvf53T

You can also generate a cryptographically secure random string (using os.urandom(), internally) with:

su.random(length: 22) // RaF56o2r58hTKT7AYS9doj

To see the alphabet that is being used to generate new UUIDs:

su.alphabet // 23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

If you want to use your own alphabet to generate UUIDs

su.alphabet = "aaaaabcdefgh1230123"
su.uuid() // 0agee20aa1hehebcagddhedddc0d2chhab3b

shortuuid will automatically sort and remove duplicates from your alphabet to ensure consistency:

su.alphabet // 0123abcdefgh

License

MIT

GitHub

link
Stars: 2
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.1
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics