

native-querystring - Node’s querystring module implemented using the built-in UR...
source link: https://github.com/niksy/native-querystring
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

native-querystring
Node’s querystring module implemented using the built-in
URLSeachParams
API
.
:warning:
Differences with original querystring
module
-
Space and its percent-encoded value (
%20
) is replaced with plus-sign+
-
Fourth argument for
parse
andstringify
is not supported
If you want to use Node’s url
module based on the URL API, consider using native-url
module.
Install
npm install native-querystring --save
Usage
import * as qs from 'querystring'; qs.parse('becky=1&jackson=brody&jackson=winnie'); // { becky: '1', jackson: ['brody', 'winnie'] } qs.stringify({ becky: 1, gracie: ['rex', 'milo'], shadow: '' }); // becky=1&gracie=rex&gracie=milo&shadow=
If you want to alias querystring
module to this module, refer to Webpack
and Rollup
documentation on aliasing
modules (or, native-url alias explanation
).
API
parse(input, separator, equals)
Returns: Object
Parses a URL query string into a collection of key and value pairs.
Property Type Default Descriptioninput
string
The URL query string to parse.
separator
string
&
The substring used to delimit key and value pairs in the query string.
equals
string
=
The substring used to delimit keys and values in the query string.
stringify(input, separator, equals)
Returns: string
Produces a URL query string from a given obj by iterating through the object's "own properties".
Property Type Default Descriptioninput
Object
The object to serialize into a URL query string.
separator
string
&
The substring used to delimit key and value pairs in the query string.
equals
string
=
The substring used to delimit keys and values in the query string.
escape(input)
Returns: string
Performs URL percent-encoding on the given input in a manner that is optimized for the specific requirements of URL query strings.
input
Type: string
unescape(input)
Returns: string
Performs decoding of URL percent-encoded characters on the given input.
input
Type: string
Browser support
Tested in IE9+ and all modern browsers.
It relies on the DOM
URLSearchParams
API
to work. For older browsers
that don’t support the URLSearchParams
API, a polyfill
is
available.
Test
Test suite is taken from Node core
and
querystring-es3
module
to cover all native querystring test
cases.
For automated tests, run npm run test:automated
(append :watch
for watcher
support).
License
MIT © Ivan Nikolić
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK