| 1 |
/** Takes each possible code section and filters out undefined */ |
| 2 |
export const findTheCode = (item) => |
| 3 |
[item?.template?.code, item?.template?.code2].filter(Boolean).join('') |
| 4 |
|
| 5 |
/** Removes any hash or qs values from URL - Airtable adds timestamps */ |
| 6 |
export const stripUrlParams = (url) => url?.[0]?.url?.split(/[?#]/)?.[0] |
| 7 |
|
| 8 |
/** Lowers the quality of images */ |
| 9 |
export const lowerImageQuality = (html) => { |
| 10 |
return html.replace(/\w+:\/\/\S*(w=(\d*))&\w+\S*"/g, (url, w, width) => |
| 11 |
// Could lower the width here if needed |
| 12 |
url.replace(w, 'w=' + Math.floor(Number(width)) + '&q=10'), |
| 13 |
) |
| 14 |
} |
| 15 |
|
| 16 |
/** Capitalize first letter of a string */ |
| 17 |
export const capitalize = (str) => |
| 18 |
str.charAt(0).toUpperCase() + str.slice(1).toLowerCase() |
| 19 |
|