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

interval-op

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interval-op

Basic operations on discrete intervals in JS

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

interval-op

0-dependencies library implemeting basic operations on discrete intervals where boundary conditions reflect the intuitive expectations when dealing with availabilities.

// Union behaves like with closed intervals
[9 .. 12] U [12 .. 17] = [9 .. 17]

// Substraction behaves like with open intervals
[9 .. 17] - [15 .. 17] = [9 .. 15]

Install

npm install interval-op

Usage

  • Intervals are represented as arrays of length 2
    • [start, end]
  • The functions manipulate sets of intervals which are represented as arrays of intervals:
    • [ [start1, end1], [start2, end2], ... ]

Examples:

const { union, subtract } = require('interval-op')
console.log( union([ [9, 12], [12, 17] ]) )          // => [[9, 17]]
console.log( subtract([ [9, 17] ], [ [15, 17] ]) )   // => [[9, 15]]

More examples can be found in test/test.js

Assumptions

The library assumes that the elements used as interval boundaries all have an order relation and can be compared with the relational operators >, <, >= and <=.

For example, it can be used with numbers or dates.

To use it with a more complex object, you can read about Abstract Relational Comparison and Symbol.toPrimitive

See test/ComplexWithRelation.js for an example of custom class implementing Symbol.toPrimitive

Development

  • Install dev dependencies with npm install the library has no production dependencies, but uses standardJS for linting/formatting
  • Run the test suite npm run test
  • Run the linter with npx standard --fix

FAQs

Package last updated on 30 Apr 2020

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