패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.6.0

uuid

Dart용 RFC4122(v1, v4, v5, v6, v7, v8) UUID 생성기 및 파서

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1890만
좋아요
2.7천
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 개

소스 저장소

이 패키지를 사용하는 프로젝트

순위