Add product group analysis view
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 41s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 41s
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user