{"version":3,"file":"_randomFormatHostname.mjs","names":[],"sources":["../../src/internal/_randomFormatHostname.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport { _randomString } from \"./_randomString\";\nimport { _ILengthProps } from \"./_randomStringLength\";\n\nexport const _randomFormatHostname = (props?: _ILengthProps): string => {\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return `${random(10)}.${random(3)}`;\n  // A hostname is dot-joined labels of 1..63 chars whose total is capped at 253,\n  // so the requested length is realized by splitting it across enough labels.\n  return _randomHostnameLabels(pickLength(props));\n};\n\nconst MAX_TOTAL = 253;\nconst MAX_LABEL = 63;\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 hostname satisfying both the format and the length constraints.\",\n    );\n  return _randomInteger({ type: \"integer\", minimum: low, maximum: high });\n};\n\n/**\n * Builds dot-joined hostname labels totaling exactly `length` characters, each\n * label within 63 chars. Shared with the idn-hostname generator, which reserves\n * a fixed `.<tld>` suffix and realizes the rest as these leading labels.\n */\nexport const _randomHostnameLabels = (length: number): string => {\n  const parts: string[] = [];\n  let remaining: number = length;\n  while (remaining > MAX_LABEL + 1) {\n    // one full label plus its joining dot\n    parts.push(random(MAX_LABEL));\n    remaining -= MAX_LABEL + 1;\n  }\n  if (remaining <= MAX_LABEL) parts.push(random(remaining));\n  else {\n    // remaining === MAX_LABEL + 1: two labels keep every label within 63 chars\n    parts.push(random(MAX_LABEL - 1));\n    parts.push(random(1));\n  }\n  return parts.join(\".\");\n};\n\nconst random = (length: number) =>\n  _randomString({ type: \"string\", minLength: length, maxLength: length });\n"],"mappings":";;;AAIA,MAAa,yBAAyB,UAAkC;CACtE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;CAGlC,OAAO,sBAAsB,WAAW,KAAK,CAAC;AAChD;AAEA,MAAM,YAAY;AAClB,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,6FACF;CACF,OAAO,eAAe;EAAE,MAAM;EAAW,SAAS;EAAK,SAAS;CAAK,CAAC;AACxE;;;;;;AAOA,MAAa,yBAAyB,WAA2B;CAC/D,MAAM,QAAkB,CAAC;CACzB,IAAI,YAAoB;CACxB,OAAO,YAAY,IAAe;EAEhC,MAAM,KAAK,OAAO,SAAS,CAAC;EAC5B,aAAa;CACf;CACA,IAAI,aAAa,WAAW,MAAM,KAAK,OAAO,SAAS,CAAC;MACnD;EAEH,MAAM,KAAK,OAAO,YAAY,CAAC,CAAC;EAChC,MAAM,KAAK,OAAO,CAAC,CAAC;CACtB;CACA,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,MAAM,UAAU,WACd,cAAc;CAAE,MAAM;CAAU,WAAW;CAAQ,WAAW;AAAO,CAAC"}