typia
Version:
Superfast runtime validators with only one line
1 lines • 1.73 kB
Source Map (JSON)
{"version":3,"file":"_randomFormatByte.mjs","names":[],"sources":["../../src/internal/_randomFormatByte.ts"],"sourcesContent":["import { _randomString } from \"./_randomString\";\nimport {\n _ILengthProps,\n _RANDOM_LENGTH_ERROR,\n _randomLengthPick,\n _randomLengthWindow,\n} from \"./_randomStringLength\";\n\nexport const _randomFormatByte = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return FIXED;\n // Base64 encodes three bytes as four characters, so a valid length is always\n // a multiple of four; the window is raised to the first multiple it contains\n // and the draw steps by four from there. Every character `_randomString`\n // emits is in the base64 alphabet, so the result needs no padding.\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 _randomString({\n type: \"string\",\n minLength: length,\n maxLength: length,\n });\n};\n\nconst FIXED = \"vt7ekz4lIoNTTS9sDQYdWKharxIFAR54+z/umIxSgUM=\";\n"],"mappings":";;;AAQA,MAAa,qBAAqB,UAAkC;CAClE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO;CAKT,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;CAC3D,MAAM,SACJ,MACA,IACE,kBAAkB;EAChB,KAAK;EACL,MAAM,KAAK,OAAO,OAAO,OAAO,OAAO,CAAC;CAC1C,CAAC;CACL,OAAO,cAAc;EACnB,MAAM;EACN,WAAW;EACX,WAAW;CACb,CAAC;AACH;AAEA,MAAM,QAAQ"}