self-assert
Version:
A small TypeScript library for designing models with built-in validity.
80 lines • 3.43 kB
TypeScript
import type { RuleRequirement } from "../rule";
/**
* @category Supporting types
*/
export type Predicate<ValueType> = RuleRequirement<boolean, ValueType>;
/**
* A collection of common rule requirements.
*
* It also provides a way to compose requirements using the `and`, `or` and `not` functions.
*
* @namespace
*
* @category Rules
* @categoryDescription Composition
* Methods for composing requirements. Example:
* {@includeCode ../../../../examples/snippets/requirements.ts#composition}
*/
export declare const Requirements: {
/**
* @hidden
* @privateRemarks
* This is to avoid TypeDoc from showing the prototype in the docs
*/
prototype: Object;
/**
* A predicate that evaluates to `true` if the string is empty or contains only whitespace characters.
* @function @category Strings
* @see {@link isNotBlank}
*/
isBlank: Predicate<string>;
/**
* Opposite of {@link isBlank}.
* @function @category Strings
*/
isNotBlank: Predicate<string>;
hasExactly: (aNumber: number) => (list: ArrayLike<unknown>) => boolean;
isEmpty: Predicate<ArrayLike<unknown>>;
isNotEmpty: Predicate<ArrayLike<unknown>>;
hasMoreThan: (aNumber: number) => (list: ArrayLike<unknown>) => boolean;
hasAtMost: (aNumber: number) => Predicate<ArrayLike<unknown>>;
hasLessThan: (aNumber: number) => Predicate<ArrayLike<unknown>>;
hasAtLeast: (aNumber: number) => Predicate<ArrayLike<unknown>>;
includes: <ElementType>(element: ElementType) => Predicate<{
includes: Predicate<ElementType>;
}>;
doesNotInclude: <ElementType>(element: ElementType) => Predicate<{
includes: Predicate<ElementType>;
}>;
allSatisfy: <ElementType>(predicate: Predicate<ElementType>) => (list: Iterable<ElementType>) => boolean;
anySatisfy: <ElementType>(predicate: Predicate<ElementType>) => (list: Iterable<ElementType>) => boolean;
noneSatisfy: <ElementType>(predicate: Predicate<ElementType>) => Predicate<Iterable<ElementType>>;
greaterThan: (aNumber: number) => Predicate<number>;
greaterThanOrEqual: (aNumber: number) => Predicate<number>;
lessThan: (aNumber: number) => Predicate<number>;
lessThanOrEqual: (aNumber: number) => Predicate<number>;
between: (min: number, max: number) => Predicate<number>;
isInteger: (number: unknown) => boolean;
isFloat: Predicate<unknown>;
isPositive: Predicate<number>;
isNegative: Predicate<number>;
isPositiveInteger: Predicate<number>;
isNegativeInteger: Predicate<number>;
isIntegerBetween: (min: number, max: number) => Predicate<number>;
and: <ValueType>(...conditions: Predicate<ValueType>[]) => Predicate<ValueType>;
or: <ValueType>(...conditions: Predicate<ValueType>[]) => Predicate<ValueType>;
not: <ValueType>(condition: Predicate<ValueType>) => Predicate<ValueType>;
identical: <ValueType>(expected: ValueType) => Predicate<ValueType>;
differentFrom: <ValueType>(forbiddenValue: ValueType) => Predicate<ValueType>;
isIn: <ValueType>(...allowedSet: ValueType[]) => Predicate<ValueType>;
isNotIn: <ValueType>(...forbiddenSet: ValueType[]) => Predicate<ValueType>;
/**
* A predicate that always evaluates to `true`.
*/
hold: () => boolean;
/**
* A predicate that always evaluates to `false`.
*/
fail: () => boolean;
};
//# sourceMappingURL=Requirements.d.ts.map