UNPKG

typia

Version:

Superfast runtime validators with only one line

24 lines (23 loc) 838 B
//#region src/internal/_validateReport.ts const _validateReport = (array) => { const isAncestor = (ancestor, descendant) => descendant === ancestor || descendant.startsWith(`${ancestor}.`) || descendant.startsWith(`${ancestor}[`); const reportable = (path) => { if (array.length === 0) return true; const last = array[array.length - 1].path; return isAncestor(path, last) === false && isAncestor(last, path) === false; }; return (exceptable, error) => { if (exceptable && reportable(error.path)) { if (error.value === void 0) error.description ??= [ "The value at this path is `undefined`.", "", `Please fill the \`${error.expected}\` typed value next time.` ].join("\n"); array.push(error); } return false; }; }; //#endregion export { _validateReport }; //# sourceMappingURL=_validateReport.mjs.map