@teselagen/range-utils 0.3.7 → 0.3.9

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 (96) hide show
  1. package/README.md +94 -0
  2. package/flipContainedRange.d.ts +1 -1
  3. package/index.cjs +2619 -0
  4. package/index.d.ts +52 -51
  5. package/index.js +1791 -6100
  6. package/index.umd.cjs +2623 -0
  7. package/package.json +2 -3
  8. package/src/adjustRangeToDeletionOfAnotherRange.test.js +166 -105
  9. package/src/adjustRangeToInsert.js +29 -26
  10. package/src/adjustRangeToInsert.test.js +197 -109
  11. package/src/adjustRangeToRotation.js +4 -5
  12. package/src/adjustRangeToRotation.test.js +203 -119
  13. package/src/checkIfNonCircularRangesOverlap.js +18 -15
  14. package/src/checkIfNonCircularRangesOverlap.test.js +67 -42
  15. package/src/checkIfPotentiallyCircularRangesOverlap.js +22 -12
  16. package/src/checkIfPotentiallyCircularRangesOverlap.test.js +115 -70
  17. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.js +72 -41
  18. package/src/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.js +183 -84
  19. package/src/convertRangeIndices.js +24 -20
  20. package/src/convertRangeIndices.test.js +40 -21
  21. package/src/convertRangeTo0Based.js +7 -4
  22. package/src/convertRangeTo1Based.js +8 -4
  23. package/src/doesRangeSpanEntireSequence.js +4 -4
  24. package/src/doesRangeSpanOrigin.js +3 -3
  25. package/src/expandOrContractCircularRangeToPosition.js +45 -38
  26. package/src/expandOrContractNonCircularRangeToPosition.js +24 -21
  27. package/src/expandOrContractRangeByLength.js +16 -11
  28. package/src/expandOrContractRangeByLength.test.js +109 -71
  29. package/src/expandOrContractRangeToPosition.js +17 -9
  30. package/src/flipContainedRange.js +133 -72
  31. package/src/flipContainedRange.test.js +143 -117
  32. package/src/generateRandomRange.js +17 -15
  33. package/src/generateRandomRange.test.js +21 -21
  34. package/src/getAnnotationRangeType.js +25 -21
  35. package/src/getAnnotationRangeType.test.js +56 -57
  36. package/src/getEachPositionInRangeAsArray.js +13 -13
  37. package/src/getEachPositionInRangeAsArray.test.js +12 -8
  38. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.js +16 -8
  39. package/src/getLengthOfOverlappingRegionsBetweenTwoRanges.test.js +32 -24
  40. package/src/getMiddleOfRange.js +1 -1
  41. package/src/getMiddleOfRange.test.js +5 -13
  42. package/src/getOverlapOfNonCircularRanges.js +30 -30
  43. package/src/getOverlapsOfPotentiallyCircularRanges.js +5 -5
  44. package/src/getOverlapsOfPotentiallyCircularRanges.test.js +3 -23
  45. package/src/getPositionFromAngle.js +12 -7
  46. package/src/getRangeAngles.js +1 -1
  47. package/src/getRangeAngles.test.js +10 -11
  48. package/src/getRangeLength.test.js +5 -5
  49. package/src/getRangesBetweenTwoRanges.js +31 -22
  50. package/src/getSequenceWithinRange.js +13 -13
  51. package/src/getSequenceWithinRange.test.js +43 -45
  52. package/src/getShortestDistanceBetweenTwoPositions.js +10 -6
  53. package/src/getShortestDistanceBetweenTwoPositions.test.js +11 -13
  54. package/src/getYOffsetForPotentiallyCircularRange.js +33 -21
  55. package/src/getYOffsetsForPotentiallyCircularRanges.js +26 -19
  56. package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -29
  57. package/src/getZeroedRangeOverlaps.js +30 -15
  58. package/src/getZeroedRangeOverlaps.test.js +75 -36
  59. package/src/index.js +52 -51
  60. package/src/index.test.js +6 -8
  61. package/src/invertRange.test.js +103 -93
  62. package/src/isPositionCloserToRangeStartThanRangeEnd.js +18 -6
  63. package/src/isPositionCloserToRangeStartThanRangeEnd.test.js +36 -16
  64. package/src/isPositionWithinRange.js +4 -4
  65. package/src/isRangeOrPositionWithinRange.js +18 -12
  66. package/src/isRangeOrPositionWithinRange.test.js +6 -6
  67. package/src/isRangeWithinRange.js +2 -3
  68. package/src/loopEachPositionInRange.js +3 -3
  69. package/src/modulatePositionByRange.js +8 -8
  70. package/src/modulatePositionByRange.test.js +10 -11
  71. package/src/modulateRangeBySequenceLength.js +7 -7
  72. package/src/modulateRangeBySequenceLength.test.js +39 -16
  73. package/src/normalizePositionByRangeLength.js +22 -18
  74. package/src/normalizePositionByRangeLength.test.js +23 -23
  75. package/src/normalizePositionByRangeLength1Based.js +7 -4
  76. package/src/normalizePositionByRangeLength1Based.test.js +9 -9
  77. package/src/normalizeRange.js +7 -7
  78. package/src/normalizeRange.test.js +9 -9
  79. package/src/provideInclusiveOptions.js +36 -23
  80. package/src/reversePositionInRange.js +16 -12
  81. package/src/splitRangeIntoTwoPartsIfItIsCircular.js +31 -28
  82. package/src/splitRangeIntoTwoPartsIfItIsCircular.test.js +22 -11
  83. package/src/translateRange.js +18 -8
  84. package/src/translateRange.test.js +18 -19
  85. package/src/trimAnnStartEndToFitSeqLength.js +9 -0
  86. package/src/trimAnnStartEndToFitSeqLength.test.js +35 -0
  87. package/src/trimNonCicularRangeByAnotherNonCircularRange.js +45 -42
  88. package/src/trimNumberToFitWithin0ToAnotherNumber.js +13 -10
  89. package/src/trimRangeByAnotherRange.js +20 -19
  90. package/src/trimRangeByAnotherRange.test.js +6 -6
  91. package/src/zeroSubrangeByContainerRange.js +29 -19
  92. package/src/zeroSubrangeByContainerRange.test.js +57 -47
  93. package/trimAnnStartEndToFitSeqLength.d.ts +1 -0
  94. package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
  95. package/index.mjs +0 -6928
  96. package/index.umd.js +0 -6932
