aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-06-14 14:18:50 +0200
committerGitHub <[email protected]>2022-06-14 14:18:50 +0200
commit5ea8252f727e2e577c2adca9650ac8f24a171632 (patch)
treeebc4c226c2ac2d126a6e84bc43aded4d2cca2862 /src
parente8985f60074969393fd57fc9f4f7d747742bc87c (diff)
downloadfaker-5ea8252f727e2e577c2adca9650ac8f24a171632.tar.xz
faker-5ea8252f727e2e577c2adca9650ac8f24a171632.zip
feat: throw error on unknown locale (#1071)
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();