Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Conform to 0.3.0 of typeid spec (#2)
Browse files Browse the repository at this point in the history
* list all commands when running `just`
* only init submodule if it hasn't been initialized
* allow for `_` in prefix
  • Loading branch information
mistermoe authored Jul 2, 2024
1 parent 82887b1 commit 2cc3c93
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
15 changes: 12 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
_help:
@just -l

get:
@dart pub get

analyze:
@dart analyze

test:
@git submodule init
@git submodule update
@dart test
#!/bin/bash
set -euo pipefail

if git submodule status | grep -q '^-'; then
git submodule init
git submodule update
fi

dart test
23 changes: 20 additions & 3 deletions lib/src/typeid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TypeId {
/// Decodes a TypeID into a [DecodedTypeId]. Throws [FormatException] if
/// the provided TypeID is invalid
static DecodedTypeId decode(String typeid) {
final parts = typeid.split(separator);
final parts = _splitLast(typeid, separator);

if (parts.length == 1) {
parts.insert(0, '');
Expand Down Expand Up @@ -59,10 +59,27 @@ class TypeId {
throw FormatException('Prefix too long');
}

// ensure all characters fall within [a-z]
final isValid = prefix.runes.every((code) => code > 96 && code < 123);
if (prefix.startsWith(separator) || prefix.endsWith(separator)) {
throw FormatException('Prefix cannot start or end with $separator');
}

// ensure all characters fall within [a-z_]
final isValid =
prefix.runes.every((code) => (code > 96 && code < 123) || code == 95);

if (!isValid) {
throw FormatException('prefix must only contain lowercase letters [a-z]');
}
}

static List<String> _splitLast(String input, String delimiter) {
int lastIndex = input.lastIndexOf(delimiter);
if (lastIndex == -1) {
// Delimiter not found, return the input as a single element list
return [input];
}
String beforeLast = input.substring(0, lastIndex);
String afterLast = input.substring(lastIndex + delimiter.length);
return [beforeLast, afterLast];
}
}
5 changes: 0 additions & 5 deletions lib/typeid.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;

export 'package:uuid/uuid.dart' show UuidValue;

export 'src/base32.dart';
export 'src/typeid.dart';
export 'src/decoded_typeid.dart';

// TODO: Export any libraries intended for clients of this package.
2 changes: 1 addition & 1 deletion typeid

0 comments on commit 2cc3c93

Please sign in to comment.