@teselagen/range-utils 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +94 -0
  2. package/flipContainedRange.d.ts +1 -1
  3. package/index.js +233 -85
  4. package/index.mjs +233 -85
  5. package/index.umd.js +233 -85
  6. package/package.json +1 -2
  7. package/src/adjustRangeToDeletionOfAnotherRange.test.js +166 -105
  8. package/src/adjustRangeToInsert.js +29 -26
  9. package/src/adjustRangeToInsert.test.js +197 -109
  10. package/src/adjustRangeToRotation.js +4 -5
  11. package/src/adjustRangeToRotation.test.js +203 -119
  12. package/src/checkIfNonCircularRangesOverlap.js +18 -15
  13. package/src/checkIfNonCircularRangesOverlap.test.js +67 -42
  14. package/src/checkIfPotentiallyCircularRangesOverlap.js +22 -12
  15. package/src/checkIfPotentiallyCircularRangesOverlap.test.js +115 -70
  16. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.js +72 -41
  17. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.js +183 -84
  18. package/src/convertRangeIndices.js +24 -20
  19. package/src/convertRangeIndices.test.js +40 -21
  20. package/src/convertRangeTo0Based.js +7 -4
  21. package/src/convertRangeTo1Based.js +8 -4
  22. package/src/doesRangeSpanEntireSequence.js +4 -4
  23. package/src/doesRangeSpanOrigin.js +3 -3
  24. package/src/expandOrContractCircularRangeToPosition.js +45 -38
  25. package/src/expandOrContractNonCircularRangeToPosition.js +24 -21
  26. package/src/expandOrContractRangeByLength.js +16 -11
  27. package/src/expandOrContractRangeByLength.test.js +109 -71
  28. package/src/expandOrContractRangeToPosition.js +17 -9
  29. package/src/flipContainedRange.js +133 -72
  30. package/src/flipContainedRange.test.js +143 -117
  31. package/src/generateRandomRange.js +17 -15
  32. package/src/generateRandomRange.test.js +21 -21
  33. package/src/getAnnotationRangeType.js +25 -21
  34. package/src/getAnnotationRangeType.test.js +56 -57
  35. package/src/getEachPositionInRangeAsArray.js +13 -13
  36. package/src/getEachPositionInRangeAsArray.test.js +12 -8
  37. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.js +16 -8
  38. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.test.js +32 -24
  39. package/src/getMiddleOfRange.js +1 -1
  40. package/src/getMiddleOfRange.test.js +5 -13
  41. package/src/getOverlapOfNonCircularRanges.js +30 -30
  42. package/src/getOverlapsOfPotentiallyCircularRanges.js +5 -5
  43. package/src/getOverlapsOfPotentiallyCircularRanges.test.js +3 -23
  44. package/src/getPositionFromAngle.js +12 -7
  45. package/src/getRangeAngles.js +1 -1
  46. package/src/getRangeAngles.test.js +10 -11
  47. package/src/getRangeLength.test.js +5 -5
  48. package/src/getRangesBetweenTwoRanges.js +31 -22
  49. package/src/getSequenceWithinRange.js +13 -13
  50. package/src/getSequenceWithinRange.test.js +43 -45
  51. package/src/getShortestDistanceBetweenTwoPositions.js +10 -6
  52. package/src/getShortestDistanceBetweenTwoPositions.test.js +11 -13
  53. package/src/getYOffsetForPotentiallyCircularRange.js +33 -21
  54. package/src/getYOffsetsForPotentiallyCircularRanges.js +26 -19
  55. package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -29
  56. package/src/getZeroedRangeOverlaps.js +30 -15
  57. package/src/getZeroedRangeOverlaps.test.js +75 -36
  58. package/src/index.js +51 -51
  59. package/src/index.test.js +6 -8
  60. package/src/invertRange.test.js +103 -93
  61. package/src/isPositionCloserToRangeStartThanRangeEnd.js +18 -6
  62. package/src/isPositionCloserToRangeStartThanRangeEnd.test.js +36 -16
  63. package/src/isPositionWithinRange.js +4 -4
  64. package/src/isRangeOrPositionWithinRange.js +18 -12
  65. package/src/isRangeOrPositionWithinRange.test.js +6 -6
  66. package/src/isRangeWithinRange.js +2 -3
  67. package/src/loopEachPositionInRange.js +3 -3
  68. package/src/modulatePositionByRange.js +8 -8
  69. package/src/modulatePositionByRange.test.js +10 -11
  70. package/src/modulateRangeBySequenceLength.js +7 -7
  71. package/src/modulateRangeBySequenceLength.test.js +39 -16
  72. package/src/normalizePositionByRangeLength.js +22 -18
  73. package/src/normalizePositionByRangeLength.test.js +23 -23
  74. package/src/normalizePositionByRangeLength1Based.js +7 -4
  75. package/src/normalizePositionByRangeLength1Based.test.js +9 -9
  76. package/src/normalizeRange.js +7 -7
  77. package/src/normalizeRange.test.js +9 -9
  78. package/src/provideInclusiveOptions.js +36 -23
  79. package/src/reversePositionInRange.js +16 -12
  80. package/src/splitRangeIntoTwoPartsIfItIsCircular.js +31 -28
  81. package/src/splitRangeIntoTwoPartsIfItIsCircular.test.js +22 -11
  82. package/src/translateRange.js +18 -8
  83. package/src/translateRange.test.js +18 -19
  84. package/src/trimNonCicularRangeByAnotherNonCircularRange.js +45 -42
  85. package/src/trimNumberToFitWithin0ToAnotherNumber.js +13 -10
  86. package/src/trimRangeByAnotherRange.js +20 -19
  87. package/src/trimRangeByAnotherRange.test.js +6 -6
  88. package/src/zeroSubrangeByContainerRange.js +29 -19
  89. package/src/zeroSubrangeByContainerRange.test.js +57 -47
@@ -1,16 +1,39 @@
1
- import {expect} from 'chai';
2
- import modulateRangeBySequenceLength from './modulateRangeBySequenceLength';
3
- describe('modulateRangeBySequenceLength', function() {
4
- it('should modulate ranges that are outside of the sequence length', function() {
5
- //agtc
6
- //0123
7
- expect(modulateRangeBySequenceLength({start: 2, end: 5},4)).to.deep.equal({start: 2, end:1})
8
- expect(modulateRangeBySequenceLength({start: 2, end: 4},4)).to.deep.equal({start: 2, end:0})
9
- //agtc
10
- //12345
11
- expect(modulateRangeBySequenceLength({start: 2, end: 4},4,{inclusive1BasedEnd: true})).to.deep.equal({start: 2, end:4})
12
- expect(modulateRangeBySequenceLength({start: 2, end: 4},4,{inclusive1BasedEnd: true,inclusive1BasedStart: true})).to.deep.equal({start: 2, end:4})
13
- expect(modulateRangeBySequenceLength({start: 5, end: 4},4,{inclusive1BasedEnd: true,inclusive1BasedStart: true})).to.deep.equal({start: 1, end:4})
14
- expect(modulateRangeBySequenceLength({start: 5, end: 5},4,{inclusive1BasedEnd: true,inclusive1BasedStart: true})).to.deep.equal({start: 1, end:1})
15
- })
16
- })
1
+ import { expect } from "chai";
2
+ import modulateRangeBySequenceLength from "./modulateRangeBySequenceLength";
3
+ describe("modulateRangeBySequenceLength", function () {
4
+ it("should modulate ranges that are outside of the sequence length", function () {
5
+ //agtc
6
+ //0123
7
+ expect(
8
+ modulateRangeBySequenceLength({ start: 2, end: 5 }, 4)
9
+ ).to.deep.equal({ start: 2, end: 1 });
10
+ expect(
11
+ modulateRangeBySequenceLength({ start: 2, end: 4 }, 4)
12
+ ).to.deep.equal({ start: 2, end: 0 });
13
+ //agtc
14
+ //12345
15
+ expect(
16
+ modulateRangeBySequenceLength({ start: 2, end: 4 }, 4, {
17
+ inclusive1BasedEnd: true
18
+ })
19
+ ).to.deep.equal({ start: 2, end: 4 });
20
+ expect(
21
+ modulateRangeBySequenceLength({ start: 2, end: 4 }, 4, {
22
+ inclusive1BasedEnd: true,
23
+ inclusive1BasedStart: true
24
+ })
25
+ ).to.deep.equal({ start: 2, end: 4 });
26
+ expect(
27
+ modulateRangeBySequenceLength({ start: 5, end: 4 }, 4, {
28
+ inclusive1BasedEnd: true,
29
+ inclusive1BasedStart: true
30
+ })
31
+ ).to.deep.equal({ start: 1, end: 4 });
32
+ expect(
33
+ modulateRangeBySequenceLength({ start: 5, end: 5 }, 4, {
34
+ inclusive1BasedEnd: true,
35
+ inclusive1BasedStart: true
36
+ })
37
+ ).to.deep.equal({ start: 1, end: 1 });
38
+ });
39
+ });
@@ -1,20 +1,24 @@
1
1
  //
2
2
  // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
- export default function normalizePositionByRangeLength(pPosition, sequenceLength, isInBetweenPositions) {
4
- //isInBetweenPositions refers to:
5
- // A T G C
6
- // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
7
- //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
8
- // ac.throw([ac.number, ac.posInt, ac.bool], arguments);
9
- let position = pPosition;
10
- if (position < 0) {
11
- position += sequenceLength;
12
- } else if (position + (isInBetweenPositions ? 0 : 1) > sequenceLength) {
13
- position -= sequenceLength;
14
- }
15
- return position < 0
16
- ? 0
17
- : position > (sequenceLength - (isInBetweenPositions ? 0 : 1))
18
- ? sequenceLength - (isInBetweenPositions ? 0 : 1)
19
- : position
20
- };
3
+ export default function normalizePositionByRangeLength(
4
+ pPosition,
5
+ sequenceLength,
6
+ isInBetweenPositions
7
+ ) {
8
+ //isInBetweenPositions refers to:
9
+ // A T G C
10
+ // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
11
+ //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
12
+ // ac.throw([ac.number, ac.posInt, ac.bool], arguments);
13
+ let position = pPosition;
14
+ if (position < 0) {
15
+ position += sequenceLength;
16
+ } else if (position + (isInBetweenPositions ? 0 : 1) > sequenceLength) {
17
+ position -= sequenceLength;
18
+ }
19
+ return position < 0
20
+ ? 0
21
+ : position > sequenceLength - (isInBetweenPositions ? 0 : 1)
22
+ ? sequenceLength - (isInBetweenPositions ? 0 : 1)
23
+ : position;
24
+ }
@@ -1,23 +1,23 @@
1
- import {expect} from 'chai';
2
- import normalizePositionByRangeLength from './normalizePositionByRangeLength';
3
- describe('normalizePositionByRangeLength', function() {
4
- it('should normalize positions by their max length, assuming 0-based inclusive indices', function() {
5
- expect(normalizePositionByRangeLength(10,9)).to.equal(1)
6
- expect(normalizePositionByRangeLength(9,9)).to.equal(0)
7
- expect(normalizePositionByRangeLength(3572,2000)).to.equal(1572)
8
- })
9
- it('should set something more than twice outside the sequence length to either 0 or sequenceLength-1', function () {
10
- expect(normalizePositionByRangeLength(-3572,2000)).to.equal(0)
11
- expect(normalizePositionByRangeLength(33572,2000)).to.equal(1999)
12
- })
13
- it('should handle isInBetweenPositions === true being passed in ', function() {
14
- expect(normalizePositionByRangeLength(9,9,true)).to.equal(9)
15
- })
16
- it('should set something more than twice outside the sequence length to either 0 or sequenceLength when isInBetweenPositions is true', function () {
17
- expect(normalizePositionByRangeLength(-3572,2000, true)).to.equal(0)
18
- expect(normalizePositionByRangeLength(33572,2000, true)).to.equal(2000)
19
- })
20
- it('should not do anything if it does not have to', function() {
21
- expect(normalizePositionByRangeLength(10,99)).to.equal(10)
22
- })
23
- })
1
+ import { expect } from "chai";
2
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
3
+ describe("normalizePositionByRangeLength", function () {
4
+ it("should normalize positions by their max length, assuming 0-based inclusive indices", function () {
5
+ expect(normalizePositionByRangeLength(10, 9)).to.equal(1);
6
+ expect(normalizePositionByRangeLength(9, 9)).to.equal(0);
7
+ expect(normalizePositionByRangeLength(3572, 2000)).to.equal(1572);
8
+ });
9
+ it("should set something more than twice outside the sequence length to either 0 or sequenceLength-1", function () {
10
+ expect(normalizePositionByRangeLength(-3572, 2000)).to.equal(0);
11
+ expect(normalizePositionByRangeLength(33572, 2000)).to.equal(1999);
12
+ });
13
+ it("should handle isInBetweenPositions === true being passed in ", function () {
14
+ expect(normalizePositionByRangeLength(9, 9, true)).to.equal(9);
15
+ });
16
+ it("should set something more than twice outside the sequence length to either 0 or sequenceLength when isInBetweenPositions is true", function () {
17
+ expect(normalizePositionByRangeLength(-3572, 2000, true)).to.equal(0);
18
+ expect(normalizePositionByRangeLength(33572, 2000, true)).to.equal(2000);
19
+ });
20
+ it("should not do anything if it does not have to", function () {
21
+ expect(normalizePositionByRangeLength(10, 99)).to.equal(10);
22
+ });
23
+ });
@@ -1,5 +1,8 @@
1
- import modulatePositionByRange from './modulatePositionByRange';
1
+ import modulatePositionByRange from "./modulatePositionByRange";
2
2
 
