UNPKG

zod-error

Version:

Utilities to format and customize Zod error messages

22 lines (21 loc) 729 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getObjectNotation = void 0; /** * Converts a Zod Issue path to object notation. * @export * @param {z.ZodIssue['path']} path * @param {ObjectNotation} options * @return {*} {string} */ function getObjectNotation(path, options) { var _a; const arraySquareBrackets = (_a = options.arraySquareBrackets) !== null && _a !== void 0 ? _a : true; return path.reduce((str, key) => { if (typeof key === 'number' && arraySquareBrackets) { return `${str}[${key}]`; } return [str, key].filter((s) => typeof s === 'number' || !!s).join('.'); }, ''); } exports.getObjectNotation = getObjectNotation;