Skip to content

hap-fluent / createRangePredicate

Function: createRangePredicate()

ts
function createRangePredicate(
   min, 
   max, 
inclusive?): ValuePredicate<number>;

Defined in: packages/hap-fluent/src/type-utils.ts:268

Create a ValuePredicate that validates whether a number falls within [min, max].

Parameters

ParameterTypeDefault valueDescription
minnumberundefinedMinimum value.
maxnumberundefinedMaximum value.
inclusivebooleantrueWhen true (default), the bounds are inclusive.

Returns

ValuePredicate<number>

A predicate returning true if the value is within range.

Example

typescript
const isValidHue = createRangePredicate(0, 360);
isValidHue(180); // Returns true
isValidHue(400); // Returns false
isValidHue(0);   // Returns true (inclusive)

Released under the Apache-2.0 License.