MCPcopy Create free account
hub / github.com/codecombat/codecombat / sanitizeStateName

Function sanitizeStateName

app/core/utils.js:1206–1220  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

1204 // returns null if can't find sanitized name in the state map
1205
1206 const sanitizeStateName = function (name) {
1207 if (!_.isString(name)) {
1208 return null
1209 }
1210 // bad whitespace remains bad whitespace e.g. "O hi o" is not valid
1211 name = name.trim().toLowerCase().replace(/[^a-z\s]/g, '').replace(/\s+/g, ' ')
1212 let tokens = name.split(/\s+/)
1213 tokens = _.map(tokens, token => token.charAt(0).toUpperCase() + token.slice(1))
1214 // account for District of Columbia
1215 if (tokens.length > 2) {
1216 tokens[1] = tokens[1].toLowerCase()
1217 }
1218 name = tokens.join(' ')
1219 if (stateCodesByName[name]) { return name } else { return null }
1220 }
1221
1222 // returns a valid state code else null
1223

Callers 1

getStateCodeByStateNameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected