Skip to content

Commit

Permalink
remove lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
timche committed Jan 26, 2024
1 parent 7f3099f commit 21ae83b
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 68 deletions.
61 changes: 15 additions & 46 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@material-ui/core": "^3.9.1",
"array-shuffle": "^3.0.0",
"camelcase-keys": "^4.2.0",
"copy-text-to-clipboard": "^1.0.4",
"country-list": "^2.1.0",
Expand All @@ -29,7 +30,6 @@
"dom-chef": "^5.1.0",
"js-cookie": "^2.2.1",
"ky": "^0.11.1",
"lodash": "^4.17.10",
"lucide-react": "^0.314.0",
"mem": "^4.0.0",
"p-memoize": "^1.0.0",
Expand Down
9 changes: 7 additions & 2 deletions src/content/features/add-player-profile-matches-demo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'dom-chef'
import get from 'lodash/get'
import select from 'select-dom'
import createButton from '../components/button'
import {
Expand Down Expand Up @@ -67,9 +66,15 @@ export default async (statsContentElement) => {
text: 'Watch Demo',
onClick: async (e) => {
e.stopPropagation()

const match = await getMatch(matchId)

if (!match) {
return
}

const demoUrl =
get(match, 'externalMatches[0].stats.demoFileUrl') ||
match.externalMatches?.[0]?.stats?.demoFileUrl ||
match.demoUrl ||
match.demoUrLs[0]

Expand Down
4 changes: 2 additions & 2 deletions src/content/features/add-player-profile-matches-elo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'dom-chef'
import random from 'lodash/random'
import select from 'select-dom'
import { randomNumber } from '../../shared/utils'
import {
hasFeatureAttribute,
setFeatureAttribute,
Expand Down Expand Up @@ -108,7 +108,7 @@ export default async (statsContentElement) => {
opacity: selfIsFreeMember && 0.33,
}}
>
{selfIsFreeMember ? random(1000, 3000) : newElo}
{selfIsFreeMember ? randomNumber(1000, 3000) : newElo}
</span>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions src/content/features/add-sidebar-matches-elo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'dom-chef'
import random from 'lodash/random'
import select from 'select-dom'
import { IS_FACEIT_BETA } from '../../shared/faceit-beta'
import { randomNumber } from '../../shared/utils'
import {
hasFeatureAttribute,
setFeatureAttribute,
Expand Down Expand Up @@ -96,7 +96,7 @@ export default async () => {
opacity: selfIsFreeMember && 0.33,
}}
>
{selfIsFreeMember ? random(1000, 3000) : newElo}
{selfIsFreeMember ? randomNumber(1000, 3000) : newElo}
</span>
</div>,
matchTypeElement,
Expand Down
6 changes: 4 additions & 2 deletions src/content/features/click-match-room-veto-maps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import shuffle from 'lodash/shuffle'
import arrayShuffle from 'array-shuffle'
import select from 'select-dom'
import storage from '../../shared/storage'
import {
Expand Down Expand Up @@ -43,7 +43,9 @@ export default async (parentElement) => {
let autoVetoItems = matchRoomAutoVetoMapItems.map((m) => maps.csgo[m] || m)

if (shuffleMaps) {
const shuffledItems = shuffle(autoVetoItems.splice(0, shuffleMapsAmount))
const shuffledItems = arrayShuffle(
autoVetoItems.splice(0, shuffleMapsAmount),
)
autoVetoItems.unshift(...shuffledItems)
}

Expand Down
10 changes: 5 additions & 5 deletions src/content/helpers/elo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import isNumber from 'lodash/isNumber'
import round from 'lodash/round'
import mem from 'mem'
import { getMatchmakingQueue } from './faceit-api'

Expand All @@ -11,8 +9,8 @@ export function estimateRatingChange(elo1, elo2, K = 50) {
const eloDiff = elo2 - elo1
const percentage = 1 / (1 + 10 ** (eloDiff / 400))

const gain = round(K * (1 - percentage))
const loss = round(K * (0 - percentage))
const gain = Math.round(K * (1 - percentage))
const loss = Math.round(K * (0 - percentage))

return {
gain: gain || 1,
Expand Down Expand Up @@ -90,7 +88,9 @@ export async function getEloChangesByMatches(matches) {
const previousElo = previousMatch.elo && normalizeElo(previousMatch.elo)
const newElo = match.elo && normalizeElo(match.elo)
const eloDiff =
isNumber(previousElo) && isNumber(newElo) ? newElo - previousElo : null
typeof previousElo === 'number' && typeof newElo === 'number'
? newElo - previousElo
: null

if (
!eloDiff ||
Expand Down
4 changes: 1 addition & 3 deletions src/content/helpers/match-room.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import head from 'lodash/head'
import isEmpty from 'lodash/isEmpty'
import mem from 'mem'
import select from 'select-dom'
import { getCurrentPath } from './location'
Expand Down Expand Up @@ -91,7 +89,7 @@ export function mapPlayersToPartyColors(
let partyColor

if (isPremade) {
partyColor = isEmpty(acc) ? pickColor() : head(acc).partyColor
partyColor = acc.length === 0 ? pickColor() : acc[0].partyColor
} else if (curr.activeTeamId || !isTeamV1Element) {
let partyMember
if (isTeamV1Element) {
Expand Down
5 changes: 2 additions & 3 deletions src/content/helpers/user-settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import throttle from 'lodash/throttle'
import browser from 'webextension-polyfill'
import storage from '../../shared/storage'

Expand All @@ -19,7 +18,7 @@ export const runFeatureIf = async (option, feature, parent) => {
}
}

export const notifyIf = throttle(async (option, message) => {
export const notifyIf = async (option, message) => {
const options = await storage.getAll()

if (!options.notifyDisabled && options[option]) {
Expand All @@ -28,4 +27,4 @@ export const notifyIf = throttle(async (option, message) => {
...message,
})
}
}, 500)
}
5 changes: 3 additions & 2 deletions src/popup/sections/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { detect } from 'detect-browser'
import capitalize from 'lodash/capitalize'
import React from 'react'
import browser from 'webextension-polyfill'
import ListItemLink from '../components/list-item-link'
Expand All @@ -17,7 +16,9 @@ export default () => (
subreddit={encodeURI(
`submit?selftext=true&text=\n\n\n---\n\nVersion: ${
browser.runtime.getManifest().version
}\nBrowser: ${capitalize(userBrowser.name)} (${userBrowser.version})`,
}\nBrowser: ${userBrowser.name[0].toUpperCase()}${userBrowser.name.slice(
1,
)} (${userBrowser.version})`,
)}
/>
<ListItemLink primary="Ask on Reddit" subreddit="submit?selftext=true" />
Expand Down
3 changes: 3 additions & 0 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}

0 comments on commit 21ae83b

Please sign in to comment.