aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/faker.ts30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/faker.ts b/src/faker.ts
index d6a288c6..c84d77a4 100644
--- a/src/faker.ts
+++ b/src/faker.ts
@@ -45,8 +45,34 @@ const metadataKeys: ReadonlyArray<keyof LocaleDefinition> = [
export class Faker {
locales: UsedLocales;
- locale: UsableLocale;
- localeFallback: UsableLocale;
+ private _locale: UsableLocale;
+ private _localeFallback: UsableLocale;
+
+ get locale(): UsableLocale {
+ return this._locale;
+ }
+
+ set locale(locale: UsableLocale) {
+ if (!this.locales[locale]) {
+ throw new FakerError(
+ `Locale ${locale} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
+ );
+ }
+ this._locale = locale;
+ }
+
+ get localeFallback(): UsableLocale {
+ return this._localeFallback;
+ }
+
+ set localeFallback(localeFallback: UsableLocale) {
+ if (!this.locales[localeFallback]) {
+ throw new FakerError(
+ `Locale ${localeFallback} is not supported. You might want to add the requested locale first to \`faker.locales\`.`
+ );
+ }
+ this._localeFallback = localeFallback;
+ }
readonly definitions: LocaleDefinition = this.initDefinitions();