```ts
/**
 * Converts a prefix length to its corresponding network mask in dotted-quad notation.
 * @param prefix - The number of leading ones in the binary representation of the mask (0-32).
 * @returns A string representing the network mask in dotted-quad notation.
 */
export function maskFromPrefix(prefix: number): string {
  if (!Number.isInteger(prefix) || prefix < 0 || prefix > 32) {
    throw new Error("Invalid prefix");
  }

  const octets = Array(4).fill(0);
  for (let i = 0; i < prefix; i++) {
    octets[Math.floor(i / 8)] |= 1 << (7 - i % 8);
  }
  return octets.join(".");
}

/**
 * Converts a network mask in dotted-quad notation to its corresponding prefix length.
 * @param mask - A string representing the network mask in dotted-quad notation.
 * @returns The number of leading ones in the binary representation of the mask (0-32).
 */
export function prefixFromMask(mask: string): number {
  if (typeof mask !== "string") {
    throw new Error("Invalid input");
  }

  const octets = mask.split(".");
  if (octets.length !== 4) {
    throw new Error("Invalid mask format");
  }

  for (const octet of octets) {
    if (!/^\d+$/.test(octet)) {
      throw new Error("Non-numeric field in mask");
    }
    const num = parseInt(octet, 10);
    if (num < 0 || num > 255 || (octet.length > 1 && octet.startsWith("0"))) {
      throw new Error("Invalid octet value in mask");
    }
  }

  let prefix = 0;
  for (let i = 0; i < 4; i++) {
    const octet = parseInt(octets[i], 10);
    if ((octet & 0xFF) !== 0) {
      for (let j = 7; j >= 0; j--) {
        if (octet & (1 << j)) {
          prefix++;
        } else {
          break;
        }
      }
    } else if (i === 0) {
      throw new Error("Leading zero octets in mask");
    } else {
      for (let j = 7; j >= 0; j--) {
        if ((octets[i - 1] & (1 << j)) !== 0) {
          throw new Error("Broken run of ones in mask");
        }
      }
    }
  }

  return prefix;
}
```