|
1 | 1 | import type { LocaleDefinition } from '../definitions'; |
2 | 2 | import { FakerError } from '../errors/faker-error'; |
| 3 | +import { assertLocaleData } from './assert-locale-data'; |
3 | 4 |
|
4 | 5 | /** |
5 | 6 | * A proxy for LocaleDefinition that marks all properties as required and throws an error when an entry is accessed that is not defined. |
@@ -54,31 +55,6 @@ export function createLocaleProxy(locale: LocaleDefinition): LocaleProxy { |
54 | 55 | }) as LocaleProxy; |
55 | 56 | } |
56 | 57 |
|
57 | | -/** |
58 | | - * Checks that the value is not null or undefined and throws an error if it is. |
59 | | - * |
60 | | - * @param value The value to check. |
61 | | - * @param path The path to the locale data. |
62 | | - */ |
63 | | -export function assertLocaleData<T>( |
64 | | - value: T, |
65 | | - ...path: string[] |
66 | | -): asserts value is NonNullable<T> { |
67 | | - if (value === null) { |
68 | | - throw new FakerError( |
69 | | - `The locale data for '${path.join('.')}' aren't applicable to this locale. |
70 | | - If you think this is a bug, please report it at: https://github.com/faker-js/faker` |
71 | | - ); |
72 | | - } else if (value === undefined) { |
73 | | - throw new FakerError( |
74 | | - `The locale data for '${path.join('.')}' are missing in this locale. |
75 | | - If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'. |
76 | | - Please contribute the missing data to the project or use a locale/Faker instance that has these data. |
77 | | - For more information see https://fakerjs.dev/guide/localization.html` |
78 | | - ); |
79 | | - } |
80 | | -} |
81 | | - |
82 | 58 | /** |
83 | 59 | * Creates a proxy for a category that throws an error when accessing an undefined property. |
84 | 60 | * |
@@ -106,8 +82,7 @@ function createCategoryProxy< |
106 | 82 | return value; |
107 | 83 | } |
108 | 84 |
|
109 | | - assertLocaleData(value, categoryName, entryName.toString()); |
110 | | - return value; |
| 85 | + return assertLocaleData(value, categoryName, entryName.toString()); |
111 | 86 | }, |
112 | 87 |
|
113 | 88 | set: throwReadOnlyError, |
|
0 commit comments