mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 22:16:58 +00:00
31 lines
967 B
TypeScript
31 lines
967 B
TypeScript
import { MedusaProductOption } from './medusa/types';
|
|
|
|
export const createUrl = (pathname: string, params: URLSearchParams) => {
|
|
const paramsString = params.toString();
|
|
const queryString = `${paramsString.length ? '?' : ''}${paramsString}`;
|
|
|
|
return `${pathname}${queryString}`;
|
|
};
|
|
|
|
export const mapOptionIds = (productOptions: MedusaProductOption[]) => {
|
|
// Maps the option titles to their respective ids
|
|
const map: Record<string, string> = {};
|
|
productOptions.forEach((option) => {
|
|
map[option.id] = option.title;
|
|
});
|
|
return map;
|
|
};
|
|
|
|
export const isObject = (input: any) => input instanceof Object;
|
|
export const isArray = (input: any) => Array.isArray(input);
|
|
|
|
export const isEmpty = (input: any) => {
|
|
return (
|
|
input === null ||
|
|
input === undefined ||
|
|
(isObject(input) && Object.keys(input).length === 0) ||
|
|
(isArray(input) && (input as any[]).length === 0) ||
|
|
(typeof input === 'string' && input.trim().length === 0)
|
|
);
|
|
};
|