Skip to content

Commit

Permalink
better value check for env value
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPhilbin committed Feb 16, 2024
1 parent 258c744 commit c65dfe8
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ import messages from '../Messages'
*/

const validateMinLength = val => {
if(!isNaN(val)) return val | 0
return 150
if(!val) {
// Handle undefined. null and empty string case and default to 150:
if(typeof val === 'string' && val.length === 0) return 150
return 150
}
// Handle 0 separately. Non-strict equals will be true for '0' string value:
if(val == 0) return 0

// Bitwise operator coerces to number value:
return val | 0
}

export const jsSchema = (intl) => {
const instructionsMinLength = validateMinLength(process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH)
const minLengthEnvValue = process.env.REACT_APP_CHALLENGE_INSTRUCTIONS_MIN_LENGTH
const instructionsMinLength = validateMinLength(minLengthEnvValue)

const schemaFields = {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down

0 comments on commit c65dfe8

Please sign in to comment.