@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 • 741 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isArrayOf = void 0;
const isArrayOf = (itemGuard, constraints) => (x) => {
if (!Array.isArray(x)) {
return false;
}
if (!x.every(itemGuard)) {
return false;
}
if (constraints) {
if (constraints.minLength !== undefined && x.length < constraints.minLength) {
return false;
}
if (constraints.maxLength !== undefined && x.length > constraints.maxLength) {
return false;
}
if (constraints.unique && new Set(x).size !== x.length) {
return false;
}
}
return true;
};
exports.isArrayOf = isArrayOf;
//# sourceMappingURL=isArrayOf.js.map