Viewing version 0.4.1. Open the latest package page.

uuid

0.4.1

RFC4122(v1,v4,v5) UUID Generator and Parser.

Download archive

Readme

dart-uuid

Simple, fast generation of RFC4122 UUIDs.

Heavily based on node-uuid by Robert Kieffer (I even copied this readme over and modified it.) Primarily becaue it works, well written, and so on.

Features:

  • Generate RFC4122 version 1, version 4, or version 5 UUIDs
  • Runs in dartvm and browsers.
  • Cryptographically strong random number generation on all platforms
  • Annotated source code

Getting Started

Instructions

  1. Open a command line and cd to your projects root folder
  2. In your pubspec, add an entry for dart-uuid to your dependencies (example below)
  3. pub install
  4. If you wish to run tests, go into packages/dart-uuid/ and run 'dart test/uuid_test.dart'

Pubspec

There are 2 options. Directly from git, or from pub.dartlang.org

pub.dartlang.org: (you can use 'any' instead of a version if you just want the latest always)

dependencies:
  uuid: 0.4.1
import 'package:uuid/uuid.dart';

var uuid = new Uuid();

Then create some ids ...

// Generate a v1 (time-based) id
uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'

// Generate a v4 (random) id
uuid.v4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1'

// Generate a v5 (namespace-name-sha1-based) id
uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c'

API

uuid.v1({Map options: null, List buffer: null, int offset: 0})

Generate and return a RFC4122 v1 (timestamp-based) UUID.

  • options - (Map) Optional uuid state to apply. Properties may include:

    • node - (List) Node id as List of 6 bytes (per 4.1.6). Default: Randomnly generated ID.
    • clockseq - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.
    • msecs - (Number) Time in milliseconds since unix Epoch. Default: The current time is used.
    • nsecs - (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if msecs is unspecified. Default: internal uuid counter is used, as per 4.2.1.2.
  • buffer - (List) Array or buffer where UUID bytes are to be written.

  • offset - (Int) Starting index in buffer at which to begin writing.

Returns buffer, if specified, otherwise the string form of the UUID

Example: Generate string UUID with fully-specified options

uuid.v1(options: {
    'node': [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
    'clockSeq': 0x1234,
    'mSecs': new Date(2011,11,01).millisecondsSinceEpoch,
    'nSecs': 5678
})   // -> "1d6a6e2e-0457-11e1-9234-0123456789ab"

Example: In-place generation of two binary IDs

// Generate two ids in an array
var myBuffer = new List(32); // -> []
uuid.v1(buffer: myBuffer);   
// -> [115, 189, 5, 128, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]
uuid.v1(buffer: myBuffer, offset: 16);  
// -> [115, 189, 5, 128, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128, 115, 189, 5, 129, 201, 91, 17, 225, 146, 52, 109, 0, 9, 0, 52, 128]

// Optionally use uuid.unparse() to get stringify the ids
uuid.unparse(buffer: myBuffer);    // -> '73bd0580-c95b-11e1-9234-6d0009003480'
uuid.unparse(buffer: myBuffer, offset: 16) // -> '73bd0581-c95b-11e1-9234-6d0009003480'

uuid.v4({Map options: null, List buffer: null, int offset: 0})

Generate and return a RFC4122 v4 UUID.

  • options - (Map) Optional uuid state to apply. Properties may include:

    • random - (Number[16]) List of 16 numbers (0-255) to use in place of randomly generated values
    • rng - (Function) Random # generator to use. A Custom function that returns an list[16] of byte values or 1 of 2 provided.
  • buffer - (List) Array or buffer where UUID bytes are to be written.

  • offset - (Number) Starting index in buffer at which to begin writing.

Returns buffer, if specified, otherwise the string form of the UUID

Example: Generate string UUID with fully-specified options

uuid.v4(options: {
  'random': [
    0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
    0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
  ]
});
// -> "109156be-c4fb-41ea-b1b4-efe1671c5836"

Example: Generate two IDs in a single buffer

var myBuffer = new List(32);
uuid.v4(buffer: myBuffer);
uuid.v4(buffer: myBuffer, offset: 16);

uuid.v5(String namespace, String name, {Map options: null, List buffer: null, int offset: 0})

Generate and return a RFC4122 v5 UUID.

  • options - (Map) Optional uuid state to apply. Properties may include:

    • randomNamespace - (Boolean) Default True. Returns if you want a v4 generated namespace (true) or NAMESPACE_NIL (false)
  • buffer - (List) Array or buffer where UUID bytes are to be written.

  • offset - (Number) Starting index in buffer at which to begin writing.

Returns buffer, if specified, otherwise the string form of the UUID

Example: Generate string UUID with fully-specified options

uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com');
// -> "c74a196f-f19d-5ea9-bffd-a2742432fc9c"

Example: Generate two IDs in a single buffer

var myBuffer = new List(32);
uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com', buffer: myBuffer);
uuid.v5(Uuid.NAMESPACE_URL, 'www.google.com', buffer: myBuffer, offset: 16);

uuid.parse(String uuid, {List buffer: null, int offset: 0})

uuid.unparse(List buffer, {int offset: 0})

Parse and unparse UUIDs

  • id - (String) UUID(-like) string
  • buffer - (List) Array or buffer where UUID bytes are to be written. Default: A new Array or Buffer is used
  • offset - (Int | Number) Starting index in buffer at which to begin writing. Default: 0

Example parsing and unparsing a UUID string

var bytes = uuid.parse('797ff043-11eb-11e1-80d6-510998755d10'); // -> [121, 127, 240, 67, 17, 235, 17, 225, 128, 214, 81, 9, 152, 117, 93, 16]
var string = uuid.unparse(bytes); // -> '797ff043-11eb-11e1-80d6-510998755d10'

Testing

In dartvm

dart test\uuid_test.dart

In Browser

N/A as I have not used or tested this in the browser. But there are users of this library that do, and reported that it does infact work.

Benchmarking

Its pretty quick, but no official benchmarking.

Release notes

See CHANGELOG

Changelog

v0.4.1

  • Changed initCipher location so that if you ever only use v1 UUIDs, you will get a very small Dart2JS output compared to v4 or v5 that do load it.

v0.4.0

  • Use Cipher base.dart, as I don't need entropy generators, and this allows me to merge client/server together again and fix many issues this caused.

v0.3.2

  • Fix import/library bug.

v0.3.1

  • Update pubspec to allow installation of the latest Cipher 0.7.

v0.3.0

  • Updated to latest Cipher at 0.6.0. This created a breaking change in the imports. Please make sure you update your code.
  • Fixed problem when creating v4 UUIDs too fast, it would create duplicate UUIDs.

v0.2.2

  • Pegging cipher to 0.4.0 temporarily for browser support

v0.2.1

  • Using new version of cipher.

v0.2.0

  • Dart 1.0 Readiness
  • Switched from custom AES to cipher package AES.

v0.1.6

  • Adjusting usage of constants.
  • Fixing tests.

v0.1.5

  • Stupid typo on import.

v0.1.4

  • Fixing Crypto package move.

v0.1.3

  • Fixing language changes.

v0.1.2

  • Fix change of charCodes to codeUnits

v0.1.1

  • Fixing syntax for upcoming breaking changes.

v0.1.0

  • Cleanup, changes, and prep for M3.

v0.0.9

  • Minor fix with a const RegExp
  • Made sure everything builds on latest dart.
  • Fixed pubspec to now import unittest from pub instead of sdk.

v0.0.8

  • Changed to the new optional paramater syntaxes and usages.
  • Adjusted tests for the new function call style due to parameter change.
  • Fixed Import/Source/Library statements to the new format.

v0.0.7

  • Made changes requested by the Google team to get my package up on pub.dartlang.org

v0.0.6

  • Fixed up some code to make it possibly faster and using better Dart practices.
  • Cleaned up some documentation.

v0.0.5

  • Added Initial AES for Dart (untested if it actually works/matches other AES encryptors)
  • Use AES cipher to create crypto strong bytes.

v0.0.4

  • Issue wasn't Math.Random() but a bad reseed by me.
  • Cleaned up for new Pub layout.

v0.0.3

  • Added UUIDv5
  • Fixed UUIDv4 bugs
  • Added more unit tests
  • Found bug in dart's Math.Random(), reported, waiting for fix to fix my code.

v0.0.2

  • Initial tests
  • Fixed some parser bugs.

v0.0.1

  • Initial Release
  • No tests

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'uuid:0.4.1'
pubspec.yaml
name: uuid
version: 0.4.1
description: >
  RFC4122(v1,v4,v5) UUID Generator and Parser.
author: Yulian Kuncheff <yulian@kuncheff.com>
homepage: https://github.com/Daegalus/dart-uuid
environment:
  sdk: ">=1.0.0 <2.0.0"
dependencies:
  crypto: ">=0.9.0 <0.10.0"
  cipher: ">=0.7.0 <0.8.0"
dev_dependencies:
  unittest: any

Version history

VersionPublishedArchiveSHA-256
0.0.6Cached · Upstream SHA-256 matchedDownloadd27bb6c0…be6d19
0.0.7Cached · Upstream SHA-256 matchedDownloadd5825879…e2df2c
0.0.8Cached · Upstream SHA-256 matchedDownload1a476151…e5f25f
0.0.9Cached · Upstream SHA-256 matchedDownload52a46f15…8de3e9
0.1.0Cached · Upstream SHA-256 matchedDownloadb584cb32…c9072b
0.1.1Cached · Upstream SHA-256 matchedDownload32467249…f32c88
0.1.2Cached · Upstream SHA-256 matchedDownload955a0b19…66d502
0.1.3Cached · Upstream SHA-256 matchedDownload2ba86667…c61076
0.1.4Cached · Upstream SHA-256 matchedDownloaddb2564b6…bfc740
0.1.5Cached · Upstream SHA-256 matchedDownload2f47eaa3…17a80e
0.1.6Cached · Upstream SHA-256 matchedDownloadb5fb17f2…d01e46
0.2.0Cached · Upstream SHA-256 matchedDownload930a60d0…c344a4
0.2.1Cached · Upstream SHA-256 matchedDownload2099b36e…cc6c06
0.2.2Cached · Upstream SHA-256 matchedDownload5e639255…c44715
0.3.0Cached · Upstream SHA-256 matchedDownload601c357d…7d5bcf
0.3.1Cached · Upstream SHA-256 matchedDownloada6a21f04…6c0928
0.3.2Cached · Upstream SHA-256 matchedDownload6833ce79…b17506
0.4.0Cached · Upstream SHA-256 matchedDownloadf2438445…fc605a
0.4.1Cached · Upstream SHA-256 matchedDownloadec889bc5…016f1d
0.5.0Cached · Upstream SHA-256 matchedDownload182e0f47…ec1565
0.5.1Cached · Upstream SHA-256 matchedDownload07fee225…724990
0.5.2Cached · Upstream SHA-256 matchedDownloadfdf930c6…674cc4
0.5.3Cached · Upstream SHA-256 matchedDownload5ee46227…73d3f8
1.0.0Cached · Upstream SHA-256 matchedDownload1524595b…cb95f9
1.0.1Cached · Upstream SHA-256 matchedDownload9d076ca7…b9ae9f
1.0.2Cached · Upstream SHA-256 matchedDownloada7605e1c…f1754e
1.0.3Cached · Upstream SHA-256 matchedDownload1b9363b6…11d1e2
2.0.0-rc1Cached · Upstream SHA-256 matchedDownloadfae79d68…a80336
2.0.0Cached · Upstream SHA-256 matchedDownload4930c7aa…5b3caa
2.0.1Cached · Upstream SHA-256 matchedDownload78a84f69…6c78f0
2.0.2Cached · Upstream SHA-256 matchedDownload9007ebb8…a18370
2.0.3Cached · Upstream SHA-256 matchedDownloadfe6702d3…31c8d8
2.0.4Cached · Upstream SHA-256 matchedDownload4c4896fe…77d56e
2.1.0Cached · Upstream SHA-256 matchedDownload9f6a5645…064312
2.2.0Cached · Upstream SHA-256 matchedDownload467d0a24…9a9e99
2.2.1Cached · Upstream SHA-256 matchedDownloadbedb244e…9fd2fd
2.2.2Cached · Upstream SHA-256 matchedDownloadbd96a5d8…6d81b0
3.0.0-nullsafety.0Cached · Upstream SHA-256 matchedDownloadc0a46930…20b156
3.0.0-nullsafety.1Cached · Upstream SHA-256 matchedDownload68dff0a6…8b2540
3.0.0Cached · Upstream SHA-256 matchedDownload9947b48c…a62ac6
3.0.1Cached · Upstream SHA-256 matchedDownload29aa6310…e99d50
3.0.2Cached · Upstream SHA-256 matchedDownloade89f208c…1d2ccb
3.0.3Cached · Upstream SHA-256 matchedDownload4fe24cb4…6a566a
3.0.4Cached · Upstream SHA-256 matchedDownload0ea20bfc…ca3758
3.0.5Cached · Upstream SHA-256 matchedDownload00ba1241…fc7714
3.0.6Cached · Upstream SHA-256 matchedDownload2469694a…9a8afc
3.0.7Cached · Upstream SHA-256 matchedDownload648e1030…519313
4.0.0-beta1Cached · Upstream SHA-256 matchedDownload20e95d65…17cde3
4.0.0-beta1-1Cached · Upstream SHA-256 matchedDownloade3cfb7bf…a6159f
4.0.0-beta2Cached · Upstream SHA-256 matchedDownload12bf9edc…bcd470
4.0.0-beta3Cached · Upstream SHA-256 matchedDownload3b261f49…1ee4c0
4.0.0-beta3-1Cached · Upstream SHA-256 matchedDownload2dd495c0…7bd8db
4.0.0Cached · Upstream SHA-256 matchedDownloade0392888…3c3134
4.1.0Cached · Upstream SHA-256 matchedDownloadb715b8d3…4af2a7
4.2.0Cached · Upstream SHA-256 matchedDownload49ea0b5f…a2337b
4.2.1Cached · Upstream SHA-256 matchedDownloaddf5a4d8f…889921
4.2.2Cached · Upstream SHA-256 matchedDownload22c94e5a…82127f
4.3.0Cached · Upstream SHA-256 matchedDownload505d0e80…26e5b8
4.3.1Cached · Upstream SHA-256 matchedDownloadbb55f389…1f36bc
4.3.2Cached · Upstream SHA-256 matchedDownload8c951c9c…3d4d77
4.3.3Cached · Upstream SHA-256 matchedDownloadcd210a09…aa81c8
4.4.0Cached · Upstream SHA-256 matchedDownload814e9e88…fd1ba8
4.4.1Cached · Upstream SHA-256 matchedDownloadb3e1cb24…50f3fa
4.4.2Cached · Upstream SHA-256 matchedDownload83d37c7a…ffaa90
4.5.0Cached · Upstream SHA-256 matchedDownloadf33d6bb6…576a77
4.5.1Cached · Upstream SHA-256 matchedDownloada5be9ef6…1690ff
4.5.2Cached · Upstream SHA-256 matchedDownloada11b6664…6f96e8
4.5.3Cached · Upstream SHA-256 matchedDownload1fef9e8e…a79489
4.6.0Cached · Upstream SHA-256 matchedDownload9b129329…d01dcd

Dependencies

cipher "\u003e=0.7.0 \u003c0.8.0"

crypto "\u003e=0.9.0 \u003c0.10.0"