fromExtension static method

DocType fromExtension(
  1. String ext
)

Infers the DocType from a raw extension string (without the dot). Throws ArgumentError if the extension is unrecognised.

Implementation

static DocType fromExtension(String ext) {
  return switch (ext) {
    'pdf' => DocType.pdf,
    'doc' => DocType.doc,
    'docx' => DocType.docx,
    'xls' => DocType.xls,
    'xlsx' => DocType.xlsx,
    'ppt' => DocType.ppt,
    'pptx' => DocType.pptx,
    'txt' => DocType.txt,
    'csv' => DocType.csv,
    'rtf' => DocType.rtf,
    'odt' => DocType.odt,
    'ods' => DocType.ods,
    'odp' => DocType.odp,
    _ => throw ArgumentError('Unsupported document extension: .$ext'),
  };
}