Functional Weave
Code in Rust

health.nhs-number-format@1.0.0

impl/typescript.ts

700 bytes · the TypeScript implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { validateNhsNumber } from "./validation_nhs_number.ts";  ← from validation.nhs-number ^2.0.0 · built alongside by fune

/**
 * The NHS number in the 3-3-4 display format NHS systems use, after
 * a full check with validation.nhs-number. An invalid number is an error, not
 * a formatted string: a well-spaced wrong number looks more trustworthy than
 * a badly spaced right one. The error names the reason but never echoes the
 * number, which is a patient identifier and has no place in a log.
 */
export function formatNhsNumber(value: string): string {
  const result = validateNhsNumber(value);
  if (!result.valid || result.formatted === null) {
    throw new RangeError(`not a valid NHS number (${result.reason})`);
  }
  return result.formatted;
}