export enum Alignment {
  LEFT = 'left',
  RIGHT = 'right'
}

// Utility for fixed-length field formatting
export const pad = (val: string | number, len: number, align: Alignment = Alignment.LEFT, fill = ' ') => {
  if (val === undefined || val === null) throw new Error('pad: valeur indéfinie ou nulle')

  const strVal = String(val)
  const res = align === Alignment.RIGHT ? strVal.padStart(len, fill) : strVal.padEnd(len, fill)
  if (res.length !== len) {
    throw new Error(`Padding error: ${res} is not of length ${len}`)
  }
  return res
}
