Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all uses of top-level lodash import #1882

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/consumer-client/src/pages/examples/gpc-proof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { PODPCDPackage } from "@pcd/pod-pcd";
import { SemaphoreIdentityPCDPackage } from "@pcd/semaphore-identity-pcd";
import { emptyStrToUndefined } from "@pcd/util";
import JSONBig from "json-bigint";
import _ from "lodash";
import isEqual from "lodash/isEqual";
import { useEffect, useState } from "react";
import { CodeLink, CollapsableCode, HomeLink } from "../../components/Core";
import { ExampleContainer } from "../../components/ExamplePage";
Expand Down Expand Up @@ -413,14 +413,14 @@ async function verifyProof(
} catch (configError) {
return { valid: false, err: "Invalid proof config." };
}
const sameConfig = _.isEqual(localBoundConfig, pcd.claim.config);
const sameConfig = isEqual(localBoundConfig, pcd.claim.config);
if (!sameConfig) {
return { valid: false, err: "Config does not match." };
}

// Check for equality of membership lists as sets, since the elements are
// sorted by hash before being fed into circuits.
const sameMembershipLists = _.isEqual(
const sameMembershipLists = isEqual(
membershipListsToSets(pcd.claim.revealed.membershipLists ?? {}),
membershipLists === undefined
? {}
Expand Down
4 changes: 2 additions & 2 deletions apps/generic-issuance-client/src/components/FancyEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Spinner } from "@chakra-ui/react";
import { Editor, Monaco } from "@monaco-editor/react";
import _ from "lodash";
import merge from "lodash/merge";
import { editor } from "monaco-editor";
import React, {
useCallback,
Expand Down Expand Up @@ -56,7 +56,7 @@ export const FancyEditor = React.forwardRef(

const mergedEditorOptions =
useMemo<editor.IStandaloneEditorConstructionOptions>(() => {
return _.merge(
return merge(
{
readOnly: readonly,
minimap: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CheckIcon, CopyIcon } from "@chakra-ui/icons";
import { Button, Spacer, useToast } from "@chakra-ui/react";
import { PipelineZuAuthConfig } from "@pcd/passport-interface";
import _ from "lodash";
import isEqual from "lodash/isEqual";
import uniqWith from "lodash/uniqWith";
import { ReactNode, useCallback, useState } from "react";

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ export function PipelineZuAuthConfigSection({
*/
if (!includeProductOptions) {
json = JSON.stringify(
_.uniqWith(
uniqWith(
pipelineZuAuthConfig.map(
({ eventId, eventName, publicKey, pcdType }) =>
({
Expand All @@ -68,7 +69,7 @@ export function PipelineZuAuthConfigSection({
eventName
}) satisfies PipelineZuAuthConfig
),
_.isEqual
isEqual
),
null,
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PipelineDefinition,
PipelineInfoResponseValue
} from "@pcd/passport-interface";
import _ from "lodash";
import isEqual from "lodash/isEqual";
import { ReactNode } from "react";
import { PodLink } from "../../components/Core";
import { pipelineDisplayNameStr } from "../../components/PipelineDisplayUtils";
Expand Down Expand Up @@ -270,7 +270,7 @@ function ExpandAllButton(): ReactNode {
const ctx = useGIContext();
const disabled =
!ctx.pipelineDetailsAccordionState ||
_.isEqual(ctx.pipelineDetailsAccordionState, EXPANDED);
isEqual(ctx.pipelineDetailsAccordionState, EXPANDED);

return (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PipelineInfoResponseValue,
isCSVPipelineDefinition
} from "@pcd/passport-interface";
import _ from "lodash";
import cloneDeep from "lodash/cloneDeep";
import React, { ReactNode, useCallback, useState } from "react";
import styled from "styled-components";
import { AddDataModal } from "../../../components/AddDataModal";
Expand Down Expand Up @@ -81,7 +81,7 @@ export function PipelineActions({
}

setActionInProgress(`Reverting pipeline '${pipeline.id}'...`);
const historicVersion: Partial<PipelineDefinition> = _.cloneDeep(
const historicVersion: Partial<PipelineDefinition> = cloneDeep(
maybeHistoricPipeline
);
historicVersion.timeUpdated = pipeline.timeUpdated;
Expand Down Expand Up @@ -114,7 +114,7 @@ export function PipelineActions({
}

setActionInProgress(`Duplicating pipeline '${pipeline.id}'...`);
const copyDefinition: Partial<PipelineDefinition> = _.cloneDeep(pipeline);
const copyDefinition: Partial<PipelineDefinition> = cloneDeep(pipeline);
delete copyDefinition.id;
delete copyDefinition.ownerUserId;
copyDefinition.options = {
Expand Down Expand Up @@ -179,7 +179,7 @@ export function PipelineActions({
setActionInProgress(
`Changing protection status of pipeline '${pipeline.id}'...`
);
const copyDefinition: Partial<PipelineDefinition> = _.cloneDeep(pipeline);
const copyDefinition: Partial<PipelineDefinition> = cloneDeep(pipeline);
copyDefinition.options = {
...copyDefinition.options,
protected: !pipelineProtected
Expand Down Expand Up @@ -210,7 +210,7 @@ export function PipelineActions({
setActionInProgress(
`Changing pause state of pipeline '${pipeline.id}'...`
);
const copyDefinition: Partial<PipelineDefinition> = _.cloneDeep(pipeline);
const copyDefinition: Partial<PipelineDefinition> = cloneDeep(pipeline);
copyDefinition.options = {
...copyDefinition.options,
paused: !pipelinePaused
Expand Down Expand Up @@ -241,7 +241,7 @@ export function PipelineActions({
setActionInProgress(
`Changing importance of pipeline '${pipeline.id}'...`
);
const copyDefinition: Partial<PipelineDefinition> = _.cloneDeep(pipeline);
const copyDefinition: Partial<PipelineDefinition> = cloneDeep(pipeline);
copyDefinition.options = {
...copyDefinition.options,
important: !pipelineImportant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isReplaceInFolderPermission
} from "@pcd/pcd-collection";
import { sleep } from "@pcd/util";
import _ from "lodash";
import uniq from "lodash/uniq";
import React, {
MouseEvent,
useCallback,
Expand Down Expand Up @@ -545,7 +545,7 @@ function AlreadySubscribed({
};

const navigate = useNavigate();
const folders = _.uniq(
const folders = uniq(
existingSubscription.feed.permissions.map((p) => p.folder)
).sort((a, b) => a.localeCompare(b));
const goToFolder = useCallback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EdDSATicketPCD } from "@pcd/eddsa-ticket-pcd";
import _ from "lodash";
import range from "lodash/range";
import styled from "styled-components";
import { Button } from "../../core";
import { AdhocModal } from "../../modals/AdhocModal";
Expand Down Expand Up @@ -78,7 +78,7 @@ const Container = styled.div<{ index: number; count: number; color: string }>`
padding: 0;
border: 1px solid ${({ color }): string => color};
box-shadow: ${({ index, count, color }): string => {
return [..._.range(-1, -index - 1, -1), ..._.range(1, count - index)]
return [...range(-1, -index - 1, -1), ...range(1, count - index)]
.map((i) => {
const offset = i * 2;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FrogCryptoFolderName } from "@pcd/passport-interface";
import _ from "lodash";
import min from "lodash/min";
import prettyMilliseconds from "pretty-ms";
import { PropsWithChildren, useEffect, useMemo, useState } from "react";
import styled, {
Expand Down Expand Up @@ -108,7 +108,7 @@ function useFetchTimestamp(): number | null {
return null;
}

return _.min(activeFeeds.map((feed) => feed.nextFetchAt)) ?? null;
return min(activeFeeds.map((feed) => feed.nextFetchAt)) ?? null;
} catch (e) {
console.error(e);
return null;
Expand All @@ -131,7 +131,7 @@ function CountDown({
}, [timestamp]);
const [diffText, setDiffText] = useState(
timestamp < Date.now() && !frogcryptoGrayscale
? _.upperCase("Available Now")
? "Available Now".toLocaleUpperCase()
: ""
);

Expand All @@ -142,7 +142,7 @@ function CountDown({
if (frogcryptoGrayscale) {
setDiffText("");
} else if (diffMs < 0) {
setDiffText(_.upperCase("Available Now"));
setDiffText("Available Now".toLocaleUpperCase());
} else {
const diffString = prettyMilliseconds(diffMs, {
millisecondsDecimalDigits: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EdDSAFrogPCD } from "@pcd/eddsa-frog-pcd";
import _ from "lodash";
import range from "lodash/range";
import { useCallback, useState } from "react";
import { useSwipeable } from "react-swipeable";
import styled from "styled-components";
Expand Down Expand Up @@ -78,7 +78,7 @@ const Container = styled.div<{ index: number; count: number; color: string }>`
padding: 0;
border: 1px solid ${({ color }): string => color};
box-shadow: ${({ index, count, color }): string => {
return [..._.range(-1, -index - 1, -1), ..._.range(1, count - index)]
return [...range(-1, -index - 1, -1), ...range(1, count - index)]
.map((i) => {
const offset = i * 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
SubscriptionErrorType
} from "@pcd/passport-interface";
import { Separator } from "@pcd/passport-ui";
import _ from "lodash";
import keyBy from "lodash/keyBy";
import maxBy from "lodash/maxBy";
import prettyMilliseconds from "pretty-ms";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { toast } from "react-hot-toast";
Expand Down Expand Up @@ -47,7 +48,7 @@ export function GetFrogTab({
}): JSX.Element {
const { value: subManager } = useSubscriptions();
const userStateByFeedId = useMemo(
() => _.keyBy(userState.feeds, (feed) => feed.feedId),
() => keyBy(userState.feeds, (feed) => feed.feedId),
[userState]
);

Expand Down Expand Up @@ -194,7 +195,10 @@ const SearchButton = ({
refreshUserState,
subManager
]);
const name = useMemo(() => `search ${_.upperCase(feed.name)}`, [feed.name]);
const name = useMemo(
() => `search ${feed.name.toLocaleUpperCase()}`,
[feed.name]
);
const freerolls = FROG_FREEROLLS + 1 - (score ?? 0);
const ButtonComponent = useMemo(() => {
switch (feed.name) {
Expand Down Expand Up @@ -241,7 +245,7 @@ const useGetLastFrog = (): (() => EdDSAFrogPCD | undefined) => {
const pcdCollection = usePCDCollection();
const getLastFrog = useCallback(
() =>
_.maxBy(
maxBy(
pcdCollection
.getAllPCDsInFolder(FrogCryptoFolderName)
.filter(isEdDSAFrogPCD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ErrorMessage, Separator } from "@pcd/passport-ui";
import { SerializedPCD } from "@pcd/pcd-types";
import { getErrorMessage } from "@pcd/util";
import _ from "lodash";
import upperFirst from "lodash/upperFirst";
import prettyMilliseconds from "pretty-ms";
import { useEffect, useMemo, useState } from "react";
// react-table-lite does not have types
Expand Down Expand Up @@ -206,7 +206,7 @@ function feedParser(data: string): FrogCryptoDbFeedData[] {
Object.keys(Biome).reduce((acc, biome) => {
const dropWeightScaler =
rawFeed[
`biomes${_.upperFirst(
`biomes${upperFirst(
biome.replace(/\s/, "").toLowerCase()
)}Dropweightscaler`
];
Expand Down Expand Up @@ -265,7 +265,7 @@ function feedUnparser(feeds: FrogCryptoDbFeedData[]): string {
const biomeConfig = feed.feed.biomes[biome];
if (biomeConfig) {
acc[
`biomes${_.upperFirst(
`biomes${upperFirst(
biome.replace(/\s/, "").toLowerCase()
)}Dropweightscaler`
] = biomeConfig.dropWeightScaler;
Expand All @@ -292,7 +292,10 @@ export function DataTable({
}));
const keys =
data.length > 0
? _.chain(data).map(Object.keys).flatten().uniq().value()
? data
.map(Object.keys)
.flat()
.filter((key, index, self) => self.indexOf(key) === index)
: [];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { ErrorMessage, Separator } from "@pcd/passport-ui";
import { SerializedPCD } from "@pcd/pcd-types";
import { getErrorMessage } from "@pcd/util";
import _ from "lodash";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
// react-table-lite does not have types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -277,7 +276,10 @@ export function DataTable({
}): JSX.Element {
const keys =
data.length > 0
? _.chain(data).map(Object.keys).flatten().uniq().value()
? data
.map(Object.keys)
.flat()
.filter((key, index, self) => self.indexOf(key) === index)
: [];

const dataWithChecked = data.map((row) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
FrogCryptoScore,
requestFrogCryptoGetScoreboard
} from "@pcd/passport-interface";
import _ from "lodash";
import orderBy from "lodash/orderBy";
import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
import styled from "styled-components";
import { appConfig } from "../../../src/appConfig";
Expand Down Expand Up @@ -225,7 +225,7 @@ export function groupScores(scores: FrogCryptoScore[]): {
scores: [] as FrogCryptoScore[]
})).reverse();

_.orderBy(scores, ["score"], ["desc"]).forEach((score) => {
orderBy(scores, ["score"], ["desc"]).forEach((score) => {
const index = SCORES.findIndex((item) => item.score > score.score);
const curr = SCORES[index === -1 ? SCORES.length - 1 : index - 1];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PCDCrypto } from "@pcd/passport-crypto";
import _ from "lodash";
import startCase from "lodash/startCase";
import { useCallback, useEffect, useState } from "react";
import { bigintToUint8Array, uint8arrayToBigint } from "../../../src/util";

Expand Down Expand Up @@ -39,7 +39,7 @@ export function useUsernameGenerator():

return lowercase
? randomAdjective + "_" + randomAnimal
: _.startCase(`${randomAdjective} ${randomAnimal}`);
: startCase(`${randomAdjective} ${randomAnimal}`);
} catch (e) {
console.debug("Error in useUsernameGenerator", e);
return "An Unknown Toad";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
ZKEdDSAEventTicketPCDPackage,
isZKEdDSAEventTicketPCDPackage
} from "@pcd/zk-eddsa-event-ticket-pcd";
import _ from "lodash";
import { useCallback, useEffect, useMemo, useState } from "react";
import styled from "styled-components";
import { appConfig } from "../../../src/appConfig";
Expand Down Expand Up @@ -163,7 +162,7 @@ export function GenericProveSection<T extends PCDPackage = PCDPackage>({
const result: SerializedPCD<ZKEdDSAEventTicketPCD>[] = [];

for (const t of relevantPCDs) {
const argsClone = _.clone(args) as ArgsOf<
const argsClone = structuredClone(args) as ArgsOf<
typeof ZKEdDSAEventTicketPCDPackage
>;
argsClone.ticket.value = await EdDSATicketPCDPackage.serialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
SemaphoreSignaturePCDArgs,
SemaphoreSignaturePCDPackage
} from "@pcd/semaphore-signature-pcd";
import { cloneDeep } from "lodash";
import cloneDeep from "lodash/cloneDeep";
import { ReactNode, useCallback, useState } from "react";
import styled from "styled-components";
import { appConfig } from "../../../src/appConfig";
Expand Down
Loading
Loading