npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

min-max-range

v1.0.6

Published

Implementation of range data structures using plain JavaScript arrays.

Downloads

17

Readme

build Coverage Status GitHub License NPM Version Monthly Downloads

min-max-range

Implementation of range data structures using plain JavaScript arrays. Built with a functional programming approach in mind.

Importing this library

Node Modules

  • Run npm install min-max-range
  • Import the utility functions you need and use them in your code.

CDN

  • Put the following script tag <script src="https://cdn.jsdelivr.net/npm/min-max-range@1/dist/min-max-range.umd.min.js"></script> in the head of your HTML file.
  • Then you can access the library with the global variable minMaxRange

Data Types

EmptyRange

type EmptyRange = [];

Range1D

type Range1D = [number, number];

Range2D

type Range2D = [Range1D, Range1D];

MultiDimRange

type MultiDimRange = [Range1D, Range1D, ...Range1D[]];

NonEmptyRange

type NonEmptyRange = Range1D | MultiDimRange;

Range

type Range = EmptyRange | NonEmptyRange;

Coordinates2D

type Coordinates2D = [number, number];

Transform

type Transform<Input, Output> = (value: Input) => Output;

Utility Functions

isRange: (value) => boolean

Check if value is range.

  • value (any): Value to test.

isEmptyRange: (value) => boolean

Check if value is empty range.

  • value (any): Value to test.

isNonEmptyRange: (value) => boolean

Check if value is non-empty range.

  • value (any): Value to test.

isRange1D: (value) => boolean

Check if value is one-dimensional range.

  • value (any): Value to test.

isRange2D: (value) => boolean

Check if value is two-dimensional range.

  • value (any): Value to test.

isMultiDimRange: (value) => boolean

Check if value is multi-dimensional range.

  • value (any): Value to test.

min: (range) => undefined | number | number[]

Return minimum value of each dimension of a range.

  • range (Range): The range.

Example

var minOfRange = min([-1, 1]);

console.log(minOfRange);
// expected output: -1

max: (range) => undefined | number | number[]

Return maximum value of each dimension of a range.

  • range (Range): The range.

Example

var maxOfRange = max([1, -1]);

console.log(maxOfRange);
// expected output: 1

mean: (range) => undefined | number | number[]

Return mean of each dimension of a range.

  • range (Range): The range.

Example

var meanOfRange = mean([-1, 1]);

console.log(meanOfRange);
// expected output: 0

first: (range) => undefined | number | number[]

Return the first value of each dimension of a range.

  • range (Range): The range.

Example

var firstOfRange = first([0, 1]);

console.log(firstOfRange);
// expected output: 0

last: (range) => undefined | number | number[]

Return the last value of each dimension of a range.

  • range: (Range): The range.

Example

var lastOfRange = last([0, 1]);

console.log(lastOfRange);
// expected output: 1

length: (range) => number | number[]

Return length of each dimension of a range.

  • range (Range): The range.

Example

var lengthOfRange = length([-1, 1]);

console.log(lengthOfRange);
// expected output: 2

bottomLeft: (range) => Coordinates2D

Return bottom-left coordinates of two-dimensional range.

  • range (Range2D): Two-dimensional range.

Example

var coords = bottomLeft([[0, 1], [0, 1]]);

console.log(coords);
// expected output: Array [0, 0]

bottomRight: (range) => Coordinates2D

Return bottom-right coordinates of two-dimensional range.

  • range (Range2D): Two-dimensional range.

Example

var coords = bottomRight([[0, 1], [0, 1]]);

console.log(coords);
// expected output: Array [1, 0]

topLeft: (range) => Coordinates2D

Return top-left coordinates of two-dimensional range.

  • range (Range2D): Two-dimensional range.

Example

var coords = topLeft([[0, 1], [0, 1]]);

console.log(coords);
// expected output: Array [0, 1]

topRight: (range) => Coordinates2D

Return top-right coordinates of two-dimensional range.

  • range (Range2D): Two-dimensional range.

Example

var coords = topRight([[0, 1], [0, 1]]);

console.log(coords);
// expected output: Array [1, 1]

shift: (range, delta) => Range

Move range by a specified delta.

  • range (Range): Range to move.
  • delta (number | number[]): Delta to move range by. Has to have equal length as range in case of multi-dimensional ranges.

Example

var shiftedRange = shift([0, 1], -0.5);

console.log(shiftedRange);
// expected output: Array [-0.5, 0.5]

sort: (range) => Range

Return range with values in each dimension sorted from lowest to highest.

  • range: (Range): The range.

Example

var sortedRange = sort([1, -1]);

console.log(sortedRange);
// expected output: Array [-1, 1]

reverse: (range) => Range

Return range with values in each dimensions swapped.

  • range (Range): The range.

Example

var reversedRange = reverse([0, 1]);

console.log(reversedRange);
// expected output: Array [1, 0]

inside: (range) => Transform<number | number[], boolean>

Return method to check if value is included in range.

  • range (Range): Reference range.

Example

var isInside = inside([0, 1]);

console.log(isInside(0.5));
// expected output: true

includes: (range) => Transform<Range, boolean>

Return method to check if one range is included in another.

  • range (Range): Reference range.

Example

var isIncluded = includes([-1, 1]);

console.log(isIncluded([0, 1]));
// expected output: true

partOf: (range) => Transform<Range, boolean>

Return method to check if range is part of another.

  • range (Range): Reference range.

Example

var isPartOf = partOf([0, 1]);

console.log(isPartOf([-1, 1]));
// expected output: true

intersect: (range) => Transform<Range, Range>

Return method to determine intersection of range with reference.

  • range (Range): Reference range.

Example

var intersection = intersect([-1, 1]);

console.log(intersection([0, 2]));
// expected output: Array [0, 1]

NPM Scripts

  • npm install: Install dependencies
  • npm test: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code

Contributing

Pull requests are welcome! Please include new tests for your code and make sure that all tests succeed running npm test.