UNPKG

@naturalcycles/nodejs-lib

Version:
29 lines (28 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Joi = void 0; const JoiLib = require("joi"); const number_extensions_1 = require("./number.extensions"); const string_extensions_1 = require("./string.extensions"); /** * This is the only right place to import Joi from */ // eslint-disable-next-line @typescript-eslint/naming-convention exports.Joi = JoiLib.defaults(schema => { // hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself if (schema.type === 'string') { return (schema .trim() // trim all strings by default // 2020-09-21: null values are NOT treated as EMPTY enymore // .empty([schema.valid('', null)]) // treat '' or null as empty (undefined, will be stripped out) // treat '' as empty (undefined, will be stripped out) .empty([schema.valid('')])); } // Treat `null` as undefined for all schema types // undefined values will be stripped by default from object values // 2020-09-21: breaking change: null values are NOT treated as EMPTY anymore // return schema.empty(null) return schema; }) .extend((joi) => (0, string_extensions_1.stringExtensions)(joi)) .extend((joi) => (0, number_extensions_1.numberExtensions)(joi));