Skip to content

Instantly share code, notes, and snippets.

@mathiasgheno
Created April 11, 2023 01:19
Show Gist options
  • Save mathiasgheno/617a312306e03d0d1d50d8c97b936025 to your computer and use it in GitHub Desktop.
Save mathiasgheno/617a312306e03d0d1d50d8c97b936025 to your computer and use it in GitHub Desktop.
const hasMoreCharactersThan = (desired) => (value) => {
const size = value?.length;
if(size < desired) {
throw new Error(`Value is not more than ${desired} characters`);
}
return value;
}
const isValidDescription = hasMoreCharactersThan(100);
const isValidEmail = hasMoreCharactersThan(10);
isValidEmail('mathiasgheno@gmail.com') // ok
isValidDescription('My description') // Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment