18 lines
432 B
TypeScript
18 lines
432 B
TypeScript
export function extractOrderCodeShort(code?: string | null) {
|
|
const normalized = String(code ?? '').trim();
|
|
if (!normalized) {
|
|
return '0000';
|
|
}
|
|
|
|
const digits = normalized.replace(/\D/g, '');
|
|
if (digits.length >= 4) {
|
|
return digits.slice(-4);
|
|
}
|
|
|
|
return normalized.slice(-4).toUpperCase().padStart(4, '0');
|
|
}
|
|
|
|
export function formatOrderCode(code?: string | null) {
|
|
return `#${extractOrderCodeShort(code)}`;
|
|
}
|