From 5aeb6eda9ce50c27f243951fae7929272f63f2fb Mon Sep 17 00:00:00 2001 From: sticks Date: Sat, 19 Oct 2024 14:35:11 -0500 Subject: [PATCH] add examples and update readme --- README.md | 15 ++++++++++++--- example/idgen_dart_example.dart | 9 +++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2e7e7dd..438bdaa 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,18 @@ You will need a valid username and token to use this package. If you do not have ## Usage -TODO: Include short and useful examples for package users. Add longer examples -to `/example` folder. +You can see an example in the /example folder, but a simple example is shown below: ```dart -const like = 'sample'; +// Import the package +import 'package:teamhydra_idgen/teamhydra_idgen.dart'; + +void main() async { + IDGen idgen = IDGen(username: 'your_username', token: 'your_token'); + + // Generate a new ID, in this example we are generating a UUID V4 + IDGenResponse uuid = + await idgen.generateUUIDV4(); // all generations are async + print('Generated UUID: ${uuid.id}'); // print the generated ID +} ``` diff --git a/example/idgen_dart_example.dart b/example/idgen_dart_example.dart index 89b80f0..830299d 100644 --- a/example/idgen_dart_example.dart +++ b/example/idgen_dart_example.dart @@ -4,8 +4,9 @@ import 'package:teamhydra_idgen/teamhydra_idgen.dart'; void main() async { IDGen idgen = IDGen(username: 'your_username', token: 'your_token'); - // Generate a new ID, in this example we are generating a UUID V4 - IDGenResponse uuid = - await idgen.generateUUIDV4(); // all generations are async - print('Generated UUID: ${uuid.id}'); // print the generated ID + // A more complex example can be generating a new IDs with a specific alphabet + // and length + IDGenResponse newID = await idgen.generateNanoID( + alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', size: 20); + print('New ID: ${newID.id}'); }