Add product group analysis view
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 41s

This commit is contained in:
Cauê Faleiros
2026-07-07 10:34:17 -03:00
parent 022ed007ff
commit 566b032fb3
4 changed files with 610 additions and 15 deletions

View File

@@ -3,6 +3,23 @@ const sizeSet = new Set(sizeOrder);
export const normalizeProductText = (value: string) => value.replace(/\s+/g, ' ').trim();
export const encodeProductGroupKey = (value: string) => {
const normalizedValue = normalizeProductText(value);
const bytes = new TextEncoder().encode(normalizedValue);
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
};
export const decodeProductGroupKey = (value: string) => {
const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
const paddedBase64 = base64.padEnd(Math.ceil(base64.length / 4) * 4, '=');
const binary = atob(paddedBase64);
const bytes = Uint8Array.from(binary, character => character.charCodeAt(0));
return normalizeProductText(new TextDecoder().decode(bytes));
};
export const sortProductSizes = (sizes: string[]) => [...sizes].sort((a, b) => {
const indexA = sizeOrder.indexOf(a);
const indexB = sizeOrder.indexOf(b);