New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

min-max-range

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

min-max-range

Implementation of range data structures using plain JavaScript arrays.

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

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.

Keywords

array

FAQs

Package last updated on 27 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts