encode function

String encode(
  1. String filename,
  2. {String separator = '-',
  3. bool withSpaces = false,
  4. bool lowercase = false,
  5. bool onlyAlphanumeric = false}
)

Implementation

String encode(
  String filename, {
  String separator = '-',
  bool withSpaces = false,
  bool lowercase = false,
  bool onlyAlphanumeric = false,
}) {
  String returnString = filename;
  onlyAlphanumeric
      ? returnString = returnString.replaceAll(onlyAlphanumericRegex, '')
      : reservedCharacters.forEach((c) {
          returnString = returnString.replaceAll(c, separator);
        });
  if (!withSpaces) returnString = returnString.replaceAll(' ', separator);
  return lowercase ? returnString.toLowerCase() : returnString;
}