Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
8bf9a5e0
Commit
8bf9a5e0
authored
Dec 05, 2023
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce `pageLabelInRange` nesting by using an early return
parent
11234150
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
page-range.ts
src/sidebar/util/page-range.ts
+23
-23
No files found.
src/sidebar/util/page-range.ts
View file @
8bf9a5e0
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment