Closed Strongground closed 2 years ago
Hello,
Looking at the last snippet of code, I can see that you mentioned that it's not working because the fakeData.getLastGeneratedValue
method returns a promise.
You can easily make this code work by wrapping it in a Promise with an async
function and then await for the rest of the promises to finish. Here is how to do that with your code:
return new Promise(async function(resolve) {
const umlautMap = {
'\u00dc': 'UE',
'\u00c4': 'AE',
'\u00d6': 'OE',
'\u00fc': 'ue',
'\u00e4': 'ae',
'\u00f6': 'oe',
'\u00df': 'ss',
}
function replaceUmlaute(str) {
return str
.replace(/[\u00dc|\u00c4|\u00d6][a-z]/g, (a) => {
const big = umlautMap[a.slice(0, 1)];
return big.charAt(0) + big.charAt(1).toLowerCase() + a.slice(1);
})
.replace(new RegExp('['+Object.keys(umlautMap).join('|')+']',"g"),
(a) => umlautMap[a]
);
}
var result = replaceUmlaute(`${await fakeData.getLastGeneratedValue('first_name')} ${await fakeData.getLastGeneratedValue('last_name')}`.toUpperCase());
resolve(result);
});
Also, while Fake Data doesn't have by default a generator for fake credit card numbers, the internal faker.js library comes with one. So an alternative to your code would be to use this for generating a card number: faker.finance.creditCardNumber()
and this for generating a CVV code: faker.finance.creditCardCVV()
You can find more about these functions and the API that faker.js library provides here: https://github.com/faker-js/faker
That is very solid info - thanks a lot! I've almost never before experienced such good support on a free plugin/software project!
Hi again,
I noticed there is no standard generator to generate some common credit card data. I did this with custom generators, but it may benefit all to have something like this included:
It allows to select between four credit card issuers (replace where str, len and pos get their values from - mid script). Other helpful trivial generators: