(value, field, maxLength)
| 183 | } |
| 184 | |
| 185 | function optionalString(value, field, maxLength) { |
| 186 | if (value === undefined || value === null || value === "") { |
| 187 | return undefined; |
| 188 | } |
| 189 | |
| 190 | if (typeof value !== "string") { |
| 191 | throw new LoopValidationError(`${field} must be a string.`); |
| 192 | } |
| 193 | |
| 194 | const normalized = value.trim(); |
| 195 | |
| 196 | if (normalized.length > maxLength) { |
| 197 | throw new LoopValidationError(`${field} must be no longer than ${maxLength} characters.`); |
| 198 | } |
| 199 | |
| 200 | return normalized || undefined; |
| 201 | } |
| 202 | |
| 203 | function stringArray(value, field, { min, max, itemMax }) { |
| 204 | if (!Array.isArray(value) || value.length < min || value.length > max) { |
no outgoing calls
no test coverage detected