resolve method

  1. @override
Uri resolve(
  1. String text, {
  2. required String property,
})
override

The address text names. Throws an ArgumentError named property when text is malformed.

Implementation

@override
Uri resolve(String text, {required String property}) {
  final reference = text.substring(_prefix.length);
  final at = reference.lastIndexOf('@');
  final location = at < 0 ? reference : reference.substring(0, at);
  final ref = at < 0 ? 'HEAD' : reference.substring(at + 1);
  final parts = location.split('/');
  if (parts.length < 3 || parts.any((p) => p.isEmpty) || ref.isEmpty) {
    throw ArgumentError.value(
      text,
      property,
      'github: addresses look like github:owner/repo/path/to/file@ref',
    );
  }
  return Uri.https(
    'raw.githubusercontent.com',
    '/${parts[0]}/${parts[1]}/$ref/${parts.skip(2).join('/')}',
  );
}