* Returns a random [ISO_3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code. * * @param options The code to return or an options object. * @param options.variant The variant to return. Can be one of: * * - `'alpha-2'` (two-letter code) * - `'alpha-3'` (three-letter code)
(
options:
| 'alpha-2'
| 'alpha-3'
| 'numeric'
| {
/**
* The code to return.
* Can be either `'alpha-2'` (two-letter code),
* `'alpha-3'` (three-letter code)
* or `'numeric'` (numeric code).
*
* @default 'alpha-2'
*/
variant?: 'alpha-2' | 'alpha-3' | 'numeric';
} = {}
)
| 480 | * @since 8.0.0 |
| 481 | */ |
| 482 | countryCode( |
| 483 | options: |
| 484 | | 'alpha-2' |
| 485 | | 'alpha-3' |
| 486 | | 'numeric' |
| 487 | | { |
| 488 | /** |
| 489 | * The code to return. |
| 490 | * Can be either `'alpha-2'` (two-letter code), |
| 491 | * `'alpha-3'` (three-letter code) |
| 492 | * or `'numeric'` (numeric code). |
| 493 | * |
| 494 | * @default 'alpha-2' |
| 495 | */ |
| 496 | variant?: 'alpha-2' | 'alpha-3' | 'numeric'; |
| 497 | } = {} |
| 498 | ): string { |
| 499 | if (typeof options === 'string') { |
| 500 | options = { variant: options }; |
| 501 | } |
| 502 | |
| 503 | const { variant = 'alpha-2' } = options; |
| 504 | const key = (() => { |
| 505 | switch (variant) { |
| 506 | case 'numeric': { |
| 507 | return 'numeric'; |
| 508 | } |
| 509 | |
| 510 | case 'alpha-3': { |
| 511 | return 'alpha3'; |
| 512 | } |
| 513 | |
| 514 | case 'alpha-2': { |
| 515 | return 'alpha2'; |
| 516 | } |
| 517 | } |
| 518 | })(); |
| 519 | |
| 520 | return this.faker.helpers.arrayElement( |
| 521 | this.faker.definitions.location.country_code |
| 522 | )[key]; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Returns a random localized state, or other equivalent first-level administrative entity for the locale's country such as a province or region. |
no test coverage detected