A lightweight utility package with functions commonly used across JavaScript Mastery projects.
npm install @jsmastery/utils> A lightweight TypeScript utility library for use across JavaScript Mastery projects.
- ✅ Add or update query parameters in URLs
- ✅ Remove keys from existing query strings
- ✅ Fully typed and developer-friendly
- ✅ Works great with frameworks like React, Next.js, etc.
``bash`
npm install @jsmastery/utils
formUrlQuery
`javascript
const newUrl = formUrlQuery({
params: searchParams.toString(),
key: "your_query_key",
value: searchQuery,
});
router.push(newUrl);
`
removeKeysFromUrlQuery
`javascript
const newUrl = removeKeysFromUrlQuery({
params: searchParams.toString(),
keysToRemove: ["your_query_key"],
});
router.push(newUrl, { scroll: false });
`
formUrlQuery({ params, key, value })
Adds or updates a query string key with a given value.
- params – The current URL query string (e.g. from window.location.search)
- key – The key to add or update
- value – The new value to set
removeKeysFromUrlQuery({ params, keysToRemove })`
Removes specific keys from the given query string.
- params – The current URL query string
- keysToRemove – An array of keys to be removed
MIT © JavaScript Mastery