MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / normalizeChallengeType

Function normalizeChallengeType

api/src/utils/normalize.ts:97–117  ·  view source on GitHub ↗
(
  challengeType?: Prisma.JsonValue
)

Source from the content-addressed store, hash-verified

95 * @returns The challenge type as a number or null.
96 */
97export const normalizeChallengeType = (
98 challengeType?: Prisma.JsonValue
99): number | null => {
100 if (typeof challengeType === 'number') {
101 return challengeType;
102 } else if (typeof challengeType === 'string') {
103 const parsed = parseInt(challengeType, 10);
104 if (isNaN(parsed)) {
105 throw Error(
106 'Unexpected challengeType value: ' + JSON.stringify(challengeType)
107 );
108 }
109 return parsed;
110 } else if (challengeType === null) {
111 return null;
112 } else {
113 throw Error(
114 'Unexpected challengeType value: ' + JSON.stringify(challengeType)
115 );
116 }
117};
118
119/**
120 * Ensure that the user's profile UI settings are valid.

Callers 3

normalizeChallengesFunction · 0.85
normalize.test.tsFile · 0.85
challengeRoutesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected