UNPKG

@edgeguideab/expect

Version:

Check for user input in a consistent way and generate error messages for missings

34 lines (33 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateString = void 0; var index_1 = require("../util/index"); function validateString(_a) { var parameter = _a.parameter, value = _a.value, options = _a.options; if (typeof value !== "string") return { valid: false }; if (options.blockUnsafe && (0, index_1.containsUnsafe)({ value: value, strict: options.strictEntities, allowed: options.allowed, })) { return { valid: false, error: options.blockUnsafeErrorCode || options.errorCode || "Parameter " + (0, index_1.formatParameter)(parameter) + " contained unsafe, unescaped characters", }; } return { valid: true, parsed: options.sanitize ? (0, index_1.sanitize)({ value: value, strict: options.strictEntities, allowed: options.allowed, }) : value, }; } exports.validateString = validateString;