パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.6.0

uuid

Dart用のRFC4122(v1、v4、v5、v6、v7、v8)UUIDジェネレータとパーサー

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1970万
いいね数
2740
Pub ポイント
160

パッケージをインストール

flutter pub add uuid

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

uuid パッケージは、Dart 用の RFC4122 UUID 標準(v1、v4、v5、v6、v7、v8)の包括的な実装を提供し、安全かつ信頼性の高い一意な識別子の生成と解析を可能にします。Android、iOS、Web、macOS、Windows、Linux など、すべての主要プラットフォームをサポートしています。データレコード、セッション管理、分散システムに一意な識別子が必要なアプリケーションに最適です。明確で直感的な API を備えており、Flutter および Dart プロジェクトへの統合を容易にします。

用途

  • データベースレコード用のユニークなIDを生成する
  • セッショントークンの作成
  • 分散型システムにおけるエンティティの特定
  • サービス間でのデータ整合性の確保
  • オフライン優先のアプリケーション状態管理をサポート

主な機能

  • 複数のUUIDバージョン(v1、v4、v5、v6、v7、v8)をサポートしています
  • クロスプラットフォーム互換性
  • 堅牢な解析と検証
  • シンプルでスムーズな API
  • RFC4122準拠

適している対象

  • Dart を使用したバックエンドサービス
  • ユニークな識別子が必要なFlutterアプリ
  • デバイス間のデータ同期
  • セキュリティに敏感なアプリケーション
  • 標準化されたID形式を必要とするアプリケーション

注意事項

  • 使用状況に応じて適切なUUIDバージョンを選択することを確認する
  • v1 UUID のプライバシーへの影響に注意してください
  • ユーザー入力の解析時にUUID形式を確認する
  • パフォーマンスが重要なパスで大量のv1 UUIDを生成しないようにしてください
  • 継続的なRFC標準の進化に伴い、更新を確認してください

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

uuid

Version 4.x.x is a complete redesign of the underlying setup, but tries to be API compatible or similar to 3.x.

Build Status

Simple, fast generation of RFC4122 and RFC9562 UUIDs.

Features:

  • Generate RFC4122 version 1, version 4, or version 5 UUIDs
  • Supports RFC9562 version 6, version 7, and version 8
  • Optional monotonic version 7 generator
  • Runs in web, server, and flutter
  • Cryptographically strong random number generation on all platforms
  • Validate and parse generic 128-bit hexadecimal values without enforcing UUID version or variant bits
  • Documentation

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'
Pubspec
dependencies:
  uuid: ^4.6.0
import 'package:uuid/uuid.dart';

var uuid = 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(Namespace.url.value, 'www.google.com'); // -> 'c74a196f-f19d-5ea9-bffd-a2742432fc9c'
Structural 128-bit parsing

Use the explicit format APIs when the input must be a 128-bit hexadecimal value but UUID version and variant bits should not be enforced.

const value = '019f13f5-53cb-b219-ca3e-4b569376f32b';

Uuid.isValidUUIDFormat(fromString: value); // true
Uuid.parseHex128(value); // 16 bytes

const withoutDashes = '019f13f553cbb219ca3e4b569376f32b';
Uuid.parseHex128(withoutDashes, noDashes: true); // 16 bytes
Monotonic v7

uuid.v7() fills everything after the millisecond timestamp with random bits, so ids created in the same millisecond have no defined order. UuidV7Monotonic replaces the most significant of those random bits with a 16-bit counter (RFC 9562 §6.2, Method 1), so ids from one generator sort in creation order under an ordinary string comparison (or byte comparison if parsed).

import 'package:uuid/uuid.dart';
import 'package:uuid/v7monotonic.dart';

// Plain v7, both created in the same millisecond. Creation order and sort
// order happen to disagree.
const uuid = Uuid();
uuid.v7(); // -> '019fcd85-9fac-7f64-8711-97a4665f1adc'
uuid.v7(); // -> '019fcd85-9fac-715d-80d0-556404fa23ea'

// Monotonic, also within one millisecond. The counter defines the order.
final generator = UuidV7Monotonic();
generator.generate(); // -> '019fcd85-9fb3-7488-a625-f7a830c2dcf7'
generator.generate(); // -> '019fcd85-9fb3-7488-a87c-0c31456d733b'

Import the generator directly; it is not exported from uuid.dart.

Some limits of the monotonic generator:

  1. Ordering only holds within one generator instance. v7 cannot order concurrent generators against each other without shared state.
  2. Ids strictly increase unless the clock moves backward by more than 10 seconds, which resets ordering to the new clock reading. Ids stay unique across the reset.
  3. Ids are not secret tokens. The counter increments by exactly +1 within a millisecond, so an observer holding one id can predict the next. Use v4 if unguessability matters.

Documentation

For documentation, please visit the Documentation page. Examples are included for most functions and classes.

For more complex examples and other usages, please look at the tests.

Release notes

See CHANGELOG

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング