From cc8665404801db1c042b0b4d52dc18439a3b50b1 Mon Sep 17 00:00:00 2001 From: Aleksa Kis <59057989+aleksaKis@users.noreply.github.com> Date: Tue, 4 Jan 2022 12:19:31 +0100 Subject: [PATCH] chore(challenges-utils): Typescript migration of Challenges util (#44663) --- .../templates/Challenges/utils/{index.js => index.ts} | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) rename client/src/templates/Challenges/utils/{index.js => index.ts} (71%) diff --git a/client/src/templates/Challenges/utils/index.js b/client/src/templates/Challenges/utils/index.ts similarity index 71% rename from client/src/templates/Challenges/utils/index.js rename to client/src/templates/Challenges/utils/index.ts index ea3eb25c6b..5142978887 100644 --- a/client/src/templates/Challenges/utils/index.js +++ b/client/src/templates/Challenges/utils/index.ts @@ -2,19 +2,24 @@ import envData from '../../../../../config/env.json'; const { forumLocation } = envData; -export function getGuideUrl({ forumTopicId, title = '' }) { +interface GuideData { + forumTopicId: number; + title?: string; +} + +export function getGuideUrl({ forumTopicId, title = '' }: GuideData): string { title = encodeURIComponent(title); return forumTopicId ? `https://forum.freecodecamp.org/t/${forumTopicId}` : `${forumLocation}/search?q=${title}%20in%3Atitle%20order%3Aviews`; } -export function isGoodXHRStatus(status) { +export function isGoodXHRStatus(status: string): boolean { const statusInt = parseInt(status, 10); return (statusInt >= 200 && statusInt < 400) || statusInt === 402; } -export function transformEditorLink(url) { +export function transformEditorLink(url: string): string { return url .replace( /(\/\/)(?[^.]+)\.(?[^.]+)\.repl\.co\/?/,