{"version":3,"file":"_httpHeaderReadNumber.mjs","names":[],"sources":["../../src/internal/_httpHeaderReadNumber.ts"],"sourcesContent":["/**\n * Read one header value as a number.\n *\n * A blank value is absent, and other text is converted when it is a number and\n * kept as text otherwise.\n *\n * @evidence contracts/common.md#principled-implementation A blank header, or a blank element, is absent because `Number(\"\")` would read as zero; other text is converted when it is a number and kept as text otherwise.\n * @evidence contracts/common.md#clear-and-simple-design One conditional and two private helpers.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The blank rule follows the cited issue.\n * @evidence contracts/common.md#meaningful-documentation A comment states the cases.\n */\nexport const _httpHeaderReadNumber = (value: string | undefined) =>\n  // A blank header, or a blank element of a header list, is absent: `Number(\"\")`\n  // is 0, which let validators accept an empty header as a real zero (#2448).\n  value !== undefined && isBlank(value) === false ? toNumber(value) : undefined;\n\nconst isBlank = (value: string): boolean =>\n  typeof value === \"string\" && value.trim().length === 0;\n\nconst toNumber = (str: string): number | string => {\n  const value: number = Number(str);\n  return isNaN(value) ? str : value;\n};\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,yBAAyB,UAGpC,UAAU,KAAA,KAAa,QAAQ,KAAK,MAAM,QAAQ,SAAS,KAAK,IAAI,KAAA;AAEtE,MAAM,WAAW,UACf,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,WAAW;AAEvD,MAAM,YAAY,QAAiC;CACjD,MAAM,QAAgB,OAAO,GAAG;CAChC,OAAO,MAAM,KAAK,IAAI,MAAM;AAC9B"}