Created
April 10, 2024 07:28
-
-
Save ivanhoe011/41492b0fdf15f74be0bdf30fc8bf0bd0 to your computer and use it in GitHub Desktop.
Get all filters from the url's query (following jsonapi.org filters format)
This file contains hidden or 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
| /** | |
| * Get all filters w/ regexp, because UrlSearchParams sux | |
| * | |
| * @param string url | |
| * @return Object | |
| */ | |
| function extractFilters(url) { | |
| return url.matchAll( | |
| /[&?]filter\[([^\]]+)\]=([^&]+)/g | |
| ) | |
| .reduce((acc, match) => ({ | |
| ...acc, | |
| [match[1]]: match[2] | |
| }), | |
| {} | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment