Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tx3-bang-reader
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
tx3-bang-reader
Commits
0f8bc252
Commit
0f8bc252
authored
Jul 01, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use function instead
parent
d1bc3354
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
23 deletions
+17
-23
src/playerlist.ts
src/playerlist.ts
+13
-18
tests/test.ts
tests/test.ts
+4
-5
No files found.
src/playerlist.ts
View file @
0f8bc252
...
...
@@ -33,22 +33,17 @@ function getPlayerRowFromTree(tree: HTML.Tree): PlayerRow {
}
}
export
class
PlayerList
{
rows
:
PlayerRow
[];
private
parseRows
(
content
:
string
)
{
this
.
rows
=
[];
const
parsedContent
=
HTML
(
content
);
const
tablePos
=
findNodeIndexByTag
(
parsedContent
,
"
table
"
,
[]);
const
tableTree
=
getDepthOfTree
(
parsedContent
,
tablePos
);
const
playerPoses
=
findAllNodeIndex
(
tableTree
,
(
node
)
=>
{
return
typeof
(
node
)
!==
"
string
"
&&
node
.
tag
===
"
tr
"
&&
node
.
attrs
.
class
!==
"
trTop2
"
;
},
[]);
this
.
rows
=
playerPoses
.
map
(
pos
=>
{
const
tree
=
getDepthOfTree
(
tableTree
,
pos
);
return
getPlayerRowFromTree
(
tree
);
})
}
constructor
(
content
:
string
)
{
this
.
parseRows
(
content
);
}
export
function
parsePlayerRows
(
content
:
string
)
{
const
parsedContent
=
HTML
(
content
);
const
tablePos
=
findNodeIndexByTag
(
parsedContent
,
"
table
"
,
[]);
const
tableTree
=
getDepthOfTree
(
parsedContent
,
tablePos
);
const
playerPoses
=
findAllNodeIndex
(
tableTree
,
(
node
)
=>
{
return
typeof
(
node
)
!==
"
string
"
&&
node
.
tag
===
"
tr
"
&&
node
.
attrs
.
class
!==
"
trTop2
"
;
},
[]);
return
playerPoses
.
map
(
pos
=>
{
const
tree
=
getDepthOfTree
(
tableTree
,
pos
);
return
getPlayerRowFromTree
(
tree
);
});
}
tests/test.ts
View file @
0f8bc252
import
{
User
}
from
"
../src/user
"
;
import
fs
from
"
fs
"
;
import
{
PlayerList
}
from
"
../src/playerlist
"
;
async
function
main
()
{
let
html
=
await
fs
.
promises
.
readFile
(
"
./tests/
playerlist
.html
"
,
"
utf-8
"
);
console
.
log
(
new
PlayerList
(
htm
l
));
html
=
await
fs
.
promises
.
readFile
(
"
./tests/
playerlist-null
.html
"
,
"
utf-8
"
);
console
.
log
(
new
PlayerList
(
htm
l
));
let
html
=
await
fs
.
promises
.
readFile
(
"
./tests/
28_20588
.html
"
,
"
utf-8
"
);
console
.
log
(
new
User
(
"
28_20588
"
,
html
,
nul
l
));
html
=
await
fs
.
promises
.
readFile
(
"
./tests/
60_46782
.html
"
,
"
utf-8
"
);
console
.
log
(
new
User
(
"
60_46782
"
,
html
,
nul
l
));
}
main
();
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