Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do use Faker library to generate ISO 3166-1 alpha-3 country codes?

Tags:

nestjs

faker

as the title says, I want to implement Faker library to seed a mock country data. However, from what I've known you can only use Faker to generate alpha 2 country code (e.g, US, CN, CA) and I have a need to use Faker to generate Alpha 3 country code (e.g, USA, CHN, CAN). Is there a way for me to achieve this using Faker on NestJS? Thanks in advance

like image 295
borak Avatar asked Nov 22 '25 22:11

borak


1 Answers

You can pass 'alpha-3' as an argument to faker.address.countryCode

I found it in the source code here : https://github.com/Marak/faker.js/blob/master/lib/address.js#L194

You can test it in the dev console of their live demo here : https://rawgit.com/Marak/faker.js/master/examples/browser/index.html

like image 183
Léo Anesi Avatar answered Nov 28 '25 17:11

Léo Anesi