Skip to content

Instantly share code, notes, and snippets.

@tjkhara
Created November 11, 2020 16:58
Show Gist options
  • Select an option

  • Save tjkhara/1abc37ae2714d192127a82e82e7b157d to your computer and use it in GitHub Desktop.

Select an option

Save tjkhara/1abc37ae2714d192127a82e82e7b157d to your computer and use it in GitHub Desktop.
Misc clean up

Misc clean up

How to not accept things that are strings

model -> register function

call this.cleanUp()

Make this function above validate function

User.prototype.cleanUp = function() {
	if(typeof(this.data.username) != "string") {this.data.username = ""}
	if(typeof(this.data.email) != "string") {this.data.email = ""}
	if(typeof(this.data.password) != "string") {this.data.password = ""}
}

For any other properties ignore them

// get rid of bogus properties
this.data = {
	username = this.data.username.trim().toLowerCase(),
	email = this.data.email.trim().toLowerCase(),
	password = this.data.password
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment