UNPKG

decentralized-internet

Version:

An NPM library of programs to create decentralized web and distributed computing projects

1 lines 556 B
"use strict";const errors=require("./errors"),interval=function(r){if(!r)throw new Error("Options are missing.");if(void 0===r.left)throw new Error("Left is missing.");if(void 0===r.right)throw new Error("Right is missing.");if(void 0===r.type)throw new Error("Type is missing.");const e=r.left,i=r.right;switch(r.type){case"open":return{contains:r=>e<i?e<r&&r<i:e>i?e<r||r<i:e!==r};case"leftopen":return{contains:r=>e<i?e<r&&r<=i:!(e>i)||(e<r||r<=i)};default:throw new errors.InvalidOperation(`Unknown interval type ${r.type}.`)}};module.exports=interval;