@teselagen/range-utils 0.3.6 → 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,7 +1,7 @@
1
1
  import getOverlapsOfPotentiallyCircularRanges from "./getOverlapsOfPotentiallyCircularRanges";
2
2
  import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
3
3
  import trimNonCicularRangeByAnotherNonCircularRange from "./trimNonCicularRangeByAnotherNonCircularRange";
4
- import {extend} from "lodash";
4
+ import { extend } from "lodash";
5
5
 
6
6
  /**
7
7
  * trims range, but does *not* adjust it
@@ -31,7 +31,7 @@ export default function trimRangeByAnotherRange(
31
31
  rangeToBeTrimmed.start,
32
32
  rangeToBeTrimmed.end,
33
33
  trimmingRange.start,
34
- trimmingRange.end,
34
+ trimmingRange.end
35
35
  ]) {
36
36
  if (position < 0 || (!position && position !== 0)) {
37
37
  console.warn("invalid range input");
@@ -54,26 +54,27 @@ export default function trimRangeByAnotherRange(
54
54
  rangeToBeTrimmed,
55
55
  sequenceLength
56
56
  );
57
- splitRangesToBeTrimmed.forEach(function(nonCircularRangeToBeTrimmed, index) {
58
- overlaps.forEach(function(overlap) {
57
+ splitRangesToBeTrimmed.forEach(function (nonCircularRangeToBeTrimmed, index) {
58
+ overlaps.forEach(function (overlap) {
59
59
  if (nonCircularRangeToBeTrimmed) {
60
- nonCircularRangeToBeTrimmed = trimNonCicularRangeByAnotherNonCircularRange(
61
- nonCircularRangeToBeTrimmed,
62
- overlap
63
- );
60
+ nonCircularRangeToBeTrimmed =
61
+ trimNonCicularRangeByAnotherNonCircularRange(
62
+ nonCircularRangeToBeTrimmed,
63
+ overlap
64
+ );
64
65
  }
65
66
  });
66
67
  splitRangesToBeTrimmed[index] = nonCircularRangeToBeTrimmed;
67
68
  });
68
69
  //filter out any of the split ranges that have been fully deleted!
69
- const outputSplitRanges = splitRangesToBeTrimmed.filter(function(
70
- trimmedRange
71
- ) {
72
- if (trimmedRange) {
73
- return true;
70
+ const outputSplitRanges = splitRangesToBeTrimmed.filter(
71
+ function (trimmedRange) {
72
+ if (trimmedRange) {
73
+ return true;
74
+ }
75
+ return false;
74
76
  }
75
- return false;
76
- });
77
+ );
77
78
 
78
79
  let outputTrimmedRange;
79
80
  if (outputSplitRanges.length < 0) {
@@ -84,19 +85,19 @@ export default function trimRangeByAnotherRange(
84
85
  if (outputSplitRanges[0].start < outputSplitRanges[1].start) {
85
86
  outputTrimmedRange = {
86
87
  start: outputSplitRanges[1].start,
87
- end: outputSplitRanges[0].end,
88
+ end: outputSplitRanges[0].end
88
89
  };
89
90
  } else {
90
91
  outputTrimmedRange = {
91
92
  start: outputSplitRanges[0].start,
92
- end: outputSplitRanges[1].end,
93
+ end: outputSplitRanges[1].end
93
94
  };
94
95
  }
95
96
  }
96
97
  if (outputTrimmedRange) {
97
98
  return extend({}, rangeToBeTrimmed, {
98
99
  start: outputTrimmedRange.start,
99
- end: outputTrimmedRange.end,
100
+ end: outputTrimmedRange.end
100
101
  });
101
102
  }
102
- };
103
+ }
@@ -1,7 +1,7 @@
1
1
  import trimRangeByAnotherRange from "./trimRangeByAnotherRange.js";
2
2
  import assert from "assert";
3
3
 
4
- describe("trimRangeByAnotherRange", function() {
4
+ describe("trimRangeByAnotherRange", function () {
5
5
  it(`returns nothing if invalid inputs are sent in`, () => {
6
6
  assert.equal(
7
7
  null,
@@ -15,7 +15,7 @@ describe("trimRangeByAnotherRange", function() {
15
15
  )
16
16
  );
17
17
  });
18
- it("trims non circular ranges that dont fully overlap", function() {
18
+ it("trims non circular ranges that dont fully overlap", function () {
19
19
  assert.deepEqual(
20
20
  trimRangeByAnotherRange(
21
21
  {
@@ -36,7 +36,7 @@ describe("trimRangeByAnotherRange", function() {
36
36
  }
37
37
  );
38
38
  });
39
- it("it does not trim non circular ranges with overlap contained within it", function() {
39
+ it("it does not trim non circular ranges with overlap contained within it", function () {
40
40
  assert.deepEqual(
41
41
  trimRangeByAnotherRange(
42
42
  {
@@ -57,7 +57,7 @@ describe("trimRangeByAnotherRange", function() {
57
57
  }
58
58
  );
59
59
  });
60
- it("trims non circular ranges that fully overlap", function() {
60
+ it("trims non circular ranges that fully overlap", function () {
61
61
  assert.deepEqual(
62
62
  trimRangeByAnotherRange(
63
63
  {
@@ -115,7 +115,7 @@ describe("trimRangeByAnotherRange", function() {
115
115
  undefined
116
116
  );
117
117
  });
118
- it("does not trim non circular ranges that dont overlap", function() {
118
+ it("does not trim non circular ranges that dont overlap", function () {
119
119
  assert.deepEqual(
120
120
  trimRangeByAnotherRange(
121
121
  {
@@ -153,7 +153,7 @@ describe("trimRangeByAnotherRange", function() {
153
153
  }
154
154
  );
155
155
  });
156
- it("does trim circular ranges that overlap", function() {
156
+ it("does trim circular ranges that overlap", function () {
157
157
  assert.deepEqual(
158
158
  trimRangeByAnotherRange(
159
159
  {
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // ac.throw([ac.posInt, ac.posInt, ac.bool], arguments);
3
- import trimRangeByAnotherRange from './trimRangeByAnotherRange';
3
+ import trimRangeByAnotherRange from "./trimRangeByAnotherRange";
4
4
 
5
5
  /**
6
6
  * "zeroes" a subrange of a container range by
@@ -16,21 +16,31 @@ import trimRangeByAnotherRange from './trimRangeByAnotherRange';
16
16
  * end:
17
17
  * }
18
18
  */
19
- export default function zeroSubrangeByContainerRange(subRange, containerRange, sequenceLength) {
20
- // ac.throw([ac.range, ac.range, ac.posInt], arguments);
21
- //first check to make sure the container range fully contains the subRange
22
- const trimmedSubRange = trimRangeByAnotherRange(subRange, containerRange, sequenceLength);
23
- if (trimmedSubRange) {
24
- throw new Error('subRange must be fully contained by containerRange! Otherwise this function does not make sense');
25
- }
26
- const newSubrange = {};
27
- newSubrange.start = subRange.start - containerRange.start;
28
- newSubrange.end = subRange.end - containerRange.start;
29
- if (newSubrange.start < 0) {
30
- newSubrange.start += sequenceLength;
31
- }
32
- if (newSubrange.end < 0) {
33
- newSubrange.end += sequenceLength;
34
- }
35
- return newSubrange;
36
- };
19
+ export default function zeroSubrangeByContainerRange(
20
+ subRange,
21
+ containerRange,
22
+ sequenceLength
23
+ ) {
24
+ // ac.throw([ac.range, ac.range, ac.posInt], arguments);
25
+ //first check to make sure the container range fully contains the subRange
26
+ const trimmedSubRange = trimRangeByAnotherRange(
27
+ subRange,
28
+ containerRange,
29
+ sequenceLength
30
+ );
31
+ if (trimmedSubRange) {
32
+ throw new Error(
33
+ "subRange must be fully contained by containerRange! Otherwise this function does not make sense"
34
+ );
35
+ }
36
+ const newSubrange = {};
37
+ newSubrange.start = subRange.start - containerRange.start;
38
+ newSubrange.end = subRange.end - containerRange.start;
39
+ if (newSubrange.start < 0) {
40
+ newSubrange.start += sequenceLength;
41
+ }
42
+ if (newSubrange.end < 0) {
43
+ newSubrange.end += sequenceLength;
44
+ }
45
+ return newSubrange;
46
+ }
@@ -1,51 +1,61 @@
1
+ import { expect } from "chai";
1
2
 
3
+ import zeroSubrangeByContainerRange from "./zeroSubrangeByContainerRange.js";
4
+ describe("zeroSubrangeByContainerRange", function () {
5
+ it("throws an error if circular subRange does not fit within container range", function () {
6
+ let error = false;
7
+ try {
8
+ zeroSubrangeByContainerRange(
9
+ {
10
+ start: 20,
11
+ end: 10
12
+ },
13
+ {
14
+ start: 10,
15
+ end: 20
16
+ },
17
+ 30
18
+ );
19
+ } catch (e) {
20
+ error = true;
21
+ }
22
+ expect(error).to.be.true;
23
+ });
24
+ it("throws an error if non circular subRange does not fit within container range", function () {
25
+ let error = false;
26
+ try {
27
+ zeroSubrangeByContainerRange(
28
+ {
29
+ start: 9,
30
+ end: 20
31
+ },
32
+ {
33
+ start: 10,
34
+ end: 20
35
+ },
36
+ 30
37
+ );
38
+ } catch (e) {
39
+ error = true;
40
+ }
41
+ expect(error).to.be.true;
42
+ });
43
+ it("zeros non circular range if fully overlapped", function () {
44
+ const zeroedSubrange = zeroSubrangeByContainerRange(
45
+ {
46
+ start: 10,
47
+ end: 20
48
+ },
49
+ {
50
+ start: 10,
51
+ end: 20
52
+ },
53
+ 30
54
+ );
2
55
 
3
- import {expect} from 'chai';
4
-
5
- import zeroSubrangeByContainerRange from './zeroSubrangeByContainerRange.js';
6
- describe('zeroSubrangeByContainerRange', function() {
7
- it('throws an error if circular subRange does not fit within container range', function() {
8
- let error = false;
9
- try {
10
- zeroSubrangeByContainerRange({
11
- start: 20,
12
- end: 10
13
- }, {
14
- start: 10,
15
- end: 20
16
- }, 30);
17
- } catch (e) {
18
- error = true;
19
- }
20
- expect(error).to.be.true;
21
- });
22
- it('throws an error if non circular subRange does not fit within container range', function() {
23
- let error = false;
24
- try {
25
- zeroSubrangeByContainerRange({
26
- start: 9,
27
- end: 20
28
- }, {
29
- start: 10,
30
- end: 20
31
- }, 30);
32
- } catch (e) {
33
- error = true;
34
- }
35
- expect(error).to.be.true;
36
- });
37
- it('zeros non circular range if fully overlapped', function() {
38
- const zeroedSubrange = zeroSubrangeByContainerRange({
39
- start: 10,
40
- end: 20
41
- }, {
42
- start: 10,
43
- end: 20
44
- }, 30);
45
-
46
- expect(zeroedSubrange).to.deep.equal({
47
- start: 0,
48
- end: 10
49
- });
56
+ expect(zeroedSubrange).to.deep.equal({
57
+ start: 0,
58
+ end: 10
50
59
  });
60
+ });
51
61
  });