Created
May 20, 2018 15:46
-
-
Save usmanbashir/fe930f1bfbc004f0575eaa47d454b90d to your computer and use it in GitHub Desktop.
Experimenting a different style of programming. Where every validation method on success calls a function with the said data as an argument.
This file contains hidden or 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
| export const toProperCase = (string) => { | |
| return ( | |
| string.charAt(0).toUpperCase() + string.toLowerCase().substr(1) | |
| ) | |
| } | |
| // Usecase: | |
| // isNotEmptyString(firstName, (firstName) => { // do something... } | |
| // | |
| export const isNotEmptyString = (variable, func) => { | |
| if (variable !== "") { | |
| return func.call(null, variable); | |
| } else { | |
| return null; | |
| } | |
| } | |
| // Usecase: | |
| // isNotNull(imageUrl, (imageUrl) => { // do something... } | |
| // | |
| export const isNotNull = (variable, func) => { | |
| if (variable !== null) { | |
| return func.call(null, variable); | |
| } else { | |
| return null; | |
| } | |
| } | |
| // Usecase: | |
| // isLengthNotEmpty(rows, (rows) => { // do something... } | |
| // | |
| export const isLengthNotEmpty = (variable, func) => { | |
| if (variable.length >= 1) { | |
| return func.call(null, variable); | |
| } else { | |
| return null; | |
| } | |
| } | |
| // Usecase: | |
| // isObjectLengthNotEmpty(users, (users) => { // do something... } | |
| // | |
| export const isObjectLengthNotEmpty = (variable, func) => { | |
| if (Object.keys(variable).length >= 1) { | |
| return func.call(null, variable); | |
| } else { | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment