sane_uuid 1.0.1 copy "sane_uuid: ^1.0.1" to clipboard
sane_uuid: ^1.0.1 copied to clipboard

A sane UUID implementation with support for generating and handling v1, v4 and v5 UUIDs according to RFC4122.

example/example.dart

import 'package:sane_uuid/uuid.dart';

void main() {
  // randomly generated using secure random number generator
  final Uuid randomUuid = Uuid.v4();

  // parse any common UUID string
  final parsedHyphenated = Uuid.fromString(
    'a8796ef4-8767-4cd0-b432-c5e93ba120df',
  );
  final parsedWithoutHyphens = Uuid.fromString(
    'a8796ef487674cd0b432c5e93ba120df',
  );

  // UUID objects have proper equality and hashCode
  assert(parsedHyphenated == parsedWithoutHyphens);
  assert(parsedHyphenated.hashCode == parsedWithoutHyphens.hashCode);

  // UUID objects can be compared/sorted lexicographically
  final biggerUuid = Uuid.fromString(
    'b8796ef4-8767-4cd0-b432-c5e93ba120df',
  );
  final smallerUuid = Uuid.fromString(
    '18796ef4-8767-4cd0-b432-c5e93ba120df',
  );
  final list = [biggerUuid, smallerUuid, parsedHyphenated];
  list.sort();
  // Is ordered like this now: [smallerUuid, parsedHyphenated, biggerUuid]
  print(list);

  // Access any detailed information in the UUID:
  final timeBasedUuid = Uuid.v1();
  assert(timeBasedUuid.version == 1);
  final time = timeBasedUuid.parsedTime;
  // A usable DateTime timestamp for v1 UUIDs!
  print(time);
}
3
likes
160
points
50.6k
downloads

Publisher

verified publisherbjoernpetersen.net

Weekly Downloads

A sane UUID implementation with support for generating and handling v1, v4 and v5 UUIDs according to RFC4122.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

crypto, meta

More

Packages that depend on sane_uuid