@teselagen/range-utils 0.3.20-beta.1 → 0.3.20
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.
- package/adjustRangeToDeletionOfAnotherRange.d.ts +1 -2
- package/adjustRangeToDeletionOfAnotherRange.test.d.ts +1 -0
- package/adjustRangeToInsert.d.ts +1 -2
- package/adjustRangeToInsert.test.d.ts +1 -0
- package/adjustRangeToRotation.d.ts +1 -2
- package/adjustRangeToRotation.test.d.ts +1 -0
- package/checkIfNonCircularRangesOverlap.d.ts +1 -2
- package/checkIfNonCircularRangesOverlap.test.d.ts +1 -0
- package/checkIfPotentiallyCircularRangesOverlap.d.ts +1 -2
- package/checkIfPotentiallyCircularRangesOverlap.test.d.ts +1 -0
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.d.ts +1 -2
- package/collapseOverlapsGeneratedFromRangeComparisonIfPossible.test.d.ts +1 -0
- package/convertRangeIndices.d.ts +1 -10
- package/convertRangeIndices.test.d.ts +1 -0
- package/convertRangeTo0Based.d.ts +1 -5
- package/convertRangeTo1Based.d.ts +1 -5
- package/doesRangeSpanEntireSequence.d.ts +1 -2
- package/doesRangeSpanOrigin.d.ts +1 -2
- package/expandOrContractCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractNonCircularRangeToPosition.d.ts +2 -3
- package/expandOrContractRangeByLength.d.ts +1 -5
- package/expandOrContractRangeByLength.test.d.ts +1 -0
- package/expandOrContractRangeToPosition.d.ts +2 -3
- package/flipContainedRange.d.ts +1 -5
- package/flipContainedRange.test.d.ts +1 -0
- package/generateRandomRange.d.ts +3 -3
- package/generateRandomRange.test.d.ts +1 -0
- package/getAnnotationRangeType.d.ts +1 -2
- package/getAnnotationRangeType.test.d.ts +1 -0
- package/getEachPositionInRangeAsArray.d.ts +1 -2
- package/getEachPositionInRangeAsArray.test.d.ts +1 -0
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.d.ts +1 -2
- package/getLengthOfOverlappingRegionsBetweenTwoRanges.test.d.ts +1 -0
- package/getMiddleOfRange.d.ts +1 -2
- package/getMiddleOfRange.test.d.ts +1 -0
- package/getOverlapOfNonCircularRanges.d.ts +4 -5
- package/getOverlapsOfPotentiallyCircularRanges.d.ts +1 -2
- package/getOverlapsOfPotentiallyCircularRanges.test.d.ts +1 -0
- package/getPositionFromAngle.d.ts +1 -1
- package/getRangeAngles.d.ts +7 -3
- package/getRangeAngles.test.d.ts +1 -0
- package/getRangeLength.d.ts +1 -5
- package/getRangeLength.test.d.ts +1 -0
- package/getRangesBetweenTwoRanges.d.ts +1 -2
- package/getSequenceWithinRange.d.ts +1 -3
- package/getSequenceWithinRange.test.d.ts +1 -0
- package/getShortestDistanceBetweenTwoPositions.d.ts +1 -1
- package/getShortestDistanceBetweenTwoPositions.test.d.ts +1 -0
- package/getYOffsetForPotentiallyCircularRange.d.ts +1 -2
- package/getYOffsetsForPotentiallyCircularRanges.d.ts +2 -3
- package/getYOffsetsForPotentiallyCircularRanges.test.d.ts +1 -0
- package/getZeroedRangeOverlaps.d.ts +1 -2
- package/getZeroedRangeOverlaps.test.d.ts +1 -0
- package/index.cjs +45 -58
- package/index.d.ts +0 -1
- package/index.js +45 -58
- package/index.test.d.ts +1 -0
- package/index.umd.cjs +45 -58
- package/invertRange.d.ts +1 -5
- package/invertRange.test.d.ts +1 -0
- package/isPositionCloserToRangeStartThanRangeEnd.d.ts +1 -2
- package/isPositionCloserToRangeStartThanRangeEnd.test.d.ts +1 -0
- package/isPositionWithinRange.d.ts +2 -3
- package/isRangeOrPositionWithinRange.d.ts +1 -2
- package/isRangeOrPositionWithinRange.test.d.ts +1 -0
- package/isRangeWithinRange.d.ts +1 -2
- package/loopEachPositionInRange.d.ts +1 -2
- package/modulatePositionByRange.d.ts +1 -2
- package/modulatePositionByRange.test.d.ts +1 -0
- package/modulateRangeBySequenceLength.d.ts +1 -8
- package/modulateRangeBySequenceLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength.d.ts +1 -1
- package/normalizePositionByRangeLength.test.d.ts +1 -0
- package/normalizePositionByRangeLength1Based.d.ts +1 -1
- package/normalizePositionByRangeLength1Based.test.d.ts +1 -0
- package/normalizeRange.d.ts +1 -5
- package/normalizeRange.test.d.ts +1 -0
- package/package.json +2 -10
- package/provideInclusiveOptions.d.ts +1 -6
- package/reversePositionInRange.d.ts +1 -1
- package/splitRangeIntoTwoPartsIfItIsCircular.d.ts +3 -4
- package/splitRangeIntoTwoPartsIfItIsCircular.test.d.ts +1 -0
- package/src/{adjustRangeToDeletionOfAnotherRange.ts → adjustRangeToDeletionOfAnotherRange.js} +7 -4
- package/src/{adjustRangeToInsert.ts → adjustRangeToInsert.js} +4 -4
- package/src/adjustRangeToRotation.js +23 -0
- package/src/{checkIfNonCircularRangesOverlap.ts → checkIfNonCircularRangesOverlap.js} +4 -5
- package/src/{checkIfPotentiallyCircularRangesOverlap.ts → checkIfPotentiallyCircularRangesOverlap.js} +4 -4
- package/src/{collapseOverlapsGeneratedFromRangeComparisonIfPossible.ts → collapseOverlapsGeneratedFromRangeComparisonIfPossible.js} +4 -7
- package/src/{convertRangeIndices.ts → convertRangeIndices.js} +3 -11
- package/src/{convertRangeTo0Based.ts → convertRangeTo0Based.js} +1 -2
- package/src/{convertRangeTo1Based.ts → convertRangeTo1Based.js} +1 -2
- package/src/doesRangeSpanEntireSequence.js +7 -0
- package/src/doesRangeSpanOrigin.js +3 -0
- package/src/{expandOrContractCircularRangeToPosition.ts → expandOrContractCircularRangeToPosition.js} +3 -5
- package/src/{expandOrContractNonCircularRangeToPosition.ts → expandOrContractNonCircularRangeToPosition.js} +2 -4
- package/src/{expandOrContractRangeByLength.ts → expandOrContractRangeByLength.js} +4 -5
- package/src/{expandOrContractRangeToPosition.ts → expandOrContractRangeToPosition.js} +8 -6
- package/src/{flipContainedRange.ts → flipContainedRange.js} +8 -18
- package/src/{generateRandomRange.ts → generateRandomRange.js} +2 -6
- package/src/{getAnnotationRangeType.ts → getAnnotationRangeType.js} +3 -5
- package/src/{getEachPositionInRangeAsArray.ts → getEachPositionInRangeAsArray.js} +2 -6
- package/src/{getLengthOfOverlappingRegionsBetweenTwoRanges.ts → getLengthOfOverlappingRegionsBetweenTwoRanges.js} +3 -4
- package/src/{getMiddleOfRange.ts → getMiddleOfRange.js} +1 -2
- package/src/{getOverlapOfNonCircularRanges.ts → getOverlapOfNonCircularRanges.js} +1 -7
- package/src/{getOverlapsOfPotentiallyCircularRanges.ts → getOverlapsOfPotentiallyCircularRanges.js} +7 -13
- package/src/{getPositionFromAngle.ts → getPositionFromAngle.js} +3 -3
- package/src/{getRangeAngles.ts → getRangeAngles.js} +3 -8
- package/src/{getRangeLength.ts → getRangeLength.js} +1 -4
- package/src/{getRangesBetweenTwoRanges.ts → getRangesBetweenTwoRanges.js} +2 -7
- package/src/getSequenceWithinRange.js +17 -0
- package/src/{getShortestDistanceBetweenTwoPositions.ts → getShortestDistanceBetweenTwoPositions.js} +3 -3
- package/src/{getYOffsetForPotentiallyCircularRange.ts → getYOffsetForPotentiallyCircularRange.js} +4 -5
- package/src/{getYOffsetsForPotentiallyCircularRanges.ts → getYOffsetsForPotentiallyCircularRanges.js} +4 -5
- package/src/getYOffsetsForPotentiallyCircularRanges.test.js +42 -0
- package/src/{getZeroedRangeOverlaps.ts → getZeroedRangeOverlaps.js} +3 -4
- package/src/{getZeroedRangeOverlaps.test.ts → getZeroedRangeOverlaps.test.js} +15 -5
- package/src/{index.ts → index.js} +0 -1
- package/src/{index.test.ts → index.test.js} +3 -11
- package/src/invertRange.js +21 -0
- package/src/{isPositionCloserToRangeStartThanRangeEnd.ts → isPositionCloserToRangeStartThanRangeEnd.js} +3 -5
- package/src/{isPositionWithinRange.ts → isPositionWithinRange.js} +5 -14
- package/src/{isRangeOrPositionWithinRange.ts → isRangeOrPositionWithinRange.js} +6 -11
- package/src/{isRangeWithinRange.ts → isRangeWithinRange.js} +3 -5
- package/src/loopEachPositionInRange.js +5 -0
- package/src/{modulatePositionByRange.ts → modulatePositionByRange.js} +1 -6
- package/src/{modulateRangeBySequenceLength.ts → modulateRangeBySequenceLength.js} +1 -3
- package/src/{normalizePositionByRangeLength.ts → normalizePositionByRangeLength.js} +7 -7
- package/src/{normalizePositionByRangeLength1Based.ts → normalizePositionByRangeLength1Based.js} +2 -3
- package/src/{normalizeRange.ts → normalizeRange.js} +1 -2
- package/src/provideInclusiveOptions.js +39 -0
- package/src/{reversePositionInRange.ts → reversePositionInRange.js} +4 -4
- package/src/{splitRangeIntoTwoPartsIfItIsCircular.ts → splitRangeIntoTwoPartsIfItIsCircular.js} +4 -5
- package/src/{translateRange.ts → translateRange.js} +3 -5
- package/src/{trimAnnStartEndToFitSeqLength.ts → trimAnnStartEndToFitSeqLength.js} +2 -2
- package/src/{trimNonCicularRangeByAnotherNonCircularRange.ts → trimNonCicularRangeByAnotherNonCircularRange.js} +4 -6
- package/src/{trimNumberToFitWithin0ToAnotherNumber.ts → trimNumberToFitWithin0ToAnotherNumber.js} +4 -3
- package/src/{trimRangeByAnotherRange.ts → trimRangeByAnotherRange.js} +9 -9
- package/src/{zeroSubrangeByContainerRange.ts → zeroSubrangeByContainerRange.js} +8 -10
- package/translateRange.d.ts +1 -5
- package/translateRange.test.d.ts +1 -0
- package/trimAnnStartEndToFitSeqLength.d.ts +1 -1
- package/trimAnnStartEndToFitSeqLength.test.d.ts +1 -0
- package/trimNonCicularRangeByAnotherNonCircularRange.d.ts +4 -2
- package/trimNumberToFitWithin0ToAnotherNumber.d.ts +1 -1
- package/trimRangeByAnotherRange.d.ts +1 -2
- package/trimRangeByAnotherRange.test.d.ts +1 -0
- package/zeroSubrangeByContainerRange.d.ts +1 -2
- package/zeroSubrangeByContainerRange.test.d.ts +1 -0
- package/RangeAngles.d.ts +0 -7
- package/src/RangeAngles.ts +0 -9
- package/src/adjustRangeToRotation.ts +0 -22
- package/src/doesRangeSpanEntireSequence.ts +0 -12
- package/src/doesRangeSpanOrigin.ts +0 -5
- package/src/getSequenceWithinRange.ts +0 -33
- package/src/getYOffsetsForPotentiallyCircularRanges.test.ts +0 -17
- package/src/invertRange.ts +0 -25
- package/src/loopEachPositionInRange.ts +0 -11
- package/src/provideInclusiveOptions.ts +0 -79
- package/src/types.ts +0 -12
- package/types.d.ts +0 -12
- /package/src/{getRangeLength.test.ts → getRangeLength.test.js} +0 -0
- /package/src/{getSequenceWithinRange.test.ts → getSequenceWithinRange.test.js} +0 -0
- /package/src/{getShortestDistanceBetweenTwoPositions.test.ts → getShortestDistanceBetweenTwoPositions.test.js} +0 -0
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
|
-
// overload the function signatures so that TS knows what type to expect back (string or T[])
|
|
4
|
-
export default function getSequenceWithinRange(
|
|
5
|
-
range: Range,
|
|
6
|
-
sequence: string
|
|
7
|
-
): string;
|
|
8
|
-
export default function getSequenceWithinRange<T>(
|
|
9
|
-
range: Range,
|
|
10
|
-
sequence: T[]
|
|
11
|
-
): T[];
|
|
12
|
-
export default function getSequenceWithinRange<T>(
|
|
13
|
-
range: Range,
|
|
14
|
-
sequence: string | T[]
|
|
15
|
-
) {
|
|
16
|
-
if (range.start < 0 || range.end < 0) {
|
|
17
|
-
if (typeof sequence === "string") return "";
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
if (range.start > range.end) {
|
|
21
|
-
//circular range
|
|
22
|
-
const subSequence = sequence.slice(range.start, sequence.length);
|
|
23
|
-
if (typeof subSequence === "string") {
|
|
24
|
-
return subSequence + sequence.slice(0, range.end + 1);
|
|
25
|
-
} else {
|
|
26
|
-
return (subSequence as T[]).concat(
|
|
27
|
-
sequence.slice(0, range.end + 1) as T[]
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
} else {
|
|
31
|
-
return sequence.slice(range.start, range.end + 1);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import getYOffsetsForPotentiallyCircularRanges from "./getYOffsetsForPotentiallyCircularRanges.js";
|
|
3
|
-
describe("getYOffsetsForPotentiallyCircularRanges", function () {
|
|
4
|
-
it("returns correct yOffset for overlapping ranges", function () {
|
|
5
|
-
const ranges = [
|
|
6
|
-
{ start: 0, end: 10, id: "1" },
|
|
7
|
-
{ start: 5, end: 20, id: "2" },
|
|
8
|
-
{ start: 15, end: 25, id: "3" }
|
|
9
|
-
];
|
|
10
|
-
getYOffsetsForPotentiallyCircularRanges(ranges, false);
|
|
11
|
-
expect(ranges).to.deep.equal([
|
|
12
|
-
{ start: 0, end: 10, id: "1", yOffset: 0 },
|
|
13
|
-
{ start: 5, end: 20, id: "2", yOffset: 1 },
|
|
14
|
-
{ start: 15, end: 25, id: "3", yOffset: 0 }
|
|
15
|
-
]);
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/invertRange.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
|
-
import normalizePositionByRangeLength from "./normalizePositionByRangeLength";
|
|
4
|
-
import provideInclusiveOptions from "./provideInclusiveOptions";
|
|
5
|
-
export default provideInclusiveOptions(invertRange);
|
|
6
|
-
|
|
7
|
-
function invertRange(
|
|
8
|
-
rangeOrCaret: Range | number,
|
|
9
|
-
rangeMax: number
|
|
10
|
-
): Range | undefined {
|
|
11
|
-
if (typeof rangeOrCaret !== "number" && rangeOrCaret.start > -1) {
|
|
12
|
-
const start = rangeOrCaret.end + 1;
|
|
13
|
-
const end = rangeOrCaret.start - 1;
|
|
14
|
-
return {
|
|
15
|
-
start: normalizePositionByRangeLength(start, rangeMax, false),
|
|
16
|
-
end: normalizePositionByRangeLength(end, rangeMax, false)
|
|
17
|
-
};
|
|
18
|
-
} else if (typeof rangeOrCaret === "number" && rangeOrCaret > -1) {
|
|
19
|
-
return {
|
|
20
|
-
start: normalizePositionByRangeLength(rangeOrCaret, rangeMax, false),
|
|
21
|
-
end: normalizePositionByRangeLength(rangeOrCaret - 1, rangeMax, false)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Range } from "./types";
|
|
2
|
-
|
|
3
|
-
import getEachPositionInRangeAsArray from "./getEachPositionInRangeAsArray";
|
|
4
|
-
|
|
5
|
-
export default function loopEachPositionInRange(
|
|
6
|
-
range: Range,
|
|
7
|
-
rangeMax: number,
|
|
8
|
-
func: (pos: number) => void
|
|
9
|
-
) {
|
|
10
|
-
getEachPositionInRangeAsArray(range, rangeMax).map(func);
|
|
11
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { assign } from "lodash-es";
|
|
2
|
-
|
|
3
|
-
type Options = {
|
|
4
|
-
inclusive1BasedEnd?: boolean;
|
|
5
|
-
inclusive1BasedStart?: boolean;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export default function provideInclusiveOptions<
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
T extends (...args: any[]) => any
|
|
11
|
-
>(
|
|
12
|
-
funToWrap: T
|
|
13
|
-
): (
|
|
14
|
-
...args: [...Parameters<T>, options?: Options]
|
|
15
|
-
) => ReturnType<T> {
|
|
16
|
-
return function (
|
|
17
|
-
this: unknown,
|
|
18
|
-
...args: [...Parameters<T>, options?: Options]
|
|
19
|
-
): ReturnType<T> {
|
|
20
|
-
const options = args[args.length - 1] as Options | undefined;
|
|
21
|
-
if (
|
|
22
|
-
options &&
|
|
23
|
-
(options.inclusive1BasedEnd || options.inclusive1BasedStart)
|
|
24
|
-
) {
|
|
25
|
-
args.forEach(function (arg, index) {
|
|
26
|
-
// cast arg to check for start/end
|
|
27
|
-
const potentialRange = arg as { start?: number; end?: number } | null;
|
|
28
|
-
if (
|
|
29
|
-
potentialRange &&
|
|
30
|
-
typeof potentialRange.start === "number" &&
|
|
31
|
-
potentialRange.start > -1 &&
|
|
32
|
-
options.inclusive1BasedStart
|
|
33
|
-
) {
|
|
34
|
-
args[index] = assign(potentialRange, {
|
|
35
|
-
start: potentialRange.start - 1
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (
|
|
39
|
-
potentialRange &&
|
|
40
|
-
typeof potentialRange.end === "number" &&
|
|
41
|
-
potentialRange.end > -1 &&
|
|
42
|
-
options.inclusive1BasedEnd
|
|
43
|
-
) {
|
|
44
|
-
args[index] = assign(potentialRange, {
|
|
45
|
-
end: potentialRange.end - 1
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
51
|
-
let returnVal = (funToWrap as Function).apply(this, args);
|
|
52
|
-
const potentialReturn = returnVal as {
|
|
53
|
-
start?: number;
|
|
54
|
-
end?: number;
|
|
55
|
-
} | null;
|
|
56
|
-
|
|
57
|
-
if (
|
|
58
|
-
potentialReturn &&
|
|
59
|
-
typeof potentialReturn.start === "number" &&
|
|
60
|
-
potentialReturn.start > -1 &&
|
|
61
|
-
options &&
|
|
62
|
-
options.inclusive1BasedStart
|
|
63
|
-
) {
|
|
64
|
-
returnVal = assign(potentialReturn, {
|
|
65
|
-
start: potentialReturn.start + 1
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (
|
|
69
|
-
potentialReturn &&
|
|
70
|
-
typeof potentialReturn.end === "number" &&
|
|
71
|
-
potentialReturn.end > -1 &&
|
|
72
|
-
options &&
|
|
73
|
-
options.inclusive1BasedEnd
|
|
74
|
-
) {
|
|
75
|
-
returnVal = assign(potentialReturn, { end: potentialReturn.end + 1 });
|
|
76
|
-
}
|
|
77
|
-
return returnVal as ReturnType<T>;
|
|
78
|
-
};
|
|
79
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface Range {
|
|
2
|
-
start: number;
|
|
3
|
-
end: number;
|
|
4
|
-
type?: string;
|
|
5
|
-
locations?: Range[];
|
|
6
|
-
overlapsSelf?: boolean;
|
|
7
|
-
yOffset?: number;
|
|
8
|
-
aminoAcids?: unknown[];
|
|
9
|
-
forward?: boolean;
|
|
10
|
-
notes?: Record<string, unknown> | string;
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
}
|
package/types.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface Range {
|
|
2
|
-
start: number;
|
|
3
|
-
end: number;
|
|
4
|
-
type?: string;
|
|
5
|
-
locations?: Range[];
|
|
6
|
-
overlapsSelf?: boolean;
|
|
7
|
-
yOffset?: number;
|
|
8
|
-
aminoAcids?: unknown[];
|
|
9
|
-
forward?: boolean;
|
|
10
|
-
notes?: Record<string, unknown> | string;
|
|
11
|
-
[key: string]: unknown;
|
|
12
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|