Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "rangerjs", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A lightweight JS library for defining an array of ranges.", | ||
@@ -19,3 +19,6 @@ "main": "ranger.js", | ||
}, | ||
"homepage": "https://github.com/nigh7sh4de/rangerjs#readme" | ||
"homepage": "https://github.com/nigh7sh4de/rangerjs#readme", | ||
"devDependencies": { | ||
"mongoose": "^4.4.17" | ||
} | ||
} |
@@ -13,2 +13,42 @@ | ||
ranger.prototype = { | ||
removeRecuringRange: function(start, end, interval, count, finish) { | ||
var _start = Number(start), | ||
_end = Number(end), | ||
_finish = Number(finish), | ||
_interval = Number(interval), | ||
type = start.constructor; | ||
if (endBeforeStart(start, end)) | ||
return new Error('Start must be before end for range.'); | ||
if (interval < end - start) | ||
return new Error('Interval must be greater than duration of each range.'); | ||
if ((count == null || count < 0) && finish == null) | ||
return new Error('Recuring range must specify total count or limit.'); | ||
count = count < 1 || !count ? parseInt((_finish - _start) / _interval) : count; | ||
if (count <= 0) | ||
return new Error('Recuring interval must be greater than 0.'); | ||
for (var i=0; i < count; i++) | ||
this.removeRange(new type(_start + i*_interval), | ||
new type(_end + i*_interval)); | ||
}, | ||
addRecuringRange: function(start, end, interval, count, finish) { | ||
var _start = Number(start), | ||
_end = Number(end), | ||
_finish = Number(finish), | ||
_interval = Number(interval), | ||
type = start.constructor; | ||
if (endBeforeStart(start, end)) | ||
return new Error('Start must be before end for range.'); | ||
if (interval < end - start) | ||
return new Error('Interval must be greater than duration of each range.'); | ||
if ((count == null || count < 0) && finish == null) | ||
return new Error('Recuring range must specify total count or limit.'); | ||
count = count < 1 || !count ? parseInt((_finish - _start) / _interval) : count; | ||
if (count <= 0) | ||
return new Error('Recuring interval must be greater than 0.'); | ||
for (var i=0; i < count; i++) | ||
this.addRange(new type(_start + i*_interval), | ||
new type(_end + i*_interval)); | ||
}, | ||
addRange: function(start, end) { | ||
@@ -80,3 +120,3 @@ if (endBeforeStart(start, end)) | ||
if (this.ranges[i+1] >= start) { | ||
if (this.ranges[i] > end) | ||
if (this.ranges[i] >= end) | ||
return; | ||
@@ -89,3 +129,3 @@ else if (this.ranges[i] < start && | ||
else if (this.ranges[i] >= start && | ||
this.ranges[i+1] < end) { | ||
this.ranges[i+1] <= end) { | ||
this.ranges.splice(i, 2); | ||
@@ -95,3 +135,3 @@ i -= 2; | ||
else if (this.ranges[i] < start && | ||
this.ranges[i+1] < end) { | ||
this.ranges[i+1] <= end) { | ||
this.ranges[i+1] = start; | ||
@@ -98,0 +138,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7849
176
1