flake_uuid 0.1.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 46

Flake UUID #

Flake UUID is a Dart library that provides 64- and 128-bit, k-ordered identifiers, which preserve their order of creation (somewhat) if sorted lexically.

It generates conflict-free and unique identifiers without further coordination between the nodes on your cluster (assuming time goes forward and machine IDs are unique).

64-bit Flake ID #

The 64-bit Flake ID is created with:

  • 42-bit timestamp (millis since epoch, good til the end of this century)
  • 10-bit machine ID
  • 11-bit sequence (incremented within the same millisecond)

A simple usage example, works only with Dart VM, because it uses the environment to generate a somewhat-random machine ID:

import 'package:flake_uuid/flake_uuid.dart';

main() {
  var x = flake64.nextInt();
  var y = flake64.nextHex(); // '2b06cca4f5542000'
}

A more detailed version if you use the class directly. You must supply a pre-coordinated machine ID:

import 'package:flake_uuid/flake_base.dart';

main() {
  var flake = new Flake64(machineId: 123);
  var x = flake.nextInt();
  var y = flake.nextHex();
}

128-bit Flake ID #

The 128-bit Flake ID is created with:

  • 64-bit timestamps (macroseconds(!) since epoch, won't run out in your lifetime)
  • 48-bit machine ID
  • 16-bit sequence (incremented within the same macrosecond)

A simple usage example, works only with Dart VM, because it uses the environment to generate a somewhat-random machine ID:

import 'package:flake_uuid/flake_uuid.dart';

main() {
  var y = flake128.nextHex(); // '2b06cca4f5542000'
}

A more detailed version if you use the class directly. You must supply a pre-coordinated machine ID:

import 'package:flake_uuid/flake_base.dart';

main() {
  var flake = new Flake128(machineId: 123);
  var x = flake.nextInt(); // not recommended
  var y = flake.nextHex(); // '000540947b2305c4a25c0001c73a0000'
  var z = flake.nextUuid(); // '00054094-7b23-05c4-a25c-0001c73a0001'
}

Changelog #

0.1.3 #

  • Dart 2 support.

0.1.2 #

  • Update project with analysis suggestions.

0.1.1 #

  • Option for continuous sequence increments.

0.1 #

  • Updated 128-bit flake with UUID-formatting.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flake_uuid: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flake_uuid/flake_uuid.dart';
  
Version Uploaded Documentation Archive
0.1.3 Sep 9, 2018 Go to the documentation of flake_uuid 0.1.3 Download flake_uuid 0.1.3 archive
0.1.2 May 28, 2018 Go to the documentation of flake_uuid 0.1.2 Download flake_uuid 0.1.2 archive
0.1.1 May 6, 2017 Go to the documentation of flake_uuid 0.1.1 Download flake_uuid 0.1.1 archive
0.1.0 Apr 2, 2017 Go to the documentation of flake_uuid 0.1.0 Download flake_uuid 0.1.0 archive
0.0.2 Nov 12, 2016 Go to the documentation of flake_uuid 0.0.2 Download flake_uuid 0.0.2 archive
0.0.1 Nov 5, 2016 Go to the documentation of flake_uuid 0.0.1 Download flake_uuid 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jun 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: Flutter, other

Primary library: package:flake_uuid/flake_uuid.dart with components: io.

Health suggestions

Fix lib/flake_base.dart. (-5.84 points)

Analysis of lib/flake_base.dart reported 12 hints, including:

line 33 col 21: Use = to separate a named parameter from its default value.

line 34 col 22: Use = to separate a named parameter from its default value.

line 35 col 25: Use = to separate a named parameter from its default value.

line 37 col 28: Use = to separate a named parameter from its default value.

line 40 col 7: DO use curly braces for all flow control structures.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flake_uuid.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0