Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ouracademy/range

ouracademy6MIT1.5.1TypeScript support: included

A range

range, interval, sequence

readme

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.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.5.1 (2019-07-13)

1.5.0 (2019-07-13)

Features

  • rename iterate to step() (ead43d2)

1.4.0 (2018-12-23)

Bug Fixes

  • no exporting default, use named imports (d10edeb)

Features

  • add submodule intersection (6699f23)

1.3.0 (2018-12-22)

Features

1.2.0 (2018-12-21)

Features

1.1.1 (2018-12-19)

Bug Fixes

1.1.0 (2018-12-19)

Features

  • move to typescript-starter (a3a8a78)