decode function
Decodes a TOON-formatted string to a Dart value.
input The TOON-formatted string to parse
options Optional decoding options
Returns a Dart value (Map, List, or primitive) representing the parsed TOON data
Implementation
Object? decode(String input, {DecodeOptions? options}) {
final resolvedOptions = (options ?? const DecodeOptions()).resolve();
final scanResult = toParsedLines(input, resolvedOptions.indent, resolvedOptions.strict);
final cursor = LineCursor(scanResult.lines, scanResult.blankLines);
final decoded = decodeValueFromLines(cursor, resolvedOptions);
// Apply unflattening if enabled
if (resolvedOptions.enforceFlatMap && isJsonObject(decoded)) {
return unflattenMap(decoded, resolvedOptions.flatMapSeparator);
}
return decoded;
}