/nkp-range

Iterator utility for working with discrete and continuous ranges.

Primary LanguageTypeScriptMIT LicenseMIT

@nkp/range

npm version deploy status known vulnerabilities

Zero dependency utility to create iterable discrete and continuous ranges.

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

for (const state of range({ start: 0, end: 6, step: 2, inclusive: true })) {
    const { cursor, step, to, set, isInBounds, } = state;
    console.log(cursor);
}

// 0
// 2
// 4
// 6

Table of contents

Exports

@nkp/range exports both CommonJS and ES modules.

Installation

npm

npm install @nkp/range

yarn

yarn add @nkp/range

pnpm

pnpm add @nkp/range

Usage

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

for (const state of range({ start: 0, end: 6, step: 2, inclusive: true })) {
    const { cursor, step, to, set, isInBounds, } = state;
    console.log(cursor);
}

// 0
// 2
// 4
// 6

Publishing

To a release a new version:

  1. Update the version number in package.json
  2. Push the new version to the master branch on GitHub
  3. Create a new release on GitHub for the latest version

This will trigger a GitHub action that tests and publishes the npm package.