aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/location/index.ts30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts
index 175c5433..19816c8f 100644
--- a/src/modules/location/index.ts
+++ b/src/modules/location/index.ts
@@ -320,13 +320,19 @@ export class LocationModule {
* 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. Defaults to `{}`.
- * @param options.variant The variant to return. Can be either `'alpha-2'` (two-letter code)
- * or `'alpha-3'` (three-letter code). Defaults to `'alpha-2'`.
+ * @param options.variant The variant to return. Can be one of:
+ *
+ * - `'alpha-2'` (two-letter code)
+ * - `'alpha-3'` (three-letter code)
+ * - `'numeric'` (numeric code)
+ *
+ * Defaults to `'alpha-2'`.
*
* @example
* faker.location.countryCode() // 'SJ'
* faker.location.countryCode('alpha-2') // 'GA'
* faker.location.countryCode('alpha-3') // 'TJK'
+ * faker.location.countryCode('numeric') // '528'
*
* @since 8.0.0
*/
@@ -334,15 +340,17 @@ export class LocationModule {
options:
| 'alpha-2'
| 'alpha-3'
+ | 'numeric'
| {
/**
* The code to return.
- * Can be either `'alpha-2'` (two-letter code)
- * or `'alpha-3'` (three-letter code).
+ * 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';
+ variant?: 'alpha-2' | 'alpha-3' | 'numeric';
} = {}
): string {
if (typeof options === 'string') {
@@ -350,7 +358,17 @@ export class LocationModule {
}
const { variant = 'alpha-2' } = options;
- const key = variant === 'alpha-3' ? 'alpha3' : 'alpha2';
+ const key = (() => {
+ switch (variant) {
+ case 'numeric':
+ return 'numeric';
+ case 'alpha-3':
+ return 'alpha3';
+ case 'alpha-2':
+ default:
+ return 'alpha2';
+ }
+ })();
return this.faker.helpers.arrayElement(
this.faker.definitions.location.country_code