Slugid class
A slugid is a URL-safe base64 encoded UUID v4 stripped of ==
padding.
This is just a compact encoding of UUIDs, that makes them safe to embed in URLs. A slugid is 22 characters long and looks as follows:
U_sWAEJnR4epXu-TK0FCYA
-8prq-8rTGqKl2W9SSfyDQ
ti8C-AKGQsq3rDjSuXe94w
Fum-zBhASyO50rg3mtQcD
As it is often useful to pass slugids as arguments to command line tools it
can be a good idea to use the nice form, which ensures that the slugid
cannot start with a dash -
. This comes at the cost of one bit of
randomness. Nice slugids looks as follows:
fUKuE0DcTqOvgvgRl0JHTQ
XT77loITSg6FYZjwoR7y8w
KIIrne-pSFuFz-zIFtGMeA
L_YriPk0RLuLyU8zb638oA
Instances of the Slugid class can be serialized to string using the toString() method. This is implicitely called when using string interpolation in dart.
Example
import 'package:slugid/slugid.dart';
print('New id: ${Slugid.nice()}');
- Annotations
-
- @sealed
Constructors
- Slugid(String id)
- Create a Slugid from slugid string or UUID string.
- Slugid.nice()
- Create a slugid in nice format.
- Slugid.v4()
- Create a slugid from v4 UUID, that is a random slugid.
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bytes(
) → List< int> - Get the raw bytes forming the unencoded slugid.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Get the Url-safe base64 encoded slugid.
override
-
uuid(
) → String - Render the slugid in it's UUID string representation.
Operators
-
operator ==(
Object other) → bool -
Compare slugid to
other
slugid.override