3
- export default function normalizePositionByRangeLength1Based (position, sequenceLength) {
4
- return modulatePositionByRange(position, {start: 1, end: sequenceLength})
5
- };
3
+ export default function normalizePositionByRangeLength1Based(
4
+ position,
5
+ sequenceLength
6
+ ) {
7
+ return modulatePositionByRange(position, { start: 1, end: sequenceLength });
8
+ }
@@ -1,9 +1,9 @@
1
- import normalizePositionByRangeLength1Based from './normalizePositionByRangeLength1Based';
2
- import {expect} from 'chai';
3
- describe('normalizePositionByRangeLength1Based', function () {
4
- it('should normalize a 1 based position by a 1 based range length', function() {
5
- expect(normalizePositionByRangeLength1Based(0,10)).to.equal(10)
6
- expect(normalizePositionByRangeLength1Based(-1,10)).to.equal(9)
7
- expect(normalizePositionByRangeLength1Based(11,10)).to.equal(1)
8
- })
9
- });
1
+ import normalizePositionByRangeLength1Based from "./normalizePositionByRangeLength1Based";
2
+ import { expect } from "chai";
3
+ describe("normalizePositionByRangeLength1Based", function () {
4
+ it("should normalize a 1 based position by a 1 based range length", function () {
5
+ expect(normalizePositionByRangeLength1Based(0, 10)).to.equal(10);
6
+ expect(normalizePositionByRangeLength1Based(-1, 10)).to.equal(9);
7
+ expect(normalizePositionByRangeLength1Based(11, 10)).to.equal(1);
8
+ });
9
+ });
@@ -1,11 +1,11 @@
1
1
  //normalize range takes in a range that might be slightly outside of the rangeMax and wraps the start/end as necessary to fit
2
- import {assign} from "lodash";
2
+ import { assign } from "lodash";
3
3
 
4
- import normalizePositionByRangeLength from './normalizePositionByRangeLength';
4
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
5
5
 