package/src/index.js CHANGED
@@ -1,51 +1,52 @@
1
- export { default as adjustRangeToDeletionOfAnotherRange } from './adjustRangeToDeletionOfAnotherRange';
2
- export { default as adjustRangeToInsert } from './adjustRangeToInsert';
3
- export { default as checkIfNonCircularRangesOverlap } from './checkIfNonCircularRangesOverlap';
4
- export { default as checkIfPotentiallyCircularRangesOverlap } from './checkIfPotentiallyCircularRangesOverlap';
5
- export { default as collapseOverlapsGeneratedFromRangeComparisonIfPossible } from './collapseOverlapsGeneratedFromRangeComparisonIfPossible';
6
- export { default as convertRangeIndices } from './convertRangeIndices';
7
- export { default as convertRangeTo0Based } from './convertRangeTo0Based';
8
- export { default as convertRangeTo1Based } from './convertRangeTo1Based';
9
- export { default as doesRangeSpanEntireSequence } from './doesRangeSpanEntireSequence';
10
- export { default as isRangeOrPositionWithinRange } from './isRangeOrPositionWithinRange';
11
- export { default as doesRangeSpanOrigin } from './doesRangeSpanOrigin';
12
- export { default as expandOrContractCircularRangeToPosition } from './expandOrContractCircularRangeToPosition';
13
- export { default as expandOrContractNonCircularRangeToPosition } from './expandOrContractNonCircularRangeToPosition';
14
- export { default as expandOrContractRangeByLength } from './expandOrContractRangeByLength';
15
- export { default as expandOrContractRangeToPosition } from './expandOrContractRangeToPosition';
16
- export { default as flipContainedRange } from './flipContainedRange';
17
- export { default as generateRandomRange } from './generateRandomRange';
18
- export { default as getAnnotationRangeType } from './getAnnotationRangeType';
19
- export { default as getEachPositionInRangeAsArray } from './getEachPositionInRangeAsArray';
20
- export { default as getLengthOfOverlappingRegionsBetweenTwoRanges } from './getLengthOfOverlappingRegionsBetweenTwoRanges';
21
- export { default as getOverlapOfNonCircularRanges } from './getOverlapOfNonCircularRanges';
22
- export { default as getOverlapsOfPotentiallyCircularRanges } from './getOverlapsOfPotentiallyCircularRanges';
23
- export { default as getPositionFromAngle } from './getPositionFromAngle';
24
- export { default as getRangeAngles } from './getRangeAngles';
25
- export { default as getRangeLength } from './getRangeLength';
26
- export { default as getMiddleOfRange } from './getMiddleOfRange';
27
- export { default as getRangesBetweenTwoRanges } from './getRangesBetweenTwoRanges';
28
- export { default as getSequenceWithinRange } from './getSequenceWithinRange';
29
- export { default as getShortestDistanceBetweenTwoPositions } from './getShortestDistanceBetweenTwoPositions';
30
- export { default as getYOffsetForPotentiallyCircularRange } from './getYOffsetForPotentiallyCircularRange';
31
- export { default as getYOffsetsForPotentiallyCircularRanges } from './getYOffsetsForPotentiallyCircularRanges';
32
- export { default as invertRange } from './invertRange';
33
- export { default as isPositionCloserToRangeStartThanRangeEnd } from './isPositionCloserToRangeStartThanRangeEnd';
34
- export { default as isPositionWithinRange } from './isPositionWithinRange';
35
- export { default as isRangeWithinRange } from './isRangeWithinRange';
36
- export { default as loopEachPositionInRange } from './loopEachPositionInRange';
37
- export { default as modulatePositionByRange } from './modulatePositionByRange';
38
- export { default as modulateRangeBySequenceLength } from './modulateRangeBySequenceLength';
39
- export { default as normalizePositionByRangeLength } from './normalizePositionByRangeLength';
40
- export { default as normalizePositionByRangeLength1Based } from './normalizePositionByRangeLength1Based';
41
- export { default as normalizeRange } from './normalizeRange';
42
- export { default as provideInclusiveOptions } from './provideInclusiveOptions';
43
- export { default as reversePositionInRange } from './reversePositionInRange';
44
- export { default as splitRangeIntoTwoPartsIfItIsCircular } from './splitRangeIntoTwoPartsIfItIsCircular';
45
- export { default as translateRange } from './translateRange';
46
- export { default as trimNonCicularRangeByAnotherNonCircularRange } from './trimNonCicularRangeByAnotherNonCircularRange';
47
- export { default as trimNumberToFitWithin0ToAnotherNumber } from './trimNumberToFitWithin0ToAnotherNumber';
48
- export { default as trimRangeByAnotherRange } from './trimRangeByAnotherRange';
49
- export { default as zeroSubrangeByContainerRange } from './zeroSubrangeByContainerRange';
50
- export { default as adjustRangeToRotation } from './adjustRangeToRotation';
51
- export { default as getZeroedRangeOverlaps } from './getZeroedRangeOverlaps';
1
+ export { default as adjustRangeToDeletionOfAnotherRange } from "./adjustRangeToDeletionOfAnotherRange";
2
+ export { default as adjustRangeToInsert } from "./adjustRangeToInsert";
3
+ export { default as checkIfNonCircularRangesOverlap } from "./checkIfNonCircularRangesOverlap";
4
+ export { default as checkIfPotentiallyCircularRangesOverlap } from "./checkIfPotentiallyCircularRangesOverlap";
5
+ export { default as collapseOverlapsGeneratedFromRangeComparisonIfPossible } from "./collapseOverlapsGeneratedFromRangeComparisonIfPossible";
6
+ export { default as convertRangeIndices } from "./convertRangeIndices";
7
+ export { default as convertRangeTo0Based } from "./convertRangeTo0Based";
8
+ export { default as convertRangeTo1Based } from "./convertRangeTo1Based";
9
+ export { default as doesRangeSpanEntireSequence } from "./doesRangeSpanEntireSequence";
10
+ export { default as isRangeOrPositionWithinRange } from "./isRangeOrPositionWithinRange";
11
+ export { default as doesRangeSpanOrigin } from "./doesRangeSpanOrigin";
12
+ export { default as expandOrContractCircularRangeToPosition } from "./expandOrContractCircularRangeToPosition";
13
+ export { default as expandOrContractNonCircularRangeToPosition } from "./expandOrContractNonCircularRangeToPosition";
14
+ export { default as expandOrContractRangeByLength } from "./expandOrContractRangeByLength";
15
+ export { default as expandOrContractRangeToPosition } from "./expandOrContractRangeToPosition";
16
+ export { default as flipContainedRange } from "./flipContainedRange";
17
+ export { default as generateRandomRange } from "./generateRandomRange";
18
+ export { default as getAnnotationRangeType } from "./getAnnotationRangeType";
19
+ export { default as getEachPositionInRangeAsArray } from "./getEachPositionInRangeAsArray";
20
+ export { default as getLengthOfOverlappingRegionsBetweenTwoRanges } from "./getLengthOfOverlappingRegionsBetweenTwoRanges";
21
+ export { default as getOverlapOfNonCircularRanges } from "./getOverlapOfNonCircularRanges";
22
+ export { default as getOverlapsOfPotentiallyCircularRanges } from "./getOverlapsOfPotentiallyCircularRanges";
23
+ export { default as getPositionFromAngle } from "./getPositionFromAngle";
24
+ export { default as getRangeAngles } from "./getRangeAngles";
25
+ export { default as getRangeLength } from "./getRangeLength";
26
+ export { default as getMiddleOfRange } from "./getMiddleOfRange";
27
+ export { default as getRangesBetweenTwoRanges } from "./getRangesBetweenTwoRanges";
28
+ export { default as getSequenceWithinRange } from "./getSequenceWithinRange";
29
+ export { default as getShortestDistanceBetweenTwoPositions } from "./getShortestDistanceBetweenTwoPositions";
30
+ export { default as getYOffsetForPotentiallyCircularRange } from "./getYOffsetForPotentiallyCircularRange";
31
+ export { default as getYOffsetsForPotentiallyCircularRanges } from "./getYOffsetsForPotentiallyCircularRanges";
32
+ export { default as invertRange } from "./invertRange";
33
+ export { default as isPositionCloserToRangeStartThanRangeEnd } from "./isPositionCloserToRangeStartThanRangeEnd";
34
+ export { default as isPositionWithinRange } from "./isPositionWithinRange";
35
+ export { default as isRangeWithinRange } from "./isRangeWithinRange";
36
+ export { default as loopEachPositionInRange } from "./loopEachPositionInRange";
37
+ export { default as modulatePositionByRange } from "./modulatePositionByRange";
38
+ export { default as modulateRangeBySequenceLength } from "./modulateRangeBySequenceLength";
39
+ export { default as normalizePositionByRangeLength } from "./normalizePositionByRangeLength";
40
+ export { default as normalizePositionByRangeLength1Based } from "./normalizePositionByRangeLength1Based";
41
+ export { default as normalizeRange } from "./normalizeRange";
42
+ export { default as provideInclusiveOptions } from "./provideInclusiveOptions";
43
+ export { default as reversePositionInRange } from "./reversePositionInRange";
44
+ export { default as splitRangeIntoTwoPartsIfItIsCircular } from "./splitRangeIntoTwoPartsIfItIsCircular";
45
+ export { default as translateRange } from "./translateRange";
46
+ export { default as trimNonCicularRangeByAnotherNonCircularRange } from "./trimNonCicularRangeByAnotherNonCircularRange";
47
+ export { default as trimNumberToFitWithin0ToAnotherNumber } from "./trimNumberToFitWithin0ToAnotherNumber";
48
+ export { default as trimRangeByAnotherRange } from "./trimRangeByAnotherRange";
49
+ export { default as zeroSubrangeByContainerRange } from "./zeroSubrangeByContainerRange";
50
+ export { default as adjustRangeToRotation } from "./adjustRangeToRotation";
51
+ export { default as getZeroedRangeOverlaps } from "./getZeroedRangeOverlaps";
52
+ export { default as trimAnnStartEndToFitSeqLength } from "./trimAnnStartEndToFitSeqLength";
package/src/index.test.js CHANGED
@@ -3,15 +3,11 @@ import fs from "fs";
3
3
 
4
4
  describe("index.js", () => {
5
5
  it(`should export all functions defined`, () => {
6
- return new Promise((resolve) => {
7
-
6
+ return new Promise(resolve => {
8
7
  fs.readdir(__dirname, (err, files) => {
9
8
  let passes = true;
10
9
  files.forEach(file => {
11
- if (
12
- file.indexOf(".test.js") > -1 ||
13
- file.indexOf("index.js") > -1
14
- ) {
10
+ if (file.indexOf(".test.js") > -1 || file.indexOf("index.js") > -1) {
15
11
  return;
16
12
  }
17
13
  const funcOrObj = src[file.replace(".js", "")];
@@ -24,10 +20,12 @@ describe("index.js", () => {
24
20
  }
25
21
  });
26
22
  if (!passes) {
27
- throw new Error("Please make sure to export (or ignore) each file! Update index.js to export the file");
23
+ throw new Error(
24
+ "Please make sure to export (or ignore) each file! Update index.js to export the file"
25
+ );
28
26
  }
29
27
  resolve();
30
28
  });
31
- })
29
+ });
32
30
  });
33
31
  });
@@ -1,96 +1,106 @@
1
-
2
- import invertRange from './invertRange';
3
- import chai from 'chai';
1
+ import invertRange from "./invertRange";
2
+ import chai from "chai";
4
3
  chai.should();
5
- describe('invertRange', function () {
6
- it('should invert a non-circular range', function () {
7
- const invertedRange = invertRange({start: 2, end:2}, 10);
8
- invertedRange.start.should.equal(3)
9
- invertedRange.end.should.equal(1)
10
- });
11
- it('should invert a non-circular range', function () {
12
- const invertedRange = invertRange({start: 0, end:2}, 10);
13
- invertedRange.start.should.equal(3)
14
- invertedRange.end.should.equal(9)
15
- });
16
- it('should invert a non-circular range', function () {
17
- const invertedRange = invertRange({start: 0, end:9}, 10);
18
- invertedRange.start.should.equal(0)
19
- invertedRange.end.should.equal(9)
20
- });
21
- it('should invert a non-circular range', function () {
22
- const invertedRange = invertRange({start: 4, end:9}, 10);
23
- invertedRange.start.should.equal(0)
24
- invertedRange.end.should.equal(3)
25
- });
26
- it('should invert a circular range', function () {
27
- const invertedRange = invertRange({start: 3, end:1}, 10);
28
- invertedRange.start.should.equal(2)
29
- invertedRange.end.should.equal(2)
30
- });
31
- it('should invert a circular range', function () {
32
- const invertedRange = invertRange({start: 9, end:1}, 10);
33
- invertedRange.start.should.equal(2)
34
- invertedRange.end.should.equal(8)
35
- });
36
- it('should invert a circular range', function () {
37
- const invertedRange = invertRange({start: 3, end:0}, 10);
38
- invertedRange.start.should.equal(1)
39
- invertedRange.end.should.equal(2)
40
- });
41
- it('should handle inverting a whole range by returning the original range', function () {
42
- const invertedRange = invertRange({start: 4, end:3}, 10);
43
- invertedRange.start.should.equal(4)
44
- invertedRange.end.should.equal(3)
45
- });
46
- it('should handle inverting a caret position', function () {
47
- const invertedRange = invertRange(1, 10);
48
- invertedRange.start.should.equal(1)
49
- invertedRange.end.should.equal(0)
50
- });
51
- it('should handle inverting a caret position', function () {
52
- const invertedRange = invertRange(0, 10);
53
- invertedRange.start.should.equal(0)
54
- invertedRange.end.should.equal(9)
55
- });
56
- //tnrtodo: maybe one day we'll want to handle the "entire range" case in a special way, but for now we'll just return the original range
57
- // it('should handle inverting a whole range by setting the start and end to -1', function () {
58
- // var invertedRange = invertRange({start: 4, end:3}, 10);
59
- // invertedRange.start.should.equal(-1)
60
- // invertedRange.end.should.equal(-1)
61
- // });
4
+ describe("invertRange", function () {
5
+ it("should invert a non-circular range", function () {
6
+ const invertedRange = invertRange({ start: 2, end: 2 }, 10);
7
+ invertedRange.start.should.equal(3);
8
+ invertedRange.end.should.equal(1);
9
+ });
10
+ it("should invert a non-circular range", function () {
11
+ const invertedRange = invertRange({ start: 0, end: 2 }, 10);
12
+ invertedRange.start.should.equal(3);
13
+ invertedRange.end.should.equal(9);
14
+ });
15
+ it("should invert a non-circular range", function () {
16
+ const invertedRange = invertRange({ start: 0, end: 9 }, 10);
17
+ invertedRange.start.should.equal(0);
18
+ invertedRange.end.should.equal(9);
19
+ });
20
+ it("should invert a non-circular range", function () {
21
+ const invertedRange = invertRange({ start: 4, end: 9 }, 10);
22
+ invertedRange.start.should.equal(0);
23
+ invertedRange.end.should.equal(3);
24
+ });
25
+ it("should invert a circular range", function () {
26
+ const invertedRange = invertRange({ start: 3, end: 1 }, 10);
27
+ invertedRange.start.should.equal(2);
28
+ invertedRange.end.should.equal(2);
29
+ });
30
+ it("should invert a circular range", function () {
31
+ const invertedRange = invertRange({ start: 9, end: 1 }, 10);
32
+ invertedRange.start.should.equal(2);
33
+ invertedRange.end.should.equal(8);
34
+ });
35
+ it("should invert a circular range", function () {
36
+ const invertedRange = invertRange({ start: 3, end: 0 }, 10);
37
+ invertedRange.start.should.equal(1);
38
+ invertedRange.end.should.equal(2);
39
+ });
40
+ it("should handle inverting a whole range by returning the original range", function () {
41
+ const invertedRange = invertRange({ start: 4, end: 3 }, 10);
42
+ invertedRange.start.should.equal(4);
43
+ invertedRange.end.should.equal(3);
44
+ });
45
+ it("should handle inverting a caret position", function () {
46
+ const invertedRange = invertRange(1, 10);
47
+ invertedRange.start.should.equal(1);
48
+ invertedRange.end.should.equal(0);
49
+ });
50
+ it("should handle inverting a caret position", function () {
51
+ const invertedRange = invertRange(0, 10);
52
+ invertedRange.start.should.equal(0);
53
+ invertedRange.end.should.equal(9);
54
+ });
55
+ //tnrtodo: maybe one day we'll want to handle the "entire range" case in a special way, but for now we'll just return the original range
56
+ // it('should handle inverting a whole range by setting the start and end to -1', function () {
57
+ // var invertedRange = invertRange({start: 4, end:3}, 10);
58
+ // invertedRange.start.should.equal(-1)
59
+ // invertedRange.end.should.equal(-1)
60
+ // });
62
61
  });
63
- describe('invertRange should handle options inclusive1BasedEnd or inclusive1BasedStart', function () {
64
- it('should handle inverting a whole range by returning the original range', function () {
65
- const options = {inclusive1BasedEnd: true};
66
- const invertedRange = invertRange({start: 2, end:2}, 10, options);
67
- invertedRange.start.should.equal(2)
68
- invertedRange.end.should.equal(2)
69
- });
70
- it('should invert a non-circular range', function () {
71
- const options = {inclusive1BasedEnd: true};
72
- const invertedRange = invertRange({start: 0, end:2}, 10, options);
73
- invertedRange.start.should.equal(2)
74
- invertedRange.end.should.equal(10)
75
- });
76
- it('should invert non-circular range 1', function () {
77
- const invertedRange = invertRange({start: 0, end:9}, 10,{inclusive1BasedEnd: true});
78
- invertedRange.start.should.equal(9)
79
- invertedRange.end.should.equal(10)
80
- });
81
- it('should invert a non-circular range 2', function () {
82
- const invertedRange = invertRange({start: 1, end:9}, 10,{inclusive1BasedEnd: true,inclusive1BasedStart: true});
83
- invertedRange.start.should.equal(10)
84
- invertedRange.end.should.equal(10)
85
- });
86
- it('should invert a non-circular range 3', function () {
87
- const invertedRange = invertRange({start: 3, end:6}, 10,{inclusive1BasedEnd: true,inclusive1BasedStart: true});
88
- invertedRange.start.should.equal(7)
89
- invertedRange.end.should.equal(2)
90
- });
91
- it('should invert a circular range 4', function () {
92
- const invertedRange = invertRange({start: 6, end:3}, 10,{inclusive1BasedEnd: true,inclusive1BasedStart: true});
93
- invertedRange.start.should.equal(4)
94
- invertedRange.end.should.equal(5)
95
- });
62
+ describe("invertRange should handle options inclusive1BasedEnd or inclusive1BasedStart", function () {
63
+ it("should handle inverting a whole range by returning the original range", function () {
64
+ const options = { inclusive1BasedEnd: true };
65
+ const invertedRange = invertRange({ start: 2, end: 2 }, 10, options);
66
+ invertedRange.start.should.equal(2);
67
+ invertedRange.end.should.equal(2);
68
+ });
69
+ it("should invert a non-circular range", function () {
70
+ const options = { inclusive1BasedEnd: true };
71
+ const invertedRange = invertRange({ start: 0, end: 2 }, 10, options);
72
+ invertedRange.start.should.equal(2);
73
+ invertedRange.end.should.equal(10);
74
+ });
75
+ it("should invert non-circular range 1", function () {
76
+ const invertedRange = invertRange({ start: 0, end: 9 }, 10, {
77
+ inclusive1BasedEnd: true
78
+ });
79
+ invertedRange.start.should.equal(9);
80
+ invertedRange.end.should.equal(10);
81
+ });
82
+ it("should invert a non-circular range 2", function () {
83
+ const invertedRange = invertRange({ start: 1, end: 9 }, 10, {
84
+ inclusive1BasedEnd: true,
85
+ inclusive1BasedStart: true
86
+ });
87
+ invertedRange.start.should.equal(10);
88
+ invertedRange.end.should.equal(10);
89
+ });
90
+ it("should invert a non-circular range 3", function () {
91
+ const invertedRange = invertRange({ start: 3, end: 6 }, 10, {
92
+ inclusive1BasedEnd: true,
93
+ inclusive1BasedStart: true
94
+ });
95
+ invertedRange.start.should.equal(7);
96
+ invertedRange.end.should.equal(2);
97
+ });
98
+ it("should invert a circular range 4", function () {
99
+ const invertedRange = invertRange({ start: 6, end: 3 }, 10, {
100
+ inclusive1BasedEnd: true,
101
+ inclusive1BasedStart: true
102
+ });
103
+ invertedRange.start.should.equal(4);
104
+ invertedRange.end.should.equal(5);
105
+ });
96
106
  });
@@ -1,8 +1,20 @@
1
1
  //function to calculate whether a position is closer to the range start than the range end
2
- import getShortestDistanceBetweenTwoPositions from './getShortestDistanceBetweenTwoPositions';
2
+ import getShortestDistanceBetweenTwoPositions from "./getShortestDistanceBetweenTwoPositions";
3
3
 
4
- export default function isPositionCloserToRangeStartThanRangeEnd(position, range, maxLength) {
5
- const distanceFromStart = getShortestDistanceBetweenTwoPositions(range.start, position, maxLength);
6
- const distanceFromEnd = getShortestDistanceBetweenTwoPositions(range.end, position, maxLength);
7
- return distanceFromStart <= distanceFromEnd
8
- };
4
+ export default function isPositionCloserToRangeStartThanRangeEnd(
5
+ position,
6
+ range,
7
+ maxLength
8
+ ) {
9
+ const distanceFromStart = getShortestDistanceBetweenTwoPositions(
10
+ range.start,
11
+ position,
12
+ maxLength
13
+ );
14
+ const distanceFromEnd = getShortestDistanceBetweenTwoPositions(
15
+ range.end,
16
+ position,
17
+ maxLength
18
+ );
19
+ return distanceFromStart <= distanceFromEnd;
20
+ }
@@ -1,17 +1,37 @@
1
- import isPositionCloserToRangeStartThanRangeEnd from './isPositionCloserToRangeStartThanRangeEnd';
2
- import {expect} from 'chai';
1
+ import isPositionCloserToRangeStartThanRangeEnd from "./isPositionCloserToRangeStartThanRangeEnd";
2
+ import { expect } from "chai";
3
3
 
4
- describe('isPositionCloserToRangeStartThanRangeEnd', function() {
5
- it('should correctly determine whether a position is closer to the start of a range than the end', function() {
6
- expect(isPositionCloserToRangeStartThanRangeEnd(0,{start: 1, end: 10}, 100)).to.equal(true)
7
- expect(isPositionCloserToRangeStartThanRangeEnd(1,{start: 0, end: 10}, 100)).to.equal(true)
8
- expect(isPositionCloserToRangeStartThanRangeEnd(11,{start: 1, end: 10}, 100)).to.equal(false)
9
- expect(isPositionCloserToRangeStartThanRangeEnd(0,{start: 0, end: 10}, 100)).to.equal(true)
10
- expect(isPositionCloserToRangeStartThanRangeEnd(10,{start: 0, end: 10}, 100)).to.equal(false)
11
- expect(isPositionCloserToRangeStartThanRangeEnd(10,{start: 10, end: 5}, 100)).to.equal(true)
12
- expect(isPositionCloserToRangeStartThanRangeEnd(11,{start: 10, end: 5}, 100)).to.equal(true)
13
- expect(isPositionCloserToRangeStartThanRangeEnd(4,{start: 10, end: 5}, 100)).to.equal(false)
14
- expect(isPositionCloserToRangeStartThanRangeEnd(5,{start: 10, end: 5}, 100)).to.equal(false)
15
- expect(isPositionCloserToRangeStartThanRangeEnd(6,{start: 10, end: 5}, 100)).to.equal(false)
16
- })
17
- })
4
+ describe("isPositionCloserToRangeStartThanRangeEnd", function () {
5
+ it("should correctly determine whether a position is closer to the start of a range than the end", function () {
6
+ expect(
7
+ isPositionCloserToRangeStartThanRangeEnd(0, { start: 1, end: 10 }, 100)
8
+ ).to.equal(true);
9
+ expect(
10
+ isPositionCloserToRangeStartThanRangeEnd(1, { start: 0, end: 10 }, 100)
11
+ ).to.equal(true);
12
+ expect(
13
+ isPositionCloserToRangeStartThanRangeEnd(11, { start: 1, end: 10 }, 100)
14
+ ).to.equal(false);
15
+ expect(
16
+ isPositionCloserToRangeStartThanRangeEnd(0, { start: 0, end: 10 }, 100)
17
+ ).to.equal(true);
18
+ expect(
19
+ isPositionCloserToRangeStartThanRangeEnd(10, { start: 0, end: 10 }, 100)
20
+ ).to.equal(false);
21
+ expect(
22
+ isPositionCloserToRangeStartThanRangeEnd(10, { start: 10, end: 5 }, 100)
23
+ ).to.equal(true);
24
+ expect(
25
+ isPositionCloserToRangeStartThanRangeEnd(11, { start: 10, end: 5 }, 100)
26
+ ).to.equal(true);
27
+ expect(
28
+ isPositionCloserToRangeStartThanRangeEnd(4, { start: 10, end: 5 }, 100)
29
+ ).to.equal(false);
30
+ expect(
31
+ isPositionCloserToRangeStartThanRangeEnd(5, { start: 10, end: 5 }, 100)
32
+ ).to.equal(false);
33
+ expect(
34
+ isPositionCloserToRangeStartThanRangeEnd(6, { start: 10, end: 5 }, 100)
35
+ ).to.equal(false);
36
+ });
37
+ });
@@ -1,10 +1,10 @@
1
1
  import splitRangeIntoTwoPartsIfItIsCircular from "./splitRangeIntoTwoPartsIfItIsCircular";
2
2
  /**
3
- *
3
+ *
4
4
  * @param {*} position //assumed to be a 0 based "caretPosition"
5
5
  * @param {*} range //0 based inclusive range
6
- * @param {*} sequenceLength
7
- * @param {*} includeEdges - (default false) whether or not to say
6
+ * @param {*} sequenceLength
7
+ * @param {*} includeEdges - (default false) whether or not to say
8
8
  */
9
9
  function isPositionWithinRange(
10
10
  position,
@@ -14,7 +14,7 @@ function isPositionWithinRange(
14
14
  includeEndEdge
15
15
  ) {
16
16
  const ranges = splitRangeIntoTwoPartsIfItIsCircular(range, sequenceLength);
17
- const positionFits = ranges.some(function(range) {
17
+ const positionFits = ranges.some(function (range) {
18
18
  if (includeStartEdge ? position < range.start : position <= range.start) {
19
19
  return false;
20
20
  } else {
@@ -1,4 +1,4 @@
1
- import {isObject} from "lodash";
1
+ import { isObject } from "lodash-es";
2
2
  import isRangeWithinRange from "./isRangeWithinRange";
3
3
  import isPositionWithinRange from "./isPositionWithinRange";
4
4
 
@@ -9,21 +9,27 @@ export default function isRangeOrPositionWithinRange(
9
9
  includeStartEdge,
10
10
  includeEndEdge
11
11
  ) {
12
-
13
- if (rangeOrPositionToCheck === undefined || rangeOrPositionToCheck === null ||
14
- containingRange === undefined || containingRange === null ) {
15
- return false
12
+ if (
13
+ rangeOrPositionToCheck === undefined ||
14
+ rangeOrPositionToCheck === null ||
15
+ containingRange === undefined ||
16
+ containingRange === null
17
+ ) {
18
+ return false;
16
19
  }
17
- if (isObject(rangeOrPositionToCheck)) {
18
- return isRangeWithinRange(rangeOrPositionToCheck,
20
+ if (isObject(rangeOrPositionToCheck)) {
21
+ return isRangeWithinRange(
22
+ rangeOrPositionToCheck,
19
23
  containingRange,
20
- maxLength)
24
+ maxLength
25
+ );
21
26
  } else {
22
- return isPositionWithinRange( rangeOrPositionToCheck,
27
+ return isPositionWithinRange(
28
+ rangeOrPositionToCheck,
23
29
  containingRange,
24
30
  maxLength,
25
31
  includeStartEdge,
26
- includeEndEdge)
32
+ includeEndEdge
33
+ );
27
34
  }
28
-
29
- };
35
+ }
@@ -1,8 +1,8 @@
1
1
  import isRangeOrPositionWithinRange from "./isRangeOrPositionWithinRange";
2
- import {expect} from "chai";
2
+ import { expect } from "chai";
3
3
 
4
- describe("isRangeOrPositionWithinRange", function() {
5
- it("should correctly determine whether a position is within a range", function() {
4
+ describe("isRangeOrPositionWithinRange", function () {
5
+ it("should correctly determine whether a position is within a range", function () {
6
6
  expect(isRangeOrPositionWithinRange(1, { start: 1, end: 1 })).to.equal(
7
7
  false
8
8
  );
@@ -38,7 +38,7 @@ describe("isRangeOrPositionWithinRange", function() {
38
38
  );
39
39
  });
40
40
 
41
- it("should correctly determine whether a position is within a range when includeStartEdge/includeEndEdge is set to true", function() {
41
+ it("should correctly determine whether a position is within a range when includeStartEdge/includeEndEdge is set to true", function () {
42
42
  expect(
43
43
  isRangeOrPositionWithinRange(1, { start: 1, end: 1 }, 11, true, true)
44
44
  ).to.equal(true);
@@ -47,7 +47,7 @@ describe("isRangeOrPositionWithinRange", function() {
47
47
  ).to.equal(true);
48
48
  });
49
49
 
50
- it("should work for angle values w/ long decimal places", function() {
50
+ it("should work for angle values w/ long decimal places", function () {
51
51
  expect(
52
52
  isRangeOrPositionWithinRange(
53
53
  { start: 5.669848916850995, end: 5.815135586893387 },
@@ -56,7 +56,7 @@ describe("isRangeOrPositionWithinRange", function() {
56
56
  )
57
57
  ).to.equal(true);
58
58
  });
59
- it("should correctly determine whether a position is within a range", function() {
59
+ it("should correctly determine whether a position is within a range", function () {
60
60
  expect(
61
61
  isRangeOrPositionWithinRange(null, { start: 1, end: 10 }, 100)
62
62
  ).to.equal(false);
@@ -6,12 +6,11 @@ export default function isRangeWithinRange(
6
6
  containingRange,
7
7
  maxLength
8
8
  ) {
9
-
10
9
  const ranges = trimRangeByAnotherRange(
11
10
  rangeToCheck,
12
11
  containingRange,
13
12
  maxLength
14
13
  );
15
- if (ranges === null) return false
14
+ if (ranges === null) return false;
16
15
  return !ranges;
17
- };
16
+ }
@@ -1,5 +1,5 @@
1
- import getEachPositionInRangeAsArray from './getEachPositionInRangeAsArray';
1
+ import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
2
2
 
3
3
  export default function loopEachPositionInRange(range, rangeMax, func) {
4
- getEachPositionInRangeAsArray(range,rangeMax).map(func)
5
- };
4
+ getEachPositionInRangeAsArray(range, rangeMax).map(func);
5
+ }
@@ -1,10 +1,10 @@
1
1
  //this function takes a position that might not fit in a given range and puts it into that range
2
2
  export default function modulatePositionByRange(position, range) {
3
- let returnVal = position;
4
- if (position < range.start) {
5
- returnVal = range.end - (range.start - (position + 1))
6
- } else if (position > range.end) {
7
- returnVal = range.start + (position - range.end - 1)
8
- }
9
- return returnVal
10
- };
3
+ let returnVal = position;
4
+ if (position < range.start) {
5
+ returnVal = range.end - (range.start - (position + 1));
6
+ } else if (position > range.end) {
7
+ returnVal = range.start + (position - range.end - 1);
8
+ }
9
+ return returnVal;
10
+ }
@@ -1,12 +1,11 @@
1
- import modulatePositionByRange from './modulatePositionByRange';
2
- import {expect} from 'chai';
1
+ import modulatePositionByRange from "./modulatePositionByRange";
2
+ import { expect } from "chai";
3
3
 
4
- describe('modulatePositionByRange', function() {
5
- it('should modulate positions by their min and max', function() {
6
- expect(modulatePositionByRange(0,{start: 1, end: 10})).to.equal(10)
7
- expect(modulatePositionByRange(11,{start: 1, end: 10})).to.equal(1)
8
- expect(modulatePositionByRange(0,{start: 0, end: 10})).to.equal(0)
9
- expect(modulatePositionByRange(10,{start: 0, end: 10})).to.equal(10)
10
- })
11
-
12
- })
4
+ describe("modulatePositionByRange", function () {
5
+ it("should modulate positions by their min and max", function () {
6
+ expect(modulatePositionByRange(0, { start: 1, end: 10 })).to.equal(10);
7
+ expect(modulatePositionByRange(11, { start: 1, end: 10 })).to.equal(1);
8
+ expect(modulatePositionByRange(0, { start: 0, end: 10 })).to.equal(0);
9
+ expect(modulatePositionByRange(10, { start: 0, end: 10 })).to.equal(10);
10
+ });
11
+ });
@@ -1,11 +1,11 @@
1
- import normalizePositionByRangeLength from './normalizePositionByRangeLength';
2
- import provideInclusiveOptions from './provideInclusiveOptions';
3
- import {assign} from "lodash";
1
+ import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
2
+ import provideInclusiveOptions from "./provideInclusiveOptions";
3
+ import { assign } from "lodash-es";
4
4
  export default provideInclusiveOptions(modulateRangeBySequenceLength);
5
5
 
6
6
  function modulateRangeBySequenceLength(range, seqLen) {
7
- return assign(range, {
8
- start: normalizePositionByRangeLength(range.start, seqLen),
9
- end: normalizePositionByRangeLength(range.end, seqLen)
10
- })
7
+ return assign(range, {
8
+ start: normalizePositionByRangeLength(range.start, seqLen),
9
+ end: normalizePositionByRangeLength(range.end, seqLen)
10
+ });
11
11
  }