Skip to content

Commit

Permalink
💡 add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Apr 2, 2024
1 parent c6328fa commit 709b874
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/src/models/decode_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ typedef Decoder = dynamic Function(String? value, {Encoding? charset});
final class DecodeOptions with EquatableMixin {
const DecodeOptions({
bool? allowDots,
Decoder? decoder,
bool? decodeDotInKeys,
this.allowEmptyLists = false,
this.listLimit = 20,
this.charset = utf8,
this.charsetSentinel = false,
this.comma = false,
bool? decodeDotInKeys,
this.delimiter = '&',
this.depth = 5,
this.duplicates = Duplicates.combine,
Expand All @@ -24,7 +25,6 @@ final class DecodeOptions with EquatableMixin {
this.parameterLimit = 1000,
this.parseLists = true,
this.strictNullHandling = false,
Decoder? decoder,
}) : allowDots = allowDots ?? decodeDotInKeys == true || false,
decodeDotInKeys = decodeDotInKeys ?? true,
_decoder = decoder,
Expand All @@ -50,6 +50,7 @@ final class DecodeOptions with EquatableMixin {
final bool strictNullHandling;
final Decoder? _decoder;

/// The decoder function to use.
dynamic decoder(String? value, {Encoding? charset}) => _decoder is Function
? _decoder?.call(value, charset: charset)
: Utils.decode(value, charset: charset);
Expand Down
21 changes: 15 additions & 6 deletions lib/src/models/encode_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ typedef Sorter = int Function(dynamic a, dynamic b);
/// An options that configure the output of [QS.encode].
final class EncodeOptions with EquatableMixin {
const EncodeOptions({
Encoder? encoder,
DateSerializer? serializeDate,
ListFormat? listFormat,
@Deprecated('Use listFormat instead') bool? indices,
bool? allowDots,
this.addQueryPrefix = false,
this.allowEmptyLists = false,
this.charset = utf8,
Expand All @@ -30,11 +35,6 @@ final class EncodeOptions with EquatableMixin {
this.strictNullHandling = false,
this.commaRoundTrip,
this.sort,
bool? allowDots,
ListFormat? listFormat,
@Deprecated('Use listFormat instead') bool? indices,
DateSerializer? serializeDate,
Encoder? encoder,
}) : allowDots = allowDots ?? encodeDotInKeys || false,
listFormat = listFormat ??
(indices == false ? ListFormat.repeat : null) ??
Expand All @@ -46,7 +46,7 @@ final class EncodeOptions with EquatableMixin {
'Invalid charset',
),
assert(
filter == null || filter is Function || filter is List,
filter == null || filter is Function || filter is Iterable,
'Invalid filter',
);

Expand All @@ -69,8 +69,12 @@ final class EncodeOptions with EquatableMixin {
final DateSerializer? _serializeDate;
final Encoder? _encoder;

/// Convenience getter for accessing the [format]'s [Format.formatter]
Formatter get formatter => format.formatter;

/// Encodes a [value] to a [String].
///
/// Uses the provided [encoder] if available, otherwise uses [Utils.encode].
String encoder(dynamic value, {Encoding? charset, Format? format}) =>
_encoder?.call(
value,
Expand All @@ -83,9 +87,14 @@ final class EncodeOptions with EquatableMixin {
format: format ?? this.format,
);

/// Serializes a [DateTime] instance to a [String].
///
/// Uses the provided [serializeDate] function if available, otherwise uses
/// [DateTime.toIso8601String].
String serializeDate(DateTime date) =>
_serializeDate?.call(date) ?? date.toIso8601String();

/// Returns a new [EncodeOptions] instance with updated values.
EncodeOptions copyWith({
bool? addQueryPrefix,
bool? allowDots,
Expand Down

0 comments on commit 709b874

Please sign in to comment.