Skip to content

Commit

Permalink
fix: replace lodash with es-toolkit (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Feb 2, 2025
1 parent 0f17331 commit 465075d
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 44 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
"cssnano": "7.0.6",
"date-fns": "4.1.0",
"dotenv": "16.4.7",
"es-toolkit": "1.32.0",
"fastify": "5.2.1",
"fastify-plugin": "5.0.1",
"fastify-type-provider-zod": "4.0.2",
"generate-password": "1.7.1",
"jsonwebtoken": "9.0.2",
"lodash-es": "4.17.21",
"marked": "15.0.6",
"mime": "4.0.6",
"mongodb": "6.13.0",
Expand All @@ -66,8 +66,6 @@
"@tsconfig/strictest": "2.0.5",
"@types/eslint__js": "8.42.3",
"@types/jsonwebtoken": "9.0.8",
"@types/lodash": "4.17.15",
"@types/lodash-es": "4.17.12",
"@types/node": "22.13.0",
"@types/openid": "2.0.5",
"@types/postcss-import": "14.0.3",
Expand Down
34 changes: 8 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memoize } from 'lodash-es'
import { memoize } from 'es-toolkit'
import { servemeTf } from '../../../../serveme-tf'
import getUnicodeFlagIcon from 'country-flag-icons/unicode'
import { configuration } from '../../../../configuration'
Expand Down
4 changes: 2 additions & 2 deletions src/games/pick-teams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict } from 'node:assert'
import { meanBy } from 'lodash-es'
import { meanBy } from 'es-toolkit'
import type { SteamId64 } from '../shared/types/steam-id-64'
import type { Tf2ClassName } from '../shared/types/tf2-class-name'
import { Tf2Team } from '../shared/types/tf2-team'
Expand Down Expand Up @@ -108,7 +108,7 @@ interface TeamLineupWithSkillAverage extends TeamLineup {
}

function calculateAverageSkill(lineup: TeamLineup): TeamLineupWithSkillAverage {
return { ...lineup, skillAverage: meanBy(lineup.lineup, 'skill') }
return { ...lineup, skillAverage: meanBy(lineup.lineup, ({ skill }) => skill) }
}

interface LineupWithSkillAverageDifference extends PossibleLineup {
Expand Down
2 changes: 1 addition & 1 deletion src/games/plugins/auto-cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fp from 'fastify-plugin'
import { events } from '../../events'
import { whenGameEnds } from '../when-game-ends'
import { delay } from 'lodash-es'
import { delay } from 'es-toolkit/compat'
import { secondsToMilliseconds } from 'date-fns'
import { cleanup } from '../rcon/cleanup'
import { assertIsError } from '../../utils/assert-is-error'
Expand Down
2 changes: 1 addition & 1 deletion src/games/plugins/auto-close-games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { safe } from '../../utils/safe'
import { GameState, type GameModel } from '../../database/models/game.model'
import { configuration } from '../../configuration'
import { SlotStatus } from '../../database/models/game-slot.model'
import { debounce } from 'lodash-es'
import { debounce } from 'es-toolkit'
import { logger } from '../../logger'
import { forceEnd } from '../force-end'
import { GameEndedReason } from '../../database/models/game-event.model'
Expand Down
6 changes: 3 additions & 3 deletions src/games/plugins/launch-new-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QueueState } from '../../database/models/queue-state.model'
import { logger } from '../../logger'
import { create } from '../create'
import { queue } from '../../queue'
import { debounce } from 'lodash-es'
import { debounce } from 'es-toolkit'

const launchGame = debounce(async () => {
logger.info('launching game')
Expand All @@ -19,7 +19,7 @@ export default fp(
events.on('queue/state:updated', async ({ state }) => {
if (state === QueueState.launching) {
try {
await launchGame()
launchGame()
} catch (error) {
logger.error(error)
}
Expand All @@ -28,7 +28,7 @@ export default fp(

app.addHook('onListen', async () => {
if ((await queue.getState()) === QueueState.launching) {
await launchGame()
launchGame()
}
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/games/rcon/configure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { secondsToMilliseconds } from 'date-fns'
import { deburr } from 'lodash-es'
import { deburr } from 'es-toolkit'
import { configuration } from '../../configuration'
import { collections } from '../../database/collections'
import { GameEventType } from '../../database/models/game-event.model'
Expand Down
2 changes: 1 addition & 1 deletion src/games/rcon/whitelist-player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deburr } from 'lodash-es'
import { deburr } from 'es-toolkit'
import { collections } from '../../database/collections'
import type { GameModel } from '../../database/models/game.model'
import type { SteamId64 } from '../../shared/types/steam-id-64'
Expand Down
2 changes: 1 addition & 1 deletion src/players/views/html/player-list.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'node:path'
import { NavigationBar } from '../../../html/components/navigation-bar'
import { Layout } from '../../../html/layout'
import type { PlayerModel } from '../../../database/models/player.model'
import { deburr } from 'lodash-es'
import { deburr } from 'es-toolkit'
import { collections } from '../../../database/collections'
import type { User } from '../../../auth/types/user'
import { Page } from '../../../html/components/page'
Expand Down
2 changes: 1 addition & 1 deletion src/queue/get-map-winner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { maxBy, sample } from 'lodash-es'
import { maxBy, sample } from 'es-toolkit'
import { collections } from '../database/collections'
import { logger } from '../logger'

Expand Down
2 changes: 1 addition & 1 deletion src/serveme-tf/pick-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServerId } from '@tf2pickup-org/serveme-tf-client'
import { configuration } from '../configuration'
import { sample } from 'lodash-es'
import { sample } from 'es-toolkit'

interface ServerData {
id: ServerId
Expand Down
4 changes: 2 additions & 2 deletions src/statistics/views/html/played-maps-count.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { concat, dropRight, takeRight } from 'lodash-es'
import { dropRight, takeRight } from 'es-toolkit'
import { getPlayedMapsCount, type PlayedMapCount } from '../../get-played-maps-count'

export async function PlayedMapsCount() {
Expand Down Expand Up @@ -58,7 +58,7 @@ function toChartData(data: PlayedMapCount[]) {
mapName: 'other',
count: lastFewMaps.reduce((sum: number, d: PlayedMapCount) => sum + d.count, 0),
}
const topMaps = concat(dropRight(data, Math.max(0, data.length - 8)), other)
const topMaps = dropRight(data, Math.max(0, data.length - 8)).concat(other)

return {
labels: topMaps.map((d: PlayedMapCount) => d.mapName),
Expand Down

0 comments on commit 465075d

Please sign in to comment.