Skip to content

Commit

Permalink
✨ add Uri extension (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored May 18, 2024
1 parent 5fe6566 commit ba89462
Show file tree
Hide file tree
Showing 3 changed files with 1,547 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/qs_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export 'src/methods.dart' show decode, encode;
export 'src/models/decode_options.dart';
export 'src/models/encode_options.dart';
export 'src/models/undefined.dart';
export 'src/uri.dart';
export 'src/qs.dart';
19 changes: 19 additions & 0 deletions lib/src/uri.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:qs_dart/qs_dart.dart';

extension UriExtension on Uri {
/// The URI query split into a map.
/// Providing custom [options] will override the default behavior.
Map<String, dynamic> queryParametersQs([
DecodeOptions options = const DecodeOptions(),
]) =>
query.isNotEmpty ? QS.decode(query, options) : const <String, dynamic>{};

/// The normalized string representation of the URI.
/// Providing custom [options] will override the default behavior.
String toStringQs([EncodeOptions options = const EncodeOptions()]) => replace(
query: queryParameters.isNotEmpty
? QS.encode(queryParameters, options)
: null,
queryParameters: null,
).toString();
}
Loading

0 comments on commit ba89462

Please sign in to comment.