@debkit/types
v1.2.0
Published
Fluent boolean chains, condition helpers, and type transformation utilities
Downloads
27
Maintainers
Readme
@debkit/types
Fluent boolean chains, condition helpers, and type transformation utilities. Zero dependencies.
Install
npm install @debkit/typesAPI
Boolean Chains
when(value) / is(value) / check(value) / satisfy(value)
Creates a fluent boolean chain for composing conditions.
import { when, check } from '@debkit/types';
when(user).and(user.isActive).truthy(); // true if both truthy
check(value > 0).or(value === -1).truthy(); // true if either
when(condition).negative().truthy(); // negationChain methods:
| Method | Description |
|---|---|
| .and(value) | Logical AND with another value |
| .or(value) | Logical OR with another value |
| .negative() | Negate the chain |
| .truthy() | Resolve to boolean |
toBoolean(data)
Intelligent type coercion to boolean.
import { toBoolean } from '@debkit/types';
toBoolean('hello'); // true
toBoolean(''); // false (empty string after trim)
toBoolean(0); // false
toBoolean([]); // false (empty array)
toBoolean({ a: 1 }); // true (non-empty object)Condition Helpers
and(...conditions) / or(...conditions)
Batch boolean evaluation.
import { and, or } from '@debkit/types';
and(true, true, true); // true
or(false, false, true); // trueprocessConditions<T>(data)
Applies predicate functions against data.
import { processConditions } from '@debkit/types';
processConditions(5).and(
(v) => v > 0,
(v) => v < 10
); // trueisNullOrUndefined(value)
Returns true if value is null or undefined.
isNullAndConditions<T>(value, ...conditions)
Returns true if value is null, OR if all conditions pass.
Type Transformation
transformTypes<T>(value)
Returns a transformer object that converts value to a target type.
import { transformTypes } from '@debkit/types';
transformTypes('42').number(); // 42
transformTypes(1).boolean(); // true
transformTypes('false').boolean(); // false (special string handling)
transformTypes('hello').string(); // 'hello'
// Custom transform
transformTypes('raw').custom((v) => `processed:${v}`);
// 'processed:raw'Error Chain
checkChain<T>(value)
Fluent error-throwing chain.
import { checkChain } from '@debkit/types';
checkChain(port)
.on((v) => v < 0).throw(new Error('Port must be positive'))
.on((v) => v > 65535).throw(new Error('Port out of range'));License
MIT
