Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metadata): add method to access metadata #2143

Merged
merged 9 commits into from
Jun 17, 2023
17 changes: 16 additions & 1 deletion src/faker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LocaleDefinition } from './definitions';
import type { LocaleDefinition, MetadataDefinition } from './definitions';
import { FakerError } from './errors/faker-error';
import { deprecated } from './internal/deprecated';
import type { Mersenne } from './internal/mersenne/mersenne';
Expand Down Expand Up @@ -458,6 +458,21 @@ export class Faker {
return seed;
}

/**
* Returns an object with metadata about the current locale
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
*
* @returns An object including the locale title, code, language, endonym (native name), direction (left to right, or right to left), script, and optional country.
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* import { faker, fakerES_MX } from '@faker-js/faker';
* // const { faker, fakerES_MX } = require("@faker-js/faker")
* faker.metadata(); // { title: 'English', code: 'en', language: 'en', endonym: 'English', dir: 'ltr', script: 'Latn' }
* fakerES_MX.metadata(); // { title: 'Spanish (Mexico)', code: 'es_MX', language: 'es', endonym: 'Español (México)', dir: 'ltr', script: 'Latn', country: 'MX' }
*/
metadata(): MetadataDefinition {
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
return this.rawDefinitions.metadata;
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
}

// Pure JS backwards compatibility

/**
Expand Down