math-interval-js
Version:
A simple math interval matcher.
2 lines • 1.37 kB
JavaScript
;!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=new(e()):t.Interval=new(e())}(this,function(){var t=function(){};return t.types={setOfNumbers:/^\s*\{.*\}\s*$/,bothExclusive:/^\s*(\(|\]|\)).*(\)|\[|\()\s*$/,bothInclusive:/^\s*\[.*\]\s*$/,leftInclusive:/^\s*\[.*(\)|\[|\()\s*$/,rightInclusive:/^\s*(\(|\]|\)).*\]\s*$/},t.prototype.test=function(t,e){var s=this.parseNumbersFromInterval(e);return this.isSetOfNumbers(e)?-1!=s.indexOf(t):this.isBothInclusive(e)?t>=s[0]&&t<=s[1]:this.isBothExclusive(e)?t>s[0]&&t<s[1]:this.isRightInclusive(e)?t>s[0]&&t<=s[1]:this.isLeftInclusive(e)?t>=s[0]&&t<s[1]:!1},t.prototype.isSetOfNumbers=function(e){return t.types.setOfNumbers.test(e)},t.prototype.isBothExclusive=function(e){return t.types.bothExclusive.test(e)},t.prototype.isBothInclusive=function(e){return t.types.bothInclusive.test(e)},t.prototype.isLeftInclusive=function(e){return t.types.leftInclusive.test(e)},t.prototype.isRightInclusive=function(e){return t.types.rightInclusive.test(e)},t.prototype.parseNumber=function(t){return t=(t+"").replace(/Inf\s*?$/i,"Infinity"),Number(t)},t.prototype.parseNumbersFromInterval=function(t){var e=/\[|\]|\{|\}|\(|\)|\s*/g,s=t.replace(e,"").split(/,/),i=this;return s.map(function(t){return i.parseNumber(t)})},t});
//# sourceMappingURL=src/interval.min.js.map