MCPcopy Create free account
hub / github.com/Forward-Future/loopy / optionalString

Function optionalString

loop-library/worker/src/loop-schema.js:185–201  ·  view source on GitHub ↗
(value, field, maxLength)

Source from the content-addressed store, hash-verified

183}
184
185function 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
203function stringArray(value, field, { min, max, itemMax }) {
204 if (!Array.isArray(value) || value.length < min || value.length > max) {

Callers 1

normalizeLoopDocumentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected