{"version":3,"file":"_randomFormatIdnHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatIdnHostname.ts"],"sourcesContent":["import { _randomHostnameLabels } from \"./_randomFormatHostname\";\nimport { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\n/**\n * Generate an internationalized hostname at a length the bounds allow.\n *\n * Samples lowercase ASCII labels, each at most 63 characters. Constrained\n * lengths range from one to 253; an empty intersection with the supplied\n * inclusive bounds throws.\n *\n * @evidence contracts/common.md#principled-implementation The internationalized hostname has the same label structure as the hostname, so the same label builder realizes the requested length.\n * @evidence contracts/common.md#clear-and-simple-design One function sharing the label builder.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts It generates ASCII labels, which are valid IDN hostnames.\n * @evidence contracts/common.md#meaningful-documentation Native prose states the ASCII sample and label/total length bounds with explicit failure; the inline comment explains reuse of the shared label structure.\n */\nexport const _randomFormatIdnHostname = (props?: _ILengthProps): string => {\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return `${random(10)}.${random(3)}`;\n  // idn-hostname shares hostname's structure (a single label of 1..63 chars is\n  // valid, no dot or trailing label required), so the requested length is\n  // realized the same way: split it across dot-joined labels. #2317 dropped the\n  // mandatory dot and two-character trailing label this generator used to\n  // reserve, which is why it now realizes a length below four.\n  return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\n\nconst pickLength = (props: _ILengthProps): number => {\n  let low: number = props.minLength === undefined ? 1 : props.minLength;\n  if (low < 1) low = 1;\n  const high: number =\n    props.maxLength === undefined\n      ? Math.min(MAX_TOTAL, low + 14)\n      : Math.min(MAX_TOTAL, props.maxLength);\n  if (high < low)\n    throw new Error(\n      \"unable to generate a random idn hostname satisfying both the format and the length constraints.\",\n    );\n  return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\nconst random = (length: number) =>\n  _randomString({ type: \"string\", minLength: length, maxLength: length });\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,4BAA4B,UAAkC;CACzE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAMlC,OAAO,sBAAsB,WAAW,KAAK,CAAC;AAChD;AAEA,MAAM,YAAY;AAElB,MAAM,cAAc,UAAiC;CACnD,IAAI,MAAc,MAAM,cAAc,KAAA,IAAY,IAAI,MAAM;CAC5D,IAAI,MAAM,GAAG,MAAM;CACnB,MAAM,OACJ,MAAM,cAAc,KAAA,IAChB,KAAK,IAAI,WAAW,MAAM,EAAE,IAC5B,KAAK,IAAI,WAAW,MAAM,SAAS;CACzC,IAAI,OAAO,KACT,MAAM,IAAI,MACR,iGACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;AAEA,MAAM,UAAU,WACd,cAAc;CAAE,MAAM;CAAU,WAAW;CAAQ,WAAW;AAAO,CAAC"}