/** * Read one header value as a bigint. * * A blank value is absent, and other text is converted when it parses and kept * as text otherwise. * * @evidence contracts/common.md#principled-implementation A blank header, or a blank element, is absent because `BigInt("")` would read as zero; other text is converted when it parses and left as text when it does not. * @evidence contracts/common.md#clear-and-simple-design One conditional and two private helpers. * @evidence contracts/common.md#prohibited-implementation-shortcuts The blank rule follows the cited issue. * @evidence contracts/common.md#meaningful-documentation A comment states the cases. */ export const _httpHeaderReadBigint = (value: string | undefined) => // A blank header, or a blank element of a header list, is absent: `BigInt("")` // is 0n, which let validators accept an empty header as a real zero (#2448). value !== undefined && isBlank(value) === false ? toBigint(value) : undefined; const isBlank = (value: string): boolean => typeof value === "string" && value.trim().length === 0; const toBigint = (str: string): bigint | string => { try { return BigInt(str); } catch { return str; } };