nuid 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

dart-nuid #

A Dart-lang implementation of NATS Unique Identifiers inspired by node-nuid like UUID, but much faster and lighter. The NUID contains numbers and capital letters only, i.e. it works with base 36.

Examples: #

Run the example/main.dart:

dart example/main.dart
import 'package:nuid/nuid.dart';

void main() {
  print('String:');
  print('  First nuid:');
  for(var i = 0; i < 4; i++){
    print('  - ${nuid.next()}');
  }

  print('  Reseting nuid:');
  nuid.reset();

  for(var i = 0; i < 4; i++){
    print('  - ${nuid.next()}');
  }

  print('\nBytes:');
  print('  First nuid:');
  for(var i = 0; i < 4; i++){
    print('  - ${nuid.nextBytes()}');
  }

  print('  Reseting nuid:');
  nuid.reset();

  for(var i = 0; i < 4; i++){
    print('  - ${nuid.nextBytes()}');
  }
}

As code above shows, there are two methods: next and nextBytes. They return the nuid in a String and List<int> format respectively. The lastone is designed to be compatible with Socket in dart:io library.

Performance #

NUID needs to be very fast to generate and be truly unique, all while being entropy pool friendly. NUID uses 12 bytes of crypto generated data (entropy draining), and 10 bytes of pseudo-random sequential data that increments with a pseudo-random increment.

Total length of a NUID string is 22 bytes of base 36 ascii text, so 36^22 or 17324272922341479351919144385642496 possibilities.

1.1.0 #

  • Improving project description
  • Adding test

1.0.0 #

  • Improving variables namespacing using static attributes instead of global variables.
  • Adding getter current and buffer to read the current buffer.

0.7.0 #

Working with List<int> type because of TCP protocol user this type. Then, this will help to optimize NATS package

0.6.16 #

A translation of https://github.com/nats-io/node-nuid

example/main.dart

import 'package:nuid/nuid.dart';

void main() {
  final nuid = Nuid.instance;

  print('String:');
  print('  First nuid:');
  for (var i = 0; i < 4; i++) {
    print('  - ${nuid.next()}');
  }

  print('  Reseting nuid:');
  nuid.reset();

  for (var i = 0; i < 4; i++) {
    print('  - ${nuid.next()}');
  }

  print('\nBytes:');
  print('  First nuid:');
  for (var i = 0; i < 4; i++) {
    print('  - ${nuid.nextBytes()}');
  }

  print('  Reseting nuid:');
  nuid.reset();

  for (var i = 0; i < 4; i++) {
    print('  - ${nuid.nextBytes()}');
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  nuid: ^1.1.0

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:nuid/nuid.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Jan 24, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Fix lib/nuid.dart. (-0.50 points)

Analysis of lib/nuid.dart reported 1 hint:

line 8 col 23: Use lowercase_with_underscores when specifying a library prefix.

Dependencies

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