@jsmastery/utils
v1.0.2
Published
A lightweight utility package with functions commonly used across JavaScript Mastery projects.
Readme
jsm-utils
A lightweight TypeScript utility library for use across JavaScript Mastery projects.
✨ Features
- ✅ 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.
📦 Installation
npm install @jsmastery/utils🚀 Example Usage
formUrlQuery
const newUrl = formUrlQuery({
params: searchParams.toString(),
key: "your_query_key",
value: searchQuery,
});
router.push(newUrl);removeKeysFromUrlQuery
const newUrl = removeKeysFromUrlQuery({
params: searchParams.toString(),
keysToRemove: ["your_query_key"],
});
router.push(newUrl, { scroll: false });📘 API Reference
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
📄 License
MIT © JavaScript Mastery
