-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pure uml component #73
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Validators } from "@angular/forms"; | ||
|
||
const getNameValidator = (required: boolean = false) => { | ||
if (required) { | ||
return [Validators.pattern('^[a-zA-Z_][a-zA-Z0-9_]*$'), Validators.required, Validators.max(100)]; | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else here is not necessary, right? |
||
return [Validators.pattern('^[a-zA-Z_][a-zA-Z0-9_]*$'), Validators.max(100)]; | ||
} | ||
} | ||
|
||
const invalidNameMessage = (type: string = '') => { | ||
type = type + ' '; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modifying an input parameter? |
||
return `Please provide a valid ${type}name`; | ||
} | ||
|
||
const getValidationRegex = () => { | ||
return new RegExp('^[a-zA-Z_][a-zA-Z0-9_]*$'); | ||
} | ||
|
||
const nameIsValid = (name: string) => { | ||
const regex = getValidationRegex(); | ||
return regex.test(name) && name.length <= 100; | ||
} | ||
|
||
const getValidationClass = (name: string) => { | ||
const regex = getValidationRegex(); | ||
if (name === '') { | ||
return ''; | ||
} | ||
else if (regex.test(name) && name.length <= 100) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flatten the conditions, what is worse then else is else if ;) |
||
return 'is-valid'; | ||
} else { | ||
return 'is-invalid'; | ||
} | ||
} | ||
|
||
export { | ||
getNameValidator, | ||
invalidNameMessage, | ||
getValidationRegex, | ||
nameIsValid, | ||
getValidationClass, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would turn this to use a conditional operator !value ? value : Object.values(value)