1.5.1 • Published 5 years ago

@ouracademy/range v1.5.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Range

A package for dealing with ranges (start, end) - aka interval written in typescript, but works with vanilla JS.

More on API docs or our specifications (.spec files) for more examples

Motivation

Well my motivation is just taste & some useful methods

const aRange = range(0, 5);

if (0 <= myAge && myAge <= 5) console.log("I'm a baby.");
if (aRange.includes(myAge)) console.log("I'm a baby.");

for (let n = 0; n <= 5; n += 2) console.log(n);
for (let n of aRange.step(2)) console.log(n);

Usage

import { range } from '@ouracademy/range';

const aRange = range(1, 10); // or interval(1, 10)

String(aRange); // "[1,10]"
String(range(15)); // "[0,15]"
range(2, 10).lenght; // 9
aRange.includes(9); // true
aRange.includes(11); // false
aRange.includes(0); // false
aRange.includes(range(2, 10)); // true
aRange.includes(range(0, 10)); // false
aRange.includes(range(1, 11)); // false

aRange.step(); // lazy evaluated - 1, 2 ...10
aRange.step(2); // 1, 5, 9

aRange.toArray(); // [1, 2 ... 10]
aRange.toArray(2); // [1, 5, 9]

There are other useful functions like: intersection, overlaps that could be found in the API doc.

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago