-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/wp-105: create common utils function (#850)
* task/wp-105: create common utils function * add check is not a string * prettier * run prettier * removed null return, renamed function * prettier --------- Co-authored-by: Sal Tijerina <[email protected]>
- Loading branch information
1 parent
d36ba9f
commit ccccf91
Showing
3 changed files
with
23 additions
and
18 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Checks that the field is a non-empty string | ||
* @param {Object} props - | ||
* @param {String} propName - name of the property | ||
* @param {String} componentName - name of the component | ||
* @returns {String} Message if error, otherwise null | ||
*/ | ||
|
||
export default function emptyStringValidator(props, propName, componentName) { | ||
if ( | ||
!props[propName] || | ||
typeof props[propName] !== 'string' || | ||
props[propName].replace(/ /g, '') === '' | ||
) { | ||
return new Error( | ||
`No text passed to <${componentName}> prop "${propName}". Validation failed.` | ||
); | ||
} | ||
} |
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