Path.from constructor

Path.from(
  1. String path, {
  2. String? type,
})

Implementation

factory Path.from(String path, {String? type}) {
  final segs = path.split('/');
  segs.removeWhere((s) => s.isEmpty);

  String? name;
  if (segs.isNotEmpty) {
    final file = segs.last.split('.');
    if (file.length == 2 && file.last.isNotEmpty || type != null) {
      type ??= file.last;
      name = file.first;
      segs.removeLast();
    }
  }
  return Path(segs, filename: name, filetype: type);
}