typia
Version:
Superfast runtime validators with only one line
1 lines • 1.6 kB
Source Map (JSON)
{"version":3,"file":"_validateReport.mjs","names":[],"sources":["../../src/internal/_validateReport.ts"],"sourcesContent":["import { IValidation } from \"@typia/interface\";\n\nexport const _validateReport = (array: IValidation.IError[]) => {\n const isAncestor = (ancestor: string, descendant: string): boolean =>\n descendant === ancestor ||\n descendant.startsWith(`${ancestor}.`) ||\n descendant.startsWith(`${ancestor}[`);\n const reportable = (path: string): boolean => {\n if (array.length === 0) return true;\n const last: string = array[array.length - 1]!.path;\n return isAncestor(path, last) === false && isAncestor(last, path) === false;\n };\n return (exceptable: boolean, error: IValidation.IError): false => {\n if (exceptable && reportable(error.path)) {\n if (error.value === undefined)\n error.description ??= [\n \"The value at this path is `undefined`.\",\n \"\",\n `Please fill the \\`${error.expected}\\` typed value next time.`,\n ].join(\"\\n\");\n array.push(error);\n }\n return false;\n };\n};\n"],"mappings":";AAEA,MAAa,mBAAmB,UAAgC;CAC9D,MAAM,cAAc,UAAkB,eACpC,eAAe,YACf,WAAW,WAAW,GAAG,SAAS,EAAE,KACpC,WAAW,WAAW,GAAG,SAAS,EAAE;CACtC,MAAM,cAAc,SAA0B;EAC5C,IAAI,MAAM,WAAW,GAAG,OAAO;EAC/B,MAAM,OAAe,MAAM,MAAM,SAAS,EAAE,CAAE;EAC9C,OAAO,WAAW,MAAM,IAAI,MAAM,SAAS,WAAW,MAAM,IAAI,MAAM;CACxE;CACA,QAAQ,YAAqB,UAAqC;EAChE,IAAI,cAAc,WAAW,MAAM,IAAI,GAAG;GACxC,IAAI,MAAM,UAAU,KAAA,GAClB,MAAM,gBAAgB;IACpB;IACA;IACA,qBAAqB,MAAM,SAAS;GACtC,CAAC,CAAC,KAAK,IAAI;GACb,MAAM,KAAK,KAAK;EAClB;EACA,OAAO;CACT;AACF"}