6
6
  export default function normalizeRange(range, sequenceLength) {
7
- return assign({}, range, {
8
- start: normalizePositionByRangeLength(range.start, sequenceLength),
9
- end: normalizePositionByRangeLength(range.end, sequenceLength),
10
- })
11
- };
7
+ return assign({}, range, {
8
+ start: normalizePositionByRangeLength(range.start, sequenceLength),
9
+ end: normalizePositionByRangeLength(range.end, sequenceLength)
10
+ });
11
+ }
@@ -1,9 +1,9 @@
1
- import normalizeRange from './normalizeRange';
2
- import {expect} from 'chai';
3
- describe('normalizeRange', function () {
4
- it('should normalize range correctly', function() {
5
- const normalizedRange = normalizeRange({start: 0, end: -1},10)
6
- expect(normalizedRange.start).to.equal(0)
7
- expect(normalizedRange.end).to.equal(9)
8
- })
9
- });
1
+ import normalizeRange from "./normalizeRange";
2
+ import { expect } from "chai";
3
+ describe("normalizeRange", function () {
4
+ it("should normalize range correctly", function () {
5
+ const normalizedRange = normalizeRange({ start: 0, end: -1 }, 10);
6
+ expect(normalizedRange.start).to.equal(0);
7
+ expect(normalizedRange.end).to.equal(9);
8
+ });
9
+ });
@@ -1,26 +1,39 @@
1
- import {assign} from "lodash";
1
+ import { assign } from "lodash";
2
2
 
3
- export default function provideInclusiveOptions (funToWrap) {
4
- return function () {
5
- const args = Array.prototype.slice.call(arguments);
6
- const options = args[args.length-1];
7
- if (options && (options.inclusive1BasedEnd || options.inclusive1BasedStart)) {
8
- args.forEach(function (arg,index) {
9
- if (arg && arg.start > -1 && options.inclusive1BasedStart) {
10
- args[index] = assign(arg, {start: arg.start-1})
11
- }
12
- if (arg && arg.end > -1 && options.inclusive1BasedEnd) {
13
- args[index] = assign(arg, {end: arg.end-1})
14
- }
15
- })
3
+ export default function provideInclusiveOptions(funToWrap) {
4
+ return function () {
5
+ const args = Array.prototype.slice.call(arguments);
6
+ const options = args[args.length - 1];
7
+ if (
8
+ options &&
9
+ (options.inclusive1BasedEnd || options.inclusive1BasedStart)
10
+ ) {
11
+ args.forEach(function (arg, index) {
12
+ if (arg && arg.start > -1 && options.inclusive1BasedStart) {
13
+ args[index] = assign(arg, { start: arg.start - 1 });
16
14
  }
17
- let returnVal = funToWrap.apply(this,args);
18
- if (returnVal && returnVal.start > -1 && options && options.inclusive1BasedStart) {
19
- returnVal = assign(returnVal, {start: returnVal.start+1})
15
+ if (arg && arg.end > -1 && options.inclusive1BasedEnd) {
16
+ args[index] = assign(arg, { end: arg.end - 1 });
20
17
  }
21
- if (returnVal && returnVal.end > -1 && options && options.inclusive1BasedEnd) {
22
- returnVal = assign(returnVal, {end: returnVal.end+1})
23
- }
24
- return returnVal
25
- };
26
- };
18
+ });
19
+ }
20
+ let returnVal = funToWrap.apply(this, args);
21
+ if (
22
+ returnVal &&
23
+ returnVal.start > -1 &&
24
+ options &&
25
+ options.inclusive1BasedStart
26
+ ) {
27
+ returnVal = assign(returnVal, { start: returnVal.start + 1 });
28
+ }
29
+ if (
30
+ returnVal &&
31
+ returnVal.end > -1 &&
32
+ options &&
33
+ options.inclusive1BasedEnd
34
+ ) {
35
+ returnVal = assign(returnVal, { end: returnVal.end + 1 });
36
+ }
37
+ return returnVal;
38
+ };
39
+ }
@@ -1,13 +1,17 @@
1
1
  //
2
- export default function reversePositionInRange(position, rangeLength, isInBetweenPositions) {
3
- //isInBetweenPositions refers to:
4
- // A T G C
5
- // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
6
- //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
7
- // ac.throw([
8
- // ac.posInt,
9
- // ac.posInt,
10
- // ac.bool
11
- // ], arguments);
12
- return rangeLength - position - (isInBetweenPositions ? 0 : 1);
13
- };
2
+ export default function reversePositionInRange(
3
+ position,
4
+ rangeLength,
5
+ isInBetweenPositions
6
+ ) {
7
+ //isInBetweenPositions refers to:
8
+ // A T G C
9
+ // 0 1 2 3 <-- isInBetweenPositions = false is counting the positions themselves
10
+ //0 1 2 3 4 <-- isInBetweenPositions = true is counting the spaces between positions
11
+ // ac.throw([
12
+ // ac.posInt,
13
+ // ac.posInt,
14
+ // ac.bool
15
+ // ], arguments);
16
+ return rangeLength - position - (isInBetweenPositions ? 0 : 1);
17
+ }
@@ -1,31 +1,34 @@
1
1
  //
2
2
  // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
3
  //takes a potentially circular range and returns an array containing the range split on the origin
4
- export default function splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength) {
5
- // ac.throw([ac.range, ac.number], arguments);
6
- if (sequenceLength !== 0) {
7
- sequenceLength = sequenceLength || Infinity
8
- }
9
- const ranges = [];
10
- if (range.start > range.end) {
11
- //the range is cicular, so we return an array of two ranges
12
- ranges.push({
13
- start: 0,
14
- end: range.end,
15
- type: "end",
16
- });
17
- ranges.push({
18
- start: range.start,
19
- end: sequenceLength - 1,
20
- type: "beginning",
21
- });
22
- } else {
23
- //the range isn't circular, so we just return the range
24
- ranges.push({
25
- start: range.start,
26
- end: range.end,
27
- type: "beginningAndEnd",
28
- });
29
- }
30
- return ranges;
31
- };
4
+ export default function splitRangeIntoTwoPartsIfItIsCircular(
5
+ range,
6
+ sequenceLength
7
+ ) {
8
+ // ac.throw([ac.range, ac.number], arguments);
9
+ if (sequenceLength !== 0) {
10
+ sequenceLength = sequenceLength || Infinity;
11
+ }
12
+ const ranges = [];
13
+ if (range.start > range.end) {
14
+ //the range is cicular, so we return an array of two ranges
15
+ ranges.push({
16
+ start: 0,
17
+ end: range.end,
18
+ type: "end"
19
+ });
20
+ ranges.push({
21
+ start: range.start,
22
+ end: sequenceLength - 1,
23
+ type: "beginning"
24
+ });
25
+ } else {
26
+ //the range isn't circular, so we just return the range
27
+ ranges.push({
28
+ start: range.start,
29
+ end: range.end,
30
+ type: "beginningAndEnd"
31
+ });
32
+ }
33
+ return ranges;
34
+ }
@@ -18,16 +18,27 @@
18
18
  // }
19
19
  // };
20
20
 
21
+ import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular.js";
21
22
 
22
- import splitRangeIntoTwoPartsIfItIsCircular from './splitRangeIntoTwoPartsIfItIsCircular.js';
23
-
24
- import assert from 'assert';
25
- describe('splitRangeIntoTwoPartsIfItIsCircular', function() {
26
- it('returns an array with one range in it if the array is non-circular', function() {
27
- assert.deepEqual(splitRangeIntoTwoPartsIfItIsCircular({start: 0, end: 100}, 1000), [{start: 0, end: 100, type: 'beginningAndEnd'}]);
28
- assert.deepEqual(splitRangeIntoTwoPartsIfItIsCircular({start: 10, end: 909}, 1000), [{start: 10, end: 909, type: 'beginningAndEnd'}]);
29
- });
30
- it('returns an array with two ranges in it if the array is circular', function() {
31
- assert.deepEqual(splitRangeIntoTwoPartsIfItIsCircular({start: 110, end: 100},1000), [{start: 0, end: 100, type: 'end'},{start: 110, end: 999, type: 'beginning'}]);
32
- });
23
+ import assert from "assert";
24
+ describe("splitRangeIntoTwoPartsIfItIsCircular", function () {
25
+ it("returns an array with one range in it if the array is non-circular", function () {
26
+ assert.deepEqual(
27
+ splitRangeIntoTwoPartsIfItIsCircular({ start: 0, end: 100 }, 1000),
28
+ [{ start: 0, end: 100, type: "beginningAndEnd" }]
29
+ );
30
+ assert.deepEqual(
31
+ splitRangeIntoTwoPartsIfItIsCircular({ start: 10, end: 909 }, 1000),
32
+ [{ start: 10, end: 909, type: "beginningAndEnd" }]
33
+ );
34
+ });
35
+ it("returns an array with two ranges in it if the array is circular", function () {
36
+ assert.deepEqual(
37
+ splitRangeIntoTwoPartsIfItIsCircular({ start: 110, end: 100 }, 1000),
38
+ [
39
+ { start: 0, end: 100, type: "end" },
40
+ { start: 110, end: 999, type: "beginning" }
41
+ ]
42
+ );
43
+ });
33
44
  });
@@ -1,9 +1,19 @@
1
- import {assign} from "lodash";
2
- import normalizePositionByRangeLength from './normalizePositionByRangeLength';
1
+ import { assign } from "lodash";
2
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
3
3
 
4
- export default function translateRange(rangeToBeAdjusted, translateBy, rangeLength) {
5
- return assign({}, rangeToBeAdjusted, {
6
- start: normalizePositionByRangeLength(rangeToBeAdjusted.start + translateBy, rangeLength),
7
- end: normalizePositionByRangeLength(rangeToBeAdjusted.end + translateBy, rangeLength)
8
- });
9
- };
4
+ export default function translateRange(
5
+ rangeToBeAdjusted,
6
+ translateBy,
7
+ rangeLength
8
+ ) {
9
+ return assign({}, rangeToBeAdjusted, {
10
+ start: normalizePositionByRangeLength(
11
+ rangeToBeAdjusted.start + translateBy,
12
+ rangeLength
13
+ ),
14
+ end: normalizePositionByRangeLength(
15
+ rangeToBeAdjusted.end + translateBy,
16
+ rangeLength
17
+ )
18
+ });
19
+ }
@@ -1,20 +1,19 @@
1
- import translateRange from './translateRange';
2
- import {expect} from 'chai';
1
+ import translateRange from "./translateRange";
2
+ import { expect } from "chai";
3
3
 
4
- describe('translateRange', function() {
5
- it('should correctly translate a range', function() {
6
- expect(translateRange({start: 0, end: 10}, 10, 30)).to.deep.equal({
7
- start: 10,
8
- end: 20,
9
- })
10
- expect(translateRange({start: 0, end: 10}, 10, 15)).to.deep.equal({
11
- start: 10,
12
- end: 5,
13
- })
14
- expect(translateRange({start: 9, end: 10}, 10, 15)).to.deep.equal({
15
- start: 4,
16
- end: 5,
17
- })
18
-
19
- })
20
- })
4
+ describe("translateRange", function () {
5
+ it("should correctly translate a range", function () {
6
+ expect(translateRange({ start: 0, end: 10 }, 10, 30)).to.deep.equal({
7
+ start: 10,
8
+ end: 20
9
+ });
10
+ expect(translateRange({ start: 0, end: 10 }, 10, 15)).to.deep.equal({
11
+ start: 10,
12
+ end: 5
13
+ });
14
+ expect(translateRange({ start: 9, end: 10 }, 10, 15)).to.deep.equal({
15
+ start: 4,
16
+ end: 5
17
+ });
18
+ });
19
+ });
@@ -1,57 +1,60 @@
1
1
  //
2
- export default function trimNonCicularRangeByAnotherNonCircularRange(rangeToBeTrimmed, trimmingRange) {
3
- // ac.throw([ac.range, ac.range], arguments);
4
- let outputTrimmedRange;
5
- if (!rangeToBeTrimmed) {
6
- return outputTrimmedRange;
7
- }
8
- if (rangeToBeTrimmed.start < trimmingRange.start) {
9
- if (rangeToBeTrimmed.end < trimmingRange.start) {
2
+ export default function trimNonCicularRangeByAnotherNonCircularRange(
3
+ rangeToBeTrimmed,
4
+ trimmingRange
5
+ ) {
6
+ // ac.throw([ac.range, ac.range], arguments);
7
+ let outputTrimmedRange;
8
+ if (!rangeToBeTrimmed) {
9
+ return outputTrimmedRange;
10
+ }
11
+ if (rangeToBeTrimmed.start < trimmingRange.start) {
12
+ if (rangeToBeTrimmed.end < trimmingRange.start) {
10
13
  // rrr <range to be trimmed
11
14
  // ttt <trimming range
12
- outputTrimmedRange = {
13
- start: rangeToBeTrimmed.start,
14
- end: rangeToBeTrimmed.end
15
- };
16
- } else {
17
- if (rangeToBeTrimmed.end > trimmingRange.end) {
15
+ outputTrimmedRange = {
16
+ start: rangeToBeTrimmed.start,
17
+ end: rangeToBeTrimmed.end
18
+ };
19
+ } else {
20
+ if (rangeToBeTrimmed.end > trimmingRange.end) {
18
21
  // rrrrrr <range to be trimmed
19
22
  // ttt <trimming range
20
- outputTrimmedRange = {
21
- start: rangeToBeTrimmed.start,
22
- end: rangeToBeTrimmed.end
23
- };
24
- } else {
23
+ outputTrimmedRange = {
24
+ start: rangeToBeTrimmed.start,
25
+ end: rangeToBeTrimmed.end
26
+ };
27
+ } else {
25
28
  // rrrrrr <range to be trimmed
26
29
  // ttt <trimming range
27
- outputTrimmedRange = {
28
- start: rangeToBeTrimmed.start,
29
- end: trimmingRange.start - 1
30
- };
31
- }
32
- }
33
- } else {
34
- if (rangeToBeTrimmed.end <= trimmingRange.end) {
30
+ outputTrimmedRange = {
31
+ start: rangeToBeTrimmed.start,
32
+ end: trimmingRange.start - 1
33
+ };
34
+ }
35
+ }
36
+ } else {
37
+ if (rangeToBeTrimmed.end <= trimmingRange.end) {
35
38
  // rrr <range to be trimmed
36
39
  // ttttt <trimming range
37
40
  //fully deleting the range, so do nothing
38
- } else {
39
- if (rangeToBeTrimmed.start > trimmingRange.end) {
41
+ } else {
42
+ if (rangeToBeTrimmed.start > trimmingRange.end) {
40
43
  // rrrrrr <range to be trimmed
41
44
  // ttt <trimming range
42
- outputTrimmedRange = {
43
- end: rangeToBeTrimmed.end,
44
- start: rangeToBeTrimmed.start
45
- };
46
- } else {
45
+ outputTrimmedRange = {
46
+ end: rangeToBeTrimmed.end,
47
+ start: rangeToBeTrimmed.start
48
+ };
49
+ } else {
47
50
  // rrrrrr <range to be trimmed
48
51
  // ttt <trimming range
49
- outputTrimmedRange = {
50
- end: rangeToBeTrimmed.end,
51
- start: trimmingRange.end + 1
52
- };
53
- }
54
- }
52
+ outputTrimmedRange = {
53
+ end: rangeToBeTrimmed.end,
54
+ start: trimmingRange.end + 1
55
+ };
56
+ }
55
57
  }
56
- return outputTrimmedRange;
57
- };
58
+ }
59
+ return outputTrimmedRange;
60
+ }
@@ -1,12 +1,15 @@
1
1
  //
2
2
  // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
- export default function trimNumberToFitWithin0ToAnotherNumber(numberToBeTrimmed, max) {
4
- // ac.throw([ac.number, ac.number], arguments);
5
- if (numberToBeTrimmed < 0) {
6
- numberToBeTrimmed = 0;
7
- }
8
- if (numberToBeTrimmed > max) {
9
- numberToBeTrimmed = max;
10
- }
11
- return numberToBeTrimmed;
12
- };
3
+ export default function trimNumberToFitWithin0ToAnotherNumber(
4
+ numberToBeTrimmed,
5
+ max
6
+ ) {
7
+ // ac.throw([ac.number, ac.number], arguments);
8
+ if (numberToBeTrimmed < 0) {
9
+ numberToBeTrimmed = 0;
10
+ }
11
+ if (numberToBeTrimmed > max) {
12
+ numberToBeTrimmed = max;
13
+ }
14
+ return numberToBeTrimmed;
15
+ }