-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eac3e8d
commit 5ee1166
Showing
7 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
import { ParameterBag } from '../index.js' | ||
|
||
export interface QueryParameterBag<T> extends ParameterBag<T> { | ||
/** | ||
* Returns the querystring created from all items in this query parameter bag, | ||
* without the leading question mark `?`. | ||
* | ||
* **Notice:** the returned querystring is encoded. Node.js automatically | ||
* encodes the querystring to ensure a valid URL. Some characters would | ||
* break the URL string otherwise. This way ensures the valid string. | ||
*/ | ||
toQuerystring (): string | ||
|
||
/** | ||
* Returns the decoded querystring by running the result of `toQuerystring` | ||
* through `decodeURIComponent`. This method is useful to debug during | ||
* development. It’s recommended to use `toQuerystring` in production. | ||
*/ | ||
toQuerystringDecoded (): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
import { ParameterBag } from './parameter-bag.js' | ||
import { QueryParameterBag as QueryParameterBagContract } from '@supercharge/contracts' | ||
|
||
export class QueryParameterBag<T> extends ParameterBag<T> implements QueryParameterBagContract<T> { | ||
/** | ||
* Returns the query string created from all items in this query parameter bag, | ||
* without the leading question mark `?`. | ||
* | ||
* **Notice:** the returned querystring is encoded. Node.js automatically | ||
* encodes the querystring to ensure a valid URL. Some characters would | ||
* break the URL string otherwise. This way ensures the valid string. | ||
*/ | ||
toQuerystring (): string { | ||
return new URLSearchParams( | ||
this.all() as Record<string, string> | ||
).toString() | ||
} | ||
|
||
/** | ||
* Returns the decoded querystring by running the result of `toQuerystring` | ||
* through `decodeURIComponent`. This method is useful to debug during | ||
* development. It’s recommended to use `toQuerystring` in production. | ||
*/ | ||
toQuerystringDecoded (): string { | ||
return decodeURIComponent( | ||
this.toQuerystring() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters