Created
June 29, 2018 14:57
-
-
Save Coutlaw/af8d44e597f05c710b8aeafda70d4736 to your computer and use it in GitHub Desktop.
filter inputs in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mkLender = (assignedLender, category) => { | |
if (assignedLender) { | |
const input = assignedLender.toLowerCase().replace(/ /g, ''); | |
if (input.startsWith("userid:")) { | |
const x = /userid:(\d+)/i.exec(input); | |
if (x != null) | |
return { | |
assignedUser: {"userId": parseInt(x[1])}, | |
category: mkCategory(category) | |
}; | |
else { | |
throw new Error(`Malformated UserId, ${possibleAssignedLenderMessage}`); | |
} | |
} | |
else if (assignedLender.toLowerCase() === "autoassign") { | |
return { | |
assignedUser: assignedLender, | |
category: mkCategory(category) | |
}; | |
} else { | |
throw new Error(`Invalid associated user ${assignedLender}. ${possibleAssignedLenderMessage}`); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment