UNPKG

typia

Version:

Superfast runtime validators with only one line

1 lines 1.84 kB
{"version":3,"file":"_randomFormatJsonPointer.mjs","names":[],"sources":["../../src/internal/_randomFormatJsonPointer.ts"],"sourcesContent":["import { _randomString } from \"./_randomString\";\nimport {\n _ILengthProps,\n _randomLengthPick,\n _randomLengthWindow,\n _randomSegmentLength,\n} from \"./_randomStringLength\";\n\nexport const _randomFormatJsonPointer = (props?: _ILengthProps): string => {\n if (props?.minLength === undefined && props?.maxLength === undefined)\n return `${PREFIX}${random()}`;\n // The `/components/schemas/` prefix (20 chars) is fixed; the reference token\n // after it grows or shrinks to hit the requested length.\n if (props.maxLength === undefined || props.maxLength >= PREFIX.length)\n return `${PREFIX}${_randomSegmentLength(props, PREFIX.length, 10, 0)}`;\n // Below that prefix a pointer still exists: the empty pointer addresses the\n // whole document, and one `/`-prefixed token addresses a member of it.\n const length: number = _randomLengthPick(\n _randomLengthWindow(props, { minimum: 0, spread: 6 }),\n );\n return length === 0\n ? \"\"\n : `/${_randomString({\n type: \"string\",\n minLength: length - 1,\n maxLength: length - 1,\n })}`;\n};\n\nconst PREFIX = \"/components/schemas/\";\n\nconst random = () =>\n _randomString({ type: \"string\", minLength: 10, maxLength: 10 });\n"],"mappings":";;;AAQA,MAAa,4BAA4B,UAAkC;CACzE,IAAI,OAAO,cAAc,KAAA,KAAa,OAAO,cAAc,KAAA,GACzD,OAAO,GAAG,SAAS,OAAO;CAG5B,IAAI,MAAM,cAAc,KAAA,KAAa,MAAM,aAAa,OAAO,QAC7D,OAAO,GAAG,SAAS,qBAAqB,OAAO,OAAO,QAAQ,IAAI,CAAC;CAGrE,MAAM,SAAiB,kBACrB,oBAAoB,OAAO;EAAE,SAAS;EAAG,QAAQ;CAAE,CAAC,CACtD;CACA,OAAO,WAAW,IACd,KACA,IAAI,cAAc;EAChB,MAAM;EACN,WAAW,SAAS;EACpB,WAAW,SAAS;CACtB,CAAC;AACP;AAEA,MAAM,SAAS;AAEf,MAAM,eACJ,cAAc;CAAE,MAAM;CAAU,WAAW;CAAI,WAAW;AAAG,CAAC"}