-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split team name from username field
- Loading branch information
Showing
7 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ export interface RawRecord { | |
|
||
interface User { | ||
username: string | ||
team?: string | ||
steamId: string | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import test from 'ava' | ||
|
||
import { splitUserTeam } from './index.js' | ||
|
||
test('splitUserTeam returns username without team name', t => { | ||
t.deepEqual(splitUserTeam('username'), { | ||
username: 'username' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[username'), { | ||
username: '[username' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[username]'), { | ||
username: '[username]' | ||
}) | ||
}) | ||
|
||
test('splitUserTeam returns username with team name', t => { | ||
t.deepEqual(splitUserTeam('[team]username'), { | ||
username: 'username', | ||
team: 'team' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[team] username'), { | ||
username: 'username', | ||
team: 'team' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[team] [username]'), { | ||
username: '[username]', | ||
team: 'team' | ||
}) | ||
}) | ||
|
||
test('splitUserTeam returns username with team name and removes bad taste teams', t => { | ||
t.deepEqual(splitUserTeam('[CTR SUCKS]username'), { | ||
username: 'username' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[CTR SUCKS] username'), { | ||
username: 'username' | ||
}) | ||
|
||
t.deepEqual(splitUserTeam('[CTR SUCKS] [username]'), { | ||
username: '[username]' | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const removeBadTasteTeams = (input: string) => | ||
['CTR SUCKS'].includes(input) ? undefined : input | ||
|
||
export const splitUserTeam = (input: string) => { | ||
if (input.startsWith('[')) { | ||
const [team, ...username] = input.split(']') | ||
const formattedUsername = username.join(']').trim() | ||
const formattedTeam = removeBadTasteTeams(team.slice(1)) | ||
|
||
if (!formattedUsername) { | ||
return { | ||
username: input | ||
} | ||
} | ||
|
||
if (!formattedTeam) { | ||
return { | ||
username: formattedUsername | ||
} | ||
} | ||
|
||
return { | ||
team: formattedTeam, | ||
username: formattedUsername | ||
} | ||
} else { | ||
return { | ||
username: input | ||
} | ||
} | ||
} |