UNPKG

@frauschert/ts-guard

Version:

ts-guard is a typescript library that provides composable type guards. Its inspired by zod but focusses only on type guards and is more lightweight.

25 lines 821 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isString = isString; function isString(constraints) { return (value) => { if (typeof value !== "string") { return false; } if (!constraints) { return true; } const stringToTest = constraints.trim ? value.trim() : value; if (constraints.minLength !== undefined && stringToTest.length < constraints.minLength) { return false; } if (constraints.maxLength !== undefined && stringToTest.length > constraints.maxLength) { return false; } if (constraints.pattern && !constraints.pattern.test(stringToTest)) { return false; } return true; }; } //# sourceMappingURL=isString.js.map