```ts
export function tidyShelfMark(raw: string): string {
  if (typeof raw !== 'string') {
    throw new Error('Input must be a string');
  }

  const parts = raw.trim().split('-');

  if (parts.length !== 3) {
    throw new Error('Mark must have exactly three parts');
  }

  const [wing, bayWithFraction, peg] = parts;

  // Validate wing
  if (!/^[A-Za-z]{2}$/.test(wing)) {
    throw new Error('Wing must be exactly two letters');
  }

  // Validate and tidy bay
  const bayMatch = bayWithFraction.match(/^(\d+)(?:\.(\d*))?$/);
  if (!bayMatch) {
    throw new Error('Bay must be one to six digits, optionally followed by a dot and one to four more digits');
  }

  let [_, bay, fraction] = bayMatch;

  const bayNumber = parseInt(bay, 10);
  if (bayNumber < 1 || bayNumber > 999) {
    throw new Error('Bay must be between 1 and 999');
  }

  if (fraction) {
    fraction = fraction.replace(/0+$/, ''); // Remove trailing zeros
    if (fraction.length > 2) {
      throw new Error('Fraction must be one or two digits');
    }
  }

  const tidyBay = bayNumber.toString() + (fraction ? '.' + fraction : '');

  // Validate and tidy peg
  if (!/^[A-Za-z][1-9]$/.test(peg)) {
    throw new Error("Peg must be one letter followed by one non-zero digit");
  }

  return wing.toUpperCase() + '-' + tidyBay + '-' + peg[0].toLowerCase() + peg[1];
}
```