Created
April 22, 2020 20:32
-
-
Save MateusAndrade/aff467d98e1e85a83c3da190caf6525c to your computer and use it in GitHub Desktop.
Card Holder name generator
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
/** | |
This a simple function to create the Holder Name of a Credit Card, mainly based | |
on the pattern addopted at NuBank | |
**/ | |
const names = [ | |
"Vini Lins", | |
"Mateus Andrade da Costa Santos", | |
"Bruno Dal Santos", | |
"Helena Strada Franco de Souza", | |
"Pedro de Alcântara Francisco António João Carlos Xavier de Paula Miguel Rafael Joaquim José Gonzaga Pascoal Cipriano Serafim", | |
"Willy Mondzelewski", | |
"Pedro Bullo Junior" | |
]; | |
const holderName = name => | |
name.length < 21 | |
? name.toUpperCase() | |
: name | |
.split(" ") | |
.reduce((prev, actual, index, arr) => { | |
if (index === 0) { | |
return actual; | |
} | |
if (actual.length < 3 && /\b[a-z]+\s*/g.test(actual)) { | |
return prev; | |
} | |
if (index !== arr.length - 1) { | |
return `${prev} ${actual.charAt(0)}`; | |
} | |
return `${prev} ${actual}`; | |
}, "") | |
.toUpperCase(); | |
names.forEach(n => console.log(holderName(n))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment