
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
next-query-utils
Advanced tools
[!NOTE]
This lib no longer updates in npm. latest:
Instead, use JSR where it's published as v2.x or later
This library provides utility functions to deal with Parsed Query Objects (especially of Next.js)
このライブラリには、Parsed Query Object (特に Next.js のもの)を取り扱うためのユーティリティ関数群が含まれます。
// with npm
npm i next-query-utils
// with yarn
yarn add next-query-utils
?id=aaa
or ?id=aaa&id=other
-> "aaa"
// before
const _id = router.query["id"]
const id = Array.isArray(id) ? id[0] : id
// after
const id = getSingleQueryParam(router.query, "id")
?start_on=2022-03-02&item_type=stationary&item_type=book
-> ?start_on=2022-03-02&item_type=stationary
// before
const removeQuery = (
query: ParsedUrlQuery,
key: string,
pred: string
) => {
const value = query[key]
// if empty, leave query as it is.
if (!value) return query;
if (Array.isArray(value)) {
if(value.length === 0) return query;
// if non-empty array of string
return { ...acc, [key]: value.filter(s => s !== pred) };
}
// if single string (not empty)
return { ...acc, [key]: (s !== value) ? value : [] };
}
// after
router.push(
removeQueryParam({
item_type: "book"
})(router.query)
)
/[postId]?other=value&other2=value
-> /[postId]
In pages with Next.js's dynamic routes, router.query
include them (in this example, .postId
). so they MUST be kept from resetting.
In this case, use resetQuery()
with ignore
option.
Next.js の動的ルートがあるページでは、それが router.query
に含まれる。(この例では .postId
) なので、それらは 削除してはいけない。
このようなケースでは resetQuery()
と ignore
オプションを使いましょう。
// before
router.push({ postId: router.query["postId"] })
// after
router.push(resetQuery({ ignore: "postId" })(router.query))
/items/[postId]
/items/[postId]?param1=aa
Likewise, you need to ignore dynamic routes in order to check if the query is empty.
In this case, use isQueryEmpty()
with ignore
option.
前の例と同じように、クエリが空であるか確かめるためには、 動的ルート を無視する必要があります。
このようなケースでは、isQueryEmpty()
と ignore
オプションを使いましょう。
isQueryEmpty(router.query, { ignore: "postId" })
This library is licensed under the terms of MIT License
FAQs
Provides functions to manipulate parsed url query object
We found that next-query-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.