Files
zkldi_Tachi/server/src/utils/prudence.ts
T
zkldi 5dff2ee805 fix: change prudence's default export to named
this was causing issues with vite and is potentially a bug in prudence
or in vite. it's very hard to tell and i've already spent
3 hours trying to fix this, so here.
2022-12-23 09:04:25 +00:00

18 lines
600 B
TypeScript

import { p } from "prudence";
import type { PrudenceError, ValidSchemaValue } from "prudence";
export function FormatPrError(err: PrudenceError, foreword = "Error") {
const receivedText =
typeof err.userVal === "object" && err.userVal !== null
? ""
: ` | Received ${err.userVal} [type: ${
err.userVal === null ? "null" : typeof err.userVal
}]`;
return `${foreword}: ${err.keychain ?? "null"} | ${err.message}${receivedText}.`;
}
export const optNull = (v: ValidSchemaValue) => p.optional(p.nullable(v));
export const optNullFluffStrField = optNull(p.isBoundedString(3, 140));