{"version":3,"file":"_randomFormatUrl.mjs","names":[],"sources":["../../src/internal/_randomFormatUrl.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\n/**\n * Generate an `https` URL at a length the bounds allow.\n *\n * Samples lowercase ASCII domain labels and a path segment. Inclusive bounds\n * apply to the complete output; this builder's constrained shape starts at 12\n * characters and throws when the window is shorter.\n *\n * @evidence contracts/common.md#principled-implementation An unconstrained draw is `https://` with a host of random letters and a short top-level label; a constrained one keeps the shortest host and lets a path segment absorb extra length, since a path is unbounded, throwing when the window is below the shortest form.\n * @evidence contracts/common.md#clear-and-simple-design One function and a private length picker.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The shape is the generator's and its limits are reported.\n * @evidence contracts/common.md#meaningful-documentation Native prose identifies the sampled alphabet, whole-output inclusive bounds and 12-character shape floor/failure; the inline comment explains growth through the path.\n */\nexport const _randomFormatUrl = (props?: _ILengthProps): string => {\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return `https://${random(10)}.${random(3)}`;\n  // `https://a.bc` is the shortest host this builder emits (12 chars); any extra\n  // length rides in the path segment, which the URL grammar leaves unbounded.\n  const base: string = `https://${random(1)}.${random(2)}`;\n  const target: number = pickLength(props, base.length);\n  return target <= base.length\n    ? base\n    : `${base}/${random(target - base.length - 1)}`;\n};\n\nconst pickLength = (props: _ILengthProps, base: number): number => {\n  let low: number = props.minLength === undefined ? base : props.minLength;\n  if (low < base) low = base;\n  const high: number =\n    props.maxLength === undefined ? low + 14 : props.maxLength;\n  if (high < low)\n    throw new Error(\n      \"unable to generate a random URL 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({\n    type: \"string\",\n    minLength: length,\n    maxLength: length,\n  });\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAa,oBAAoB,UAAkC;CACjE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,WAAW,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAG1C,MAAM,OAAe,WAAW,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC;CACrD,MAAM,SAAiB,WAAW,OAAO,KAAK,MAAM;CACpD,OAAO,UAAU,KAAK,SAClB,OACA,GAAG,KAAK,GAAG,OAAO,SAAS,KAAK,SAAS,CAAC;AAChD;AAEA,MAAM,cAAc,OAAsB,SAAyB;CACjE,IAAI,MAAc,MAAM,cAAc,KAAA,IAAY,OAAO,MAAM;CAC/D,IAAI,MAAM,MAAM,MAAM;CACtB,MAAM,OACJ,MAAM,cAAc,KAAA,IAAY,MAAM,KAAK,MAAM;CACnD,IAAI,OAAO,KACT,MAAM,IAAI,MACR,wFACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;AAEA,MAAM,UAAU,WACd,cAAc;CACZ,MAAM;CACN,WAAW;CACX,WAAW;AACb,CAAC"}