Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@saekitominaga/urlsearchparams-custom-separator

SaekiTominaga5MITdeprecated2.0.1TypeScript support: included

This package has been moved to @w0s/urlsearchparams-custom-separator

Support characters other than "&" as URL query separator

url, urlsearchparams

readme

Support characters other than "&" as URL query separator

npm version test status

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 '@saekitominaga/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[])

Parameters

url
URL object, or full string of URL or substring of URL
separators
List of URL query separator

Properties

searchParams: URLSearchParams
Returns a URLSearchParams object.

Methods

toString(): string
Returns a URL query with the separator unified to "&". (e.g. ?foo=1&bar=2;baz=3foo=1&bar=2&baz=3)