This package has been deprecated

Author message:

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

@saekitominaga/urlsearchparams-custom-separator
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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)

Readme

Keywords

Package Sidebar

Install

npm i @saekitominaga/urlsearchparams-custom-separator

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

39.5 kB

Total Files

7

Last publish

Collaborators

  • saekitominaga