parse method

  1. @override
Map<String, String> parse({
  1. required Iterable<String> lines,
  2. required bool shouldWarn,
})
override

Parse dot env.

Implementation

@override
Map<String, String> parse(
    {required Iterable<String> lines, required bool shouldWarn}) {
  final environment = <String, String>{};
  for (final (number, line) in lines.indexed) {
    final normalizeLine = line.trim();
    if (normalizeLine.isEmpty || normalizeLine.startsWith('#')) {
      continue;
    }

    final parts = normalizeLine.split('=').map((e) => e.trim());
    if (parts.length < 2) {
      throw InvalidLineError(number, line);
    }

    final key = parts.elementAt(0).trim();
    final value = parts
        .skip(1)
        .join('=')
        .split('#')
        .first
        .trim()
        .trimQuotationMarks()
        .tranUnicode();

    environment[key] = value;
  }

  return environment;
}