Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

number-pairs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

number-pairs

Javascript utility for dealing with ranges of numbers and/or dates expressed as length-2 arrays.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

number-pairs

Javascript utility for dealing with ranges of numbers and/or dates expressed as length-2 arrays.

contains

tests if a range expressed as a pair of numbers contains some other value

contains([2,6],4) // true, 4 is in contained in the range 2-6
contains([2,6],7) // false

A range is considered to contain its lower bound but not its upper:

contains([2,6],2)       // true
contains([2,6],5.99)    // true
contains([2,6],6)       // false

centredOn

Creates a new range of the same size, but centred around a new value (think panning):

centredOn([2,3], 10) // [-9.5, 10.5]

mid

Calculates the midpoint of a pair of numbers

mid(-5, 5) // 0
mid(5, 10) // 7.5

pairExtent

pairExtent(-1, 10) // 11

interpolateBetweenPair

interpolateBetweenPair([5,10], 0.5) // 7.5
interpolateBetweenPair([5,10], 0)   // 5
interpolateBetweenPair([5,10], 1)   // 10

rangesOverlap

rangesOverlap([1,4],[3,8]) // returns true - these ranges overlap
rangesOverlap([1,4],[5,8]) // returns false - these ranges do notoverlap

overlap

overlap(a,b,c,d)
// same as:
rangesOverlap([a,b], [c,d])

expandPair

Expand a range so that it the returned value is proptionally larger (or smaller) than the given value.

it holds that:

extent( expand( r, n ) ) / extent(r) === n

so, to double the extent of a range:

expand( r, 2 )

to half the extent of a range:

expand( r, 0.5 )

max

Enforces the maximum extent of a range, while keeping the centre point the same (think viewport minimum)

max([a,b], maxExtent)

min

Enforces the minimum extent of a range, while keeping the centre point the same (think viewport minimum)

min([a,b], minExtent)

Keywords

FAQs

Package last updated on 07 Jun 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc