getAllQueryString
Extract all query parameters from a URL and convert them to an object.
API
getAllQueryString
Return
| Argument | Description | Type |
|---|---|---|
Object | Query parameters object | Record<string, string> |
Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
url | URL to parse (optional, defaults to current page URL) | string | Optional |
Example
Basic Usage
import { getAllQueryString } from 'ranuts';
// Assuming current URL is: https://example.com?name=John&age=30
const params = getAllQueryString();
console.log(params); // { name: 'John', age: '30' }Parse Specified URL
import { getAllQueryString } from 'ranuts';
const url = 'https://example.com?page=1&limit=10&sort=name';
const params = getAllQueryString(url);
console.log(params); // { page: '1', limit: '10', sort: 'name' }Get Specific Parameter
import { getAllQueryString } from 'ranuts';
const params = getAllQueryString();
const page = params.page || '1';
const limit = params.limit || '10';
console.log(`Page: ${page}, Limit: ${limit}`);Handle Encoded Parameters
import { getAllQueryString } from 'ranuts';
// URL: https://example.com?search=hello%20world
const params = getAllQueryString();
console.log(params.search); // 'hello world' (automatically decoded)Notes
A bare flag keeps its place.
?embedand?embed=both yield{ embed: '' }. Before 0.3 any parameter without a value was dropped, which made?readonlyand?embed— the usual way to write a boolean flag — indistinguishable from the parameter being absent. Read such a flag withqueryFlag.A fragment never leaks into the last value.
?lang=en#sectionyields{ lang: 'en' }.Only the first
=splits, so a value may contain one:?next=/a?b=1yields{ next: '/a?b=1' }.URL decoding: keys and values are percent-decoded, and
+becomes a space — matchingURLSearchParams. A malformed escape such as%zzis kept verbatim rather than dropping the parameter, so one bad value cannot hide the others.Server-side environment: returns
{}when there is nowindowand nourlwas passed. Pass a URL to use it in a build-time script.Default URL: without
url, defaults towindow.location.href.Duplicate parameters: only the last value is kept.