Files
zkldi_Tachi/server/src/utils/prudence.ts
T

16 lines
633 B
TypeScript

// @todo #118 Investigate why this import triggers a circular dependency according to madge.
import p, { PrudenceError, ValidSchemaValue } from "prudence";
export function FormatPrError(err: PrudenceError, foreword = "Error") {
const receivedText =
typeof err.userVal === "object" && err.userVal !== null
? ""
: ` | Received ${err.userVal} [${err.userVal === null ? "null" : typeof err.userVal}]`;
return `${foreword}: ${err.keychain} | ${err.message}${receivedText}.`;
}
export const optNull = (v: ValidSchemaValue) => p.optional(p.nullable(v));
export const optNullFluffStrField = optNull(p.isBoundedString(3, 140));