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

Conform to 0.3.0 of typeid spec #2

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading