Interval Spans
![npm](https://img.shields.io/npm/v/interval-spans?style=plastic)
For when you need to create interval spans and no other library will do.
Easily create interval spans, look up to which interval span a number belongs to (if any) and attach metadata to your interval spans.
Installation
yarn add interval-spans
npm install interval-spans
Usage
Interval Span
Creates an interval span from start
(inclusive) to end
(exclusive) and attach
Constructor
API
new IntervalSpan(start: number, end: number, metadata?: Record<string, any>);
Example
import { IntervalSpan } from 'interval-span';
const singleDigitIntegerSpan = new IntervalSpan(0, 10, {
name: 'single-digits',
});
Includes
API
instance.includes(numberToTest: number): boolean;
Example
const intervalSpan = new IntervalSpan(0, 10);
intervalSpan.includes(0);
intervalSpan.includes(10);
Interval Spans
Constructor
API
new IntervalSpans(intervalSpans: IntervalSpan[]);
Example
import { IntervalSpans } from 'interval-spans';
const intervalSpans = new IntervalSpans([new IntervalSpan(0, 10), new IntervalSpan(10, 20)]);
Get Span by Number
Finds the span which includes a number.
API
instance.getSpanByNumber(numberToTest: number): IntervalSpan | null;
Example
const intervalSpans = new IntervalSpans([
new IntervalSpan(0, 10, { name: 'single-digits' }),
new IntervalSpan(10, 20, { name: 'ten-to-twenty' }),
]);
intervalSpans.getSpanByNumber(0);
intervalSpans.getSpanByNumber(10);
intervalSpans.getSpanByNumber(20);
License
MIT