2.0.1 • Published 4 months ago

@saekitominaga/urlsearchparams-custom-separator v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

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

Properties

Methods

2.0.1

4 months ago

2.0.0

9 months ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago