Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
No EOL
1.5 KiB
Text
53 lines
No EOL
1.5 KiB
Text
export function searchParamsToUrlQuery(searchParams) {
|
|
const query = {};
|
|
for (const [key, value] of searchParams.entries()){
|
|
const existing = query[key];
|
|
if (typeof existing === 'undefined') {
|
|
query[key] = value;
|
|
} else if (Array.isArray(existing)) {
|
|
existing.push(value);
|
|
} else {
|
|
query[key] = [
|
|
existing,
|
|
value
|
|
];
|
|
}
|
|
}
|
|
return query;
|
|
}
|
|
function stringifyUrlQueryParam(param) {
|
|
if (typeof param === 'string') {
|
|
return param;
|
|
}
|
|
if (typeof param === 'number' && !isNaN(param) || typeof param === 'boolean') {
|
|
return String(param);
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
export function urlQueryToSearchParams(query) {
|
|
const searchParams = new URLSearchParams();
|
|
for (const [key, value] of Object.entries(query)){
|
|
if (Array.isArray(value)) {
|
|
for (const item of value){
|
|
searchParams.append(key, stringifyUrlQueryParam(item));
|
|
}
|
|
} else {
|
|
searchParams.set(key, stringifyUrlQueryParam(value));
|
|
}
|
|
}
|
|
return searchParams;
|
|
}
|
|
export function assign(target, ...searchParamsList) {
|
|
for (const searchParams of searchParamsList){
|
|
for (const key of searchParams.keys()){
|
|
target.delete(key);
|
|
}
|
|
for (const [key, value] of searchParams.entries()){
|
|
target.append(key, value);
|
|
}
|
|
}
|
|
return target;
|
|
}
|
|
|
|
//# sourceMappingURL=querystring.js.map |