devkits-query-string
v1.0.0
Published
Parse and stringify URL query strings — zero dependencies
Maintainers
Readme
devkits-query-string
Parse and stringify URL query strings. Zero dependencies, lightweight alternative to Node.js querystring.
Install
npm install -g devkits-query-stringUsage
CLI
# Parse query string to JSON
query-string parse "foo=bar&baz=qux"
# Output: {"foo":"bar","baz":"qux"}
# Stringify object to query string
query-string stringify '{"name":"test","count":5}'
# Output: name=test&count=5
# Extract query from full URL
query-string url "https://example.com/page?foo=bar#hash"
# Output: {"foo":"bar"}
# Handle arrays
query-string parse "tags[]=js&tags[]=node"
# Output: {"tags":["js","node"]}
# URL encoding
query-string parse "name=hello%20world"
# Output: {"name":"hello world"}Programmatic API
const { parse, stringify, parseUrl } = require('devkits-query-string');
// Parse query string
const obj = parse('foo=bar&baz=qux');
// { foo: 'bar', baz: 'qux' }
// Handle URL-encoded values
parse('name=hello%20world');
// { name: 'hello world' }
// Plus sign as space
parse('q=hello+world');
// { q: 'hello world' }
// Stringify object
const str = stringify({ name: 'test', count: 5 });
// 'name=test&count=5'
// Arrays become []
stringify({ tags: ['js', 'node'] });
// 'tags[]=js&tags[]=node'
// Parse full URL
parseUrl('https://example.com/page?foo=bar#hash');
// { foo: 'bar' }API
parse(str)
Parse query string into object.
| Param | Type | Description | |-------|------|-------------| | str | string | Query string (with or without ?) | | Returns | Object | Parsed key-value pairs |
stringify(obj)
Stringify object into query string.
| Param | Type | Description | |-------|------|-------------| | obj | Object | Key-value pairs | | Returns | string | Query string (without ?) |
parseUrl(url)
Parse full URL and extract query string.
| Param | Type | Description | |-------|------|-------------| | url | string | Full URL | | Returns | Object | Parsed query parameters |
Features
- Zero dependencies — Pure JavaScript, no external packages
- URL decoding — Handles %XX encoding and + as space
- Array support — Parse
foo[]=a&foo[]=binto arrays - Duplicate keys — Last value wins (standard behavior)
- CLI + library — Works as command tool or npm module
- Lightweight — ~2KB minified
Use Cases
- URL manipulation — Parse and modify query parameters
- Form data — Handle URL-encoded form submissions
- Deep linking — Extract state from URLs
- API clients — Build query strings programmatically
- Analytics — Parse tracking parameters from URLs
Examples
// Build pagination params
stringify({ page: 2, limit: 20, sort: 'created' });
// 'page=2&limit=20&sort=created'
// Parse search filters
parse('q=nodejs&category=tools&price_min=10');
// { q: 'nodejs', category: 'tools', price_min: '10' }
// Handle tracking params
parseUrl('https://site.com?utm_source=twitter&utm_medium=social');
// { utm_source: 'twitter', utm_medium: 'social' }Related Tools
🔍 Build something amazing? Check out API Monitor — simple, affordable API monitoring for indie hackers. Get alerted before your customers notice. Just $9/mo.
See Also
- DevKits — All developer tools in one place
- devkits-url-tools — URL parsing utilities
- devkits-json-formatter — Format JSON output
Support
If you find this tool useful, please consider supporting:
Open Collective
Become a sponsor: Open Collective - DevKits
Crypto Donations
- ETH:
0xDea4a6A20fCB44467e45Ef378972F54B22dC59db - USDC:
0xDea4a6A20fCB44467e45Ef378972F54B22dC59db
License
MIT — DevKits Team
