Commit 8bf9a5e0 authored by Robert Knight's avatar Robert Knight

Reduce `pageLabelInRange` nesting by using an early return

parent 11234150
......@@ -8,29 +8,29 @@
* specify an empty range.
*/
export function pageLabelInRange(label: string, range: string): boolean {
if (range.includes('-')) {
let [start, end] = range.split('-');
if (!start) {
start = label;
}
if (!end) {
end = label;
}
const [startInt, endInt, labelInt] = [
parseInt(start),
parseInt(end),
parseInt(label),
];
if (
Number.isInteger(startInt) &&
Number.isInteger(endInt) &&
Number.isInteger(labelInt)
) {
return labelInt >= startInt && labelInt <= endInt;
} else {
return false;
}
} else {
if (!range.includes('-')) {
return label === range;
}
let [start, end] = range.split('-');
if (!start) {
start = label;
}
if (!end) {
end = label;
}
const [startInt, endInt, labelInt] = [
parseInt(start),
parseInt(end),
parseInt(label),
];
if (
Number.isInteger(startInt) &&
Number.isInteger(endInt) &&
Number.isInteger(labelInt)
) {
return labelInt >= startInt && labelInt <= endInt;
} else {
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment