Skip to content

Instantly share code, notes, and snippets.

@Coutlaw
Created June 29, 2018 14:57
Show Gist options
  • Save Coutlaw/af8d44e597f05c710b8aeafda70d4736 to your computer and use it in GitHub Desktop.
Save Coutlaw/af8d44e597f05c710b8aeafda70d4736 to your computer and use it in GitHub Desktop.
filter inputs in javascript
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