@philiprehberger/predicate-ts
v0.1.3
Published
Composable predicate builders for filtering and validation
Downloads
422
Readme
@philiprehberger/ts-predicate
Composable predicate builders for filtering and validation.
Installation
npm install @philiprehberger/ts-predicateUsage
import { is, where, and, or, not } from '@philiprehberger/ts-predicate';
users.filter(where({
age: is.gte(18),
status: is.in(['active', 'verified']),
}));
const isSpecial = or(
is.property('role', is.equal('admin')),
and(is.property('tenure', is.gt(5)), is.property('rating', is.gte(4.5))),
);API
| Function | Description |
|----------|-------------|
| is.equal(v) | Strict equality |
| is.gt(n) / is.gte(n) / is.lt(n) / is.lte(n) | Numeric comparisons |
| is.between(a, b) | Inclusive range |
| is.match(regex) | Regex test |
| is.startsWith(s) / is.endsWith(s) / is.includes(s) | String checks |
| is.in(values) | Value in array |
| is.property(key, predicate) | Check object property |
| and(...predicates) | All must pass |
| or(...predicates) | Any must pass |
| not(predicate) | Invert predicate |
| where(shape) | Object shape predicate |
Development
npm install
npm run build
npm testLicense
MIT
