decode function
- dynamic input, [
- DecodeOptions? options
Top-level convenience functions that mirror the JavaScript qs
API.
These helpers forward directly to QS.encode and QS.decode so you can
call encode(...)
/ decode(...)
without referencing the QS class.
They add no extra behavior—just a terser surface that keeps parity with
the original Node.js library.
Decode a query string into a map (convenience for QS.decode).
input
can be a raw query string (e.g."a=b&c[0]=d"
), a full URL (its query part will be used), or any type supported by QS.decode.options
controls parsing behavior; if omitted, sensible defaults that match the JavaScriptqs
library are used.
Returns an insertion-ordered Map<String, dynamic>
(matching Dart's
default Map
semantics) so round-trips preserve key order where possible.
Notes
- A
null
or emptyinput
decodes to an empty map. - For duplicate keys and list parsing semantics, see DecodeOptions.
Examples
final m1 = decode('a=b'); // => {'a': 'b'}
final m2 = decode('a[0]=x&a[1]=y'); // => {'a': ['x', 'y']}
final m3 = decode(Uri.parse('https://x?x=1')); // => {'x': '1'}
Implementation
/// Decode a query string into a map (convenience for [QS.decode]).
///
/// - **`input`** can be a raw query string (e.g. `"a=b&c[0]=d"`), a full URL
/// (its query part will be used), or any type supported by [QS.decode].
/// - **`options`** controls parsing behavior; if omitted, sensible defaults
/// that match the JavaScript `qs` library are used.
///
/// Returns an insertion-ordered `Map<String, dynamic>` (matching Dart's
/// default `Map` semantics) so round-trips preserve key order where possible.
///
/// **Notes**
/// - A `null` or empty `input` decodes to an empty map.
/// - For duplicate keys and list parsing semantics, see [DecodeOptions].
///
/// **Examples**
/// ```dart
/// final m1 = decode('a=b'); // => {'a': 'b'}
/// final m2 = decode('a[0]=x&a[1]=y'); // => {'a': ['x', 'y']}
/// final m3 = decode(Uri.parse('https://x?x=1')); // => {'x': '1'}
/// ```
Map<String, dynamic> decode(dynamic input, [DecodeOptions? options]) =>
QS.decode(input, options);