Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
29 lines
1.0 KiB
Plaintext
29 lines
1.0 KiB
Plaintext
/**
|
|
* Sanitize empty strings from the query, e.g. `?preset=`
|
|
* This is how we determine whether to clear user preferences for certain params
|
|
* Once cleared, they are no longer needed in the URL
|
|
*/export const sanitizeQuery = toSanitize => {
|
|
const sanitized = {
|
|
...toSanitize
|
|
};
|
|
Object.entries(sanitized).forEach(([key, value]) => {
|
|
if (key === 'columns' && (value === '[]' || Array.isArray(sanitized[key]) && sanitized[key].length === 0)) {
|
|
delete sanitized[key];
|
|
}
|
|
if (key === 'where' && typeof value === 'object' && value !== null && !Object.keys(value).length) {
|
|
delete sanitized[key];
|
|
}
|
|
if ((key === 'limit' || key === 'page') && typeof value === 'string') {
|
|
const parsed = parseInt(value, 10);
|
|
sanitized[key] = Number.isNaN(parsed) ? undefined : parsed;
|
|
}
|
|
if (key === 'page' && value === 0) {
|
|
delete sanitized[key];
|
|
}
|
|
if (value === '') {
|
|
delete sanitized[key];
|
|
}
|
|
});
|
|
return sanitized;
|
|
};
|
|
//# sourceMappingURL=sanitizeQuery.js.map |