@w0s/urlsearchparams-custom-separator
v3.0.0
Published
Support characters other than "&" as URL query separator
Downloads
17
Readme
Support characters other than "&" as URL query separator
The URL query separator uses "&", but needs to be escaped in HTML and XML. HTML 4.01 - Appendix B.2.2 had recommended support the use of ";" in place of "&".
This feature supports arbitrary separators other than "&" and allows them to be used in URLSearchParams
objects, etc.
Examples
import URLSearchParamsCustomSeparator from '@w0s/urlsearchparams-custom-separator';
const urlSearchParams1 = new URLSearchParamsCustomSeparator(new URL('https://example.com/path/to?foo=1&bar=2;baz=3;qux=4:quux=5'), [';', ':']);
urlSearchParams1.searchParams.get('baz'); // 3
urlSearchParams1.toString(); // foo=1&bar=2&baz=3&qux=4&quux=5
const urlSearchParams2 = new URLSearchParamsCustomSeparator('https://example.com/path/to?foo=1&bar=2;baz=3;qux=4:quux=5', [';', ':']);
urlSearchParams2.searchParams.get('baz'); // 3
urlSearchParams2.toString(); // foo=1&bar=2&baz=3&qux=4&quux=5
const urlSearchParams3 = new URLSearchParamsCustomSeparator('/path/to?foo=1&bar=2;baz=3;qux=4:quux=5', [';', ':']);
urlSearchParams3.searchParams.get('baz'); // 3
urlSearchParams3.toString(); // foo=1&bar=2&baz=3&qux=4&quux=5
Constructor
new URLSearchParamsCustomSeparator(url: URL | string, separators: string[])