Skip to content

Commit

Permalink
use ts 3.9.4, fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
dajk committed Aug 22, 2020
1 parent de8f972 commit bcd3e49
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 76 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'import/prefer-default-export': 'off',
'import/no-default-export': 'on',
'import/prefer-default-export': 0,
'import/no-default-export': 0,
'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
},
],
'array-callback-return': 0,
},
settings: {
'import/resolver': {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"rimraf": "^3.0.2",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.2"
"typescript": "3.9.4"
},
"husky": {
"hooks": {
Expand Down
50 changes: 11 additions & 39 deletions src/match-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export async function getStatsByMatchId(matchId: string): Promise<IStats[]> {
const url = `${CONFIG.BASE}/${matchId}`

try {
const body = await (await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})).text()
const body = await (
await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})
).text()

const $ = cheerio.load(body, {
normalizeWhitespace: true,
Expand All @@ -40,24 +42,9 @@ export async function getStatsByMatchId(matchId: string): Promise<IStats[]> {
.find('.players .gtSmartphone-only')
.text()
.replace(/'/g, '')
const playerId = el
.find('.players')
.children('a')
.attr('href')!
const kills = parseInt(
el
.find('td.kd')
.text()
.split('-')[0],
10
)
const deaths = parseInt(
el
.find('td.kd')
.text()
.split('-')[1],
10
)
const playerId = el.find('.players').children('a').attr('href')!
const kills = parseInt(el.find('td.kd').text().split('-')[0], 10)
const deaths = parseInt(el.find('td.kd').text().split('-')[1], 10)
const plusMinus = parseInt(el.find('td.plus-minus').text(), 10)
const adr = parseFloat(el.find('td.adr').text())
const kast = parseFloat(el.find('td.kast').text())
Expand Down Expand Up @@ -89,24 +76,9 @@ export async function getStatsByMatchId(matchId: string): Promise<IStats[]> {
.find('.players .gtSmartphone-only')
.text()
.replace(/'/g, '')
const playerId = el
.find('.players')
.children('a')
.attr('href')!
const kills = parseInt(
el
.find('td.kd')
.text()
.split('-')[0],
10
)
const deaths = parseInt(
el
.find('td.kd')
.text()
.split('-')[1],
10
)
const playerId = el.find('.players').children('a').attr('href')!
const kills = parseInt(el.find('td.kd').text().split('-')[0], 10)
const deaths = parseInt(el.find('td.kd').text().split('-')[1], 10)
const plusMinus = parseInt(el.find('td.plus-minus').text(), 10)
const adr = parseFloat(el.find('td.adr').text())
const kast = parseFloat(el.find('td.kast').text())
Expand Down
20 changes: 10 additions & 10 deletions src/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ export async function getMatches() {
const url = `${CONFIG.BASE}/${CONFIG.MATCHES}`

try {
const body = await (await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})).text()
const body = await (
await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})
).text()

const $ = cheerio.load(body, {
normalizeWhitespace: true,
})

const allContent = $('.upcomingMatch')
const returnArr: any[] = []
const matches: IMatch[] = []

allContent.map((_i, element) => {
const el = $(element)
Expand Down Expand Up @@ -65,7 +67,7 @@ export async function getMatches() {
crest: team2El.find('.matchTeamLogo').attr('src')!,
}

const responseObj: IMatch = {
const response: IMatch = {
id,
link,
time,
Expand All @@ -75,18 +77,16 @@ export async function getMatches() {
teams: [team1, team2],
}

returnArr[returnArr.length] = responseObj

return responseObj
matches[matches.length] = response
})

if (!returnArr.length) {
if (!matches.length) {
throw new Error(
'There are no matches available, something went wrong. Please contact the library maintainer on https://github.com/dajk/hltv-api'
)
}

return returnArr
return matches
} catch (error) {
throw new Error(error)
}
Expand Down
30 changes: 13 additions & 17 deletions src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,27 @@ export async function getResults(): Promise<IResult[]> {
const url = `${CONFIG.BASE}${CONFIG.RESULTS}`

try {
const body = await (await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})).text()
const body = await (
await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})
).text()

const $ = cheerio.load(body, {
normalizeWhitespace: true,
})

const results: IResult[] = []

const resultElements = $('.results-all .result-con')
const results = $(resultElements).map((_i, element) => {
$(resultElements).each((_i, element) => {
const el = $(element).find('tr')
const team1 = el.children('.team-cell').first()
const team2 = el.children('.team-cell').last()
const matchId = $(element)
.children('a')
.attr('href')!
const matchId = $(element).children('a').attr('href')!
const maps = el.find('.map-text')
const result1 = el
.find('.result-score')
.children('span')
.first()
const result2 = el
.find('.result-score')
.children('span')
.last()
const result1 = el.find('.result-score').children('span').first()
const result2 = el.find('.result-score').children('span').last()

const objData: IResult = {
event: el.find('.event-name').text(),
Expand All @@ -64,7 +60,7 @@ export async function getResults(): Promise<IResult[]> {
matchId,
}

return objData
results.push(objData)
})

if (!results.length) {
Expand All @@ -73,7 +69,7 @@ export async function getResults(): Promise<IResult[]> {
)
}

return results as any
return results
} catch (error) {
throw new Error(error)
}
Expand Down
8 changes: 5 additions & 3 deletions src/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export default async function getRSS(type: 'news') {
const url = `${CONFIG.BASE}${CONFIG.RSS}${URL}`

try {
const xml = await (await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})).text()
const xml = await (
await fetch(url, {
headers: { 'User-Agent': 'node-fetch' },
})
).text()
const parser = new xml2js.Parser()

if (!validateXML(xml)) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4898,10 +4898,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2"
integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==
typescript@3.9.4:
version "3.9.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.4.tgz#5aa0a54904b51b96dfd67870ce2db70251802f10"
integrity sha512-9OL+r0KVHqsYVH7K18IBR9hhC82YwLNlpSZfQDupGcfg8goB9p/s/9Okcy+ztnTeHR2U68xq21/igW9xpoGTgA==

union-value@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit bcd3e49

Please sign in to comment.