@accounter/shaam6111-generator
Version:
Fully typed application that generates, parses, and validates SHAAM 6111 tax reports.
20 lines (19 loc) • 640 B
text/typescript
/**
* Pads or trims a string to match a specified length.
* @param value - The input string to process
* @param length - The target length
* @param padChar - Character used for padding (default: '0')
* @param alignRight - If true, right-aligns by padding left; otherwise left-aligns (default: true)
* @returns The padded or trimmed string of exact length
*/
export const padOrTrim = (
value: string,
length: number,
padChar = '0',
alignRight = true,
): string => {
if (value.length > length) {
return value.slice(0, length);
}
return alignRight ? value.padStart(length, padChar) : value.padEnd(length, padChar);
};