{"version":3,"file":"_randomFormatByte.mjs","names":[],"sources":["../../src/internal/_randomFormatByte.ts"],"sourcesContent":["import { _randomInteger } from \"./_randomInteger\";\nimport {\n  _ILengthProps,\n  _RANDOM_LENGTH_ERROR,\n  _randomLengthPick,\n  _randomLengthWindow,\n} from \"./_randomStringLength\";\nimport { __randomBase64 } from \"./private/__randomComposition\";\n\n/**\n * Generate a Base64 string for the `byte` format at a length the bounds allow.\n *\n * @evidence contracts/common.md#principled-implementation Base64 lengths are multiples of four, so an unconstrained draw spends four to twelve groups, and a constrained one raises the window floor to the first multiple of four it contains and steps by four; an empty window throws. Each character is from the alphabet that the validator allows, so no encoding step is needed and no padding is produced.\n * @evidence contracts/common.md#clear-and-simple-design One function over the shared length window and Base64 helpers.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The length rule is the format's.\n * @evidence contracts/common.md#meaningful-documentation An inline comment explains the grouping.\n */\nexport const _randomFormatByte = (props?: _ILengthProps): string => {\n  // Base64 encodes three bytes as four characters, so a valid length is always\n  // a multiple of four; an unconstrained draw spends between four and twelve\n  // groups, and a constrained one raises the window to the first multiple it\n  // contains and steps by four from there.\n  if (props?.minLength === undefined && props?.maxLength === undefined)\n    return __randomBase64(\n      4 *\n        _randomInteger({\n          type: \"integer\",\n          minimum: DEFAULT_GROUP_MIN,\n          maximum: DEFAULT_GROUP_MAX,\n        }),\n    );\n  const window = _randomLengthWindow(props, { minimum: 0, spread: 16 });\n  const low: number = Math.ceil(window.low / 4) * 4;\n  if (low > window.high) throw new Error(_RANDOM_LENGTH_ERROR);\n  const length: number =\n    low +\n    4 *\n      _randomLengthPick({\n        low: 0,\n        high: Math.floor((window.high - low) / 4),\n      });\n  return __randomBase64(length);\n};\n\nconst DEFAULT_GROUP_MIN = 4;\nconst DEFAULT_GROUP_MAX = 12;\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAa,qBAAqB,UAAkC;CAKlE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,eACL,IACE,eAAe;EACb,MAAM;EACN,SAAS;EACT,SAAS;CACX,CAAC,CACL;CACF,MAAM,SAAS,oBAAoB,OAAO;EAAE,SAAS;EAAG,QAAQ;CAAG,CAAC;CACpE,MAAM,MAAc,KAAK,KAAK,OAAO,MAAM,CAAC,IAAI;CAChD,IAAI,MAAM,OAAO,MAAM,MAAM,IAAI,MAAM,oBAAoB;CAQ3D,OAAO,eANL,MACA,IACE,kBAAkB;EAChB,KAAK;EACL,MAAM,KAAK,OAAO,OAAO,OAAO,OAAO,CAAC;CAC1C,CAAC,CACuB;AAC9B;AAEA,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB"}