`type = type.toLowerCase().replace(/\s+/g, "")` should be fine here. Any reason to leave it commented out?