Skip to content

Instantly share code, notes, and snippets.

@usmanbashir
Created May 20, 2018 15:46
Show Gist options
  • Select an option

  • Save usmanbashir/fe930f1bfbc004f0575eaa47d454b90d to your computer and use it in GitHub Desktop.

Select an option

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.
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