defineIntervalType
function defineIntervalType<T>(domain): BoundIntervalType<T>;Defined in: interval.ts:869
Bind a IntervalDomain to a concrete, new-able interval CLASS that
extends Interval, so instances are instanceof Interval (and
instanceof the bound class). The built-in classes (NumberInterval,
DateInterval, …) are made this way; use it for your own domains.
Operations inherited from Interval (union, intersection, …) return base
Interval<T> values (still instanceof Interval, but not instanceof the
bound class).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
domain |
IntervalDomain<T> |
Returns
Section titled “Returns”Example
Section titled “Example”import { defineIntervalType, Interval, numberDomain } from "@xtandard/lib/interval";
const PercentInterval = defineIntervalType({ ...numberDomain, name: "percent", isValid: (v: number) => v >= 0 && v <= 100,});type PercentInterval = InstanceType<typeof PercentInterval>;
const r = new PercentInterval({ start: 20, startClose: true, end: 80, endClose: true });r.toString(); // "[20,80]"r instanceof PercentInterval; // truer instanceof Interval; // truePercentInterval.atLeast(50).contains(150); // false (fails isValid)PercentInterval.parse("[0,100)").toString(); // "[0,100)"