string util functions location consistency and comments

This commit is contained in:
Kalle (Sendou) 2021-04-01 23:26:10 +03:00
parent 9d80b3b3d9
commit 1320ed9127
4 changed files with 15 additions and 5 deletions

View File

@ -16,8 +16,8 @@ import {
import { t, Trans } from "@lingui/macro";
import { useRouter } from "next/router";
import { useState } from "react";
import { makeNameUrlFriendly } from "utils/makeNameUrlFriendly";
import { sendData } from "utils/postData";
import { makeNameUrlFriendly } from "utils/strings";
const CreateNewTeamModal = () => {
const router = useRouter();

View File

@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "prisma/client";
import { getMySession } from "utils/api";
import { makeNameUrlFriendly } from "utils/makeNameUrlFriendly";
import { makeNameUrlFriendly } from "utils/strings";
import { teamSchema } from "utils/validators/team";
import { v4 as uuidv4 } from "uuid";

View File

@ -1,3 +0,0 @@
export function makeNameUrlFriendly(name: string) {
return name.trim().replace(/\s\s+/g, " ").toLowerCase().replace(/ /g, "-");
}

View File

@ -13,6 +13,9 @@ export const getLocalizedMonthYearString = (
});
};
/**
* Return medal emoji for top 3, otherwise returns the number as string.
*/
export const getRankingString = (ranking: number) => {
switch (ranking) {
case 1:
@ -27,8 +30,18 @@ export const getRankingString = (ranking: number) => {
}
};
export function makeNameUrlFriendly(name: string) {
return name.trim().replace(/\s\s+/g, " ").toLowerCase().replace(/ /g, "-");
}
// User attributes - should be virtuals in future if support gets added to Prisma
/**
* Takes user object and returns the formatted username morphing it with the Discord discriminator.
* @example
* // returns "Sendou#0043"
* getFullUsername({username: "Sendou", discriminator: "0043"})
*/
export const getFullUsername = ({
username,
discriminator,