diff options
| author | ST-DDT <[email protected]> | 2023-04-23 12:28:48 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-23 12:28:48 +0200 |
| commit | acb9cf5a81ec42e64a59f4708345f1af63147a34 (patch) | |
| tree | 5ba636d10f561ebc9a86d51c002bdc94695b8515 | |
| parent | f795269c3aa2014c4964ea71c38b53a51e0f6d47 (diff) | |
| download | faker-acb9cf5a81ec42e64a59f4708345f1af63147a34.tar.xz faker-acb9cf5a81ec42e64a59f4708345f1af63147a34.zip | |
refactor(locale): use null as not applicable (#2078)
33 files changed, 88 insertions, 76 deletions
diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index dd477beb..413b2bd7 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -22,9 +22,9 @@ import type { WordDefinitions } from './word'; /** * Wrapper type for all definition categories that will make all properties optional and allow extra properties. */ -export type LocaleEntry<T extends Record<string, unknown>> = Partial<T> & - // Unsupported & custom entries - Record<string, unknown>; +export type LocaleEntry<T extends Record<string, unknown>> = { + [P in keyof T]?: T[P] | null; +} & Record<string, unknown>; // Unsupported & custom entries /** * The definitions as used by the translations/locales. diff --git a/src/definitions/person.ts b/src/definitions/person.ts index 9cc86d3a..b300a689 100644 --- a/src/definitions/person.ts +++ b/src/definitions/person.ts @@ -7,21 +7,21 @@ export type PersonDefinitions = LocaleEntry<{ gender: string[]; sex: string[]; - prefix?: string[]; - female_prefix?: string[]; - male_prefix?: string[]; + prefix: string[]; + female_prefix: string[]; + male_prefix: string[]; - first_name?: string[]; - female_first_name?: string[]; - male_first_name?: string[]; + first_name: string[]; + female_first_name: string[]; + male_first_name: string[]; - middle_name?: string[]; - female_middle_name?: string[]; - male_middle_name?: string[]; + middle_name: string[]; + female_middle_name: string[]; + male_middle_name: string[]; - last_name?: string[]; - female_last_name?: string[]; - male_last_name?: string[]; + last_name: string[]; + female_last_name: string[]; + male_last_name: string[]; suffix: string[]; @@ -33,11 +33,11 @@ export type PersonDefinitions = LocaleEntry<{ /** * A weighted list of patterns used to generate last names. */ - last_name_pattern?: Array<{ value: string; weight: number }>; - male_last_name_pattern?: Array<{ value: string; weight: number }>; - female_last_name_pattern?: Array<{ value: string; weight: number }>; + last_name_pattern: Array<{ value: string; weight: number }>; + male_last_name_pattern: Array<{ value: string; weight: number }>; + female_last_name_pattern: Array<{ value: string; weight: number }>; - bio_pattern?: string[]; + bio_pattern: string[]; title: PersonTitleDefinitions; @@ -47,8 +47,8 @@ export type PersonDefinitions = LocaleEntry<{ /** * The possible definitions related to people's titles. */ -export interface PersonTitleDefinitions { - descriptor?: string[]; +export type PersonTitleDefinitions = LocaleEntry<{ + descriptor: string[]; job: string[]; - level?: string[]; -} + level: string[]; +}>; diff --git a/src/locales/az/company/suffix.ts b/src/locales/az/company/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/az/company/suffix.ts +++ b/src/locales/az/company/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/az/location/state.ts b/src/locales/az/location/state.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/az/location/state.ts +++ b/src/locales/az/location/state.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/az/person/female_prefix.ts b/src/locales/az/person/female_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/az/person/female_prefix.ts +++ b/src/locales/az/person/female_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/az/person/male_prefix.ts b/src/locales/az/person/male_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/az/person/male_prefix.ts +++ b/src/locales/az/person/male_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/az/person/prefix.ts b/src/locales/az/person/prefix.ts index cb1d846e..7646bbd1 100644 --- a/src/locales/az/person/prefix.ts +++ b/src/locales/az/person/prefix.ts @@ -1,5 +1 @@ -import { mergeArrays } from './../../../internal/merge'; -import female_prefix from './female_prefix'; -import male_prefix from './male_prefix'; - -export default mergeArrays(female_prefix, male_prefix); +export default null; diff --git a/src/locales/az/person/suffix.ts b/src/locales/az/person/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/az/person/suffix.ts +++ b/src/locales/az/person/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/id_ID/person/female_prefix.ts b/src/locales/id_ID/person/female_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/id_ID/person/female_prefix.ts +++ b/src/locales/id_ID/person/female_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/id_ID/person/male_prefix.ts b/src/locales/id_ID/person/male_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/id_ID/person/male_prefix.ts +++ b/src/locales/id_ID/person/male_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/id_ID/person/prefix.ts b/src/locales/id_ID/person/prefix.ts index cb1d846e..7646bbd1 100644 --- a/src/locales/id_ID/person/prefix.ts +++ b/src/locales/id_ID/person/prefix.ts @@ -1,5 +1 @@ -import { mergeArrays } from './../../../internal/merge'; -import female_prefix from './female_prefix'; -import male_prefix from './male_prefix'; - -export default mergeArrays(female_prefix, male_prefix); +export default null; diff --git a/src/locales/it/person/suffix.ts b/src/locales/it/person/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/it/person/suffix.ts +++ b/src/locales/it/person/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/mk/person/suffix.ts b/src/locales/mk/person/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/mk/person/suffix.ts +++ b/src/locales/mk/person/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/pt_BR/location/city_prefix.ts b/src/locales/pt_BR/location/city_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/pt_BR/location/city_prefix.ts +++ b/src/locales/pt_BR/location/city_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/pt_PT/location/city_prefix.ts b/src/locales/pt_PT/location/city_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/pt_PT/location/city_prefix.ts +++ b/src/locales/pt_PT/location/city_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/pt_PT/location/city_suffix.ts b/src/locales/pt_PT/location/city_suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/pt_PT/location/city_suffix.ts +++ b/src/locales/pt_PT/location/city_suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/pt_PT/person/suffix.ts b/src/locales/pt_PT/person/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/pt_PT/person/suffix.ts +++ b/src/locales/pt_PT/person/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/ru/person/female_prefix.ts b/src/locales/ru/person/female_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/ru/person/female_prefix.ts +++ b/src/locales/ru/person/female_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/ru/person/male_prefix.ts b/src/locales/ru/person/male_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/ru/person/male_prefix.ts +++ b/src/locales/ru/person/male_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/ru/person/prefix.ts b/src/locales/ru/person/prefix.ts index cb1d846e..7646bbd1 100644 --- a/src/locales/ru/person/prefix.ts +++ b/src/locales/ru/person/prefix.ts @@ -1,5 +1 @@ -import { mergeArrays } from './../../../internal/merge'; -import female_prefix from './female_prefix'; -import male_prefix from './male_prefix'; - -export default mergeArrays(female_prefix, male_prefix); +export default null; diff --git a/src/locales/ru/person/suffix.ts b/src/locales/ru/person/suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/ru/person/suffix.ts +++ b/src/locales/ru/person/suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/sk/location/state.ts b/src/locales/sk/location/state.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/sk/location/state.ts +++ b/src/locales/sk/location/state.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/sk/location/state_abbr.ts b/src/locales/sk/location/state_abbr.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/sk/location/state_abbr.ts +++ b/src/locales/sk/location/state_abbr.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/th/location/city_prefix.ts b/src/locales/th/location/city_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/th/location/city_prefix.ts +++ b/src/locales/th/location/city_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/th/location/city_suffix.ts b/src/locales/th/location/city_suffix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/th/location/city_suffix.ts +++ b/src/locales/th/location/city_suffix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/zh_CN/person/female_prefix.ts b/src/locales/zh_CN/person/female_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/zh_CN/person/female_prefix.ts +++ b/src/locales/zh_CN/person/female_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/zh_CN/person/male_prefix.ts b/src/locales/zh_CN/person/male_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/zh_CN/person/male_prefix.ts +++ b/src/locales/zh_CN/person/male_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/zh_CN/person/prefix.ts b/src/locales/zh_CN/person/prefix.ts index cb1d846e..7646bbd1 100644 --- a/src/locales/zh_CN/person/prefix.ts +++ b/src/locales/zh_CN/person/prefix.ts @@ -1,5 +1 @@ -import { mergeArrays } from './../../../internal/merge'; -import female_prefix from './female_prefix'; -import male_prefix from './male_prefix'; - -export default mergeArrays(female_prefix, male_prefix); +export default null; diff --git a/src/locales/zh_TW/person/female_prefix.ts b/src/locales/zh_TW/person/female_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/zh_TW/person/female_prefix.ts +++ b/src/locales/zh_TW/person/female_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/zh_TW/person/male_prefix.ts b/src/locales/zh_TW/person/male_prefix.ts index d6d1738d..7646bbd1 100644 --- a/src/locales/zh_TW/person/male_prefix.ts +++ b/src/locales/zh_TW/person/male_prefix.ts @@ -1 +1 @@ -export default []; +export default null; diff --git a/src/locales/zh_TW/person/prefix.ts b/src/locales/zh_TW/person/prefix.ts index cb1d846e..7646bbd1 100644 --- a/src/locales/zh_TW/person/prefix.ts +++ b/src/locales/zh_TW/person/prefix.ts @@ -1,5 +1 @@ -import { mergeArrays } from './../../../internal/merge'; -import female_prefix from './female_prefix'; -import male_prefix from './male_prefix'; - -export default mergeArrays(female_prefix, male_prefix); +export default null; diff --git a/test/person.spec.ts b/test/person.spec.ts index beca6643..dbd2169d 100644 --- a/test/person.spec.ts +++ b/test/person.spec.ts @@ -125,7 +125,7 @@ describe('person', () => { ...fakerMK.definitions.person.female_prefix, ...fakerMK.definitions.person.female_first_name, ...fakerMK.definitions.person.female_last_name, - ...fakerMK.definitions.person.suffix, + // ...fakerMK.definitions.person.suffix, // Not applicable ]; const fullName = fakerMK.person.fullName({ sex: 'female' }); @@ -141,7 +141,7 @@ describe('person', () => { ...fakerMK.definitions.person.male_prefix, ...fakerMK.definitions.person.male_first_name, ...fakerMK.definitions.person.male_last_name, - ...fakerMK.definitions.person.suffix, + // ...fakerMK.definitions.person.suffix, // Not applicable ]; const fullName = fakerMK.person.fullName({ sex: 'male' }); @@ -157,7 +157,7 @@ describe('person', () => { ...fakerMK.definitions.person.female_prefix, 'firstName', 'lastName', - ...fakerMK.definitions.person.suffix, + // ...fakerMK.definitions.person.suffix, // Not applicable ]; const fullName = fakerMK.person.fullName({ @@ -177,7 +177,7 @@ describe('person', () => { ...fakerMK.definitions.person.male_prefix, 'firstName', 'lastName', - ...fakerMK.definitions.person.suffix, + //...fakerMK.definitions.person.suffix, // Not applicable ]; const fullName = fakerMK.person.fullName({ diff --git a/test/utils/merge-locales.spec.ts b/test/utils/merge-locales.spec.ts index 50e519d5..3fb24ff3 100644 --- a/test/utils/merge-locales.spec.ts +++ b/test/utils/merge-locales.spec.ts @@ -29,6 +29,38 @@ describe('mergeLocales', () => { }); }); + it('should not overwrite not applicable data', () => { + const locale1: LocaleDefinition = { + metadata: { title: 'a' }, + location: { + city: null, + country: null, + }, + }; + const locale2: LocaleDefinition = { + metadata: { title: 'b' }, + location: { + city: ['b'], + }, + }; + const locale3: LocaleDefinition = { + metadata: { title: 'c' }, + location: { + city: ['c'], + country: ['c'], + }, + }; + const merged = mergeLocales([locale1, locale2, locale3]); + + expect(merged).toEqual({ + metadata: { title: 'a' }, + location: { + city: null, + country: null, + }, + }); + }); + it('should extend categories', () => { const locale1: LocaleDefinition = { metadata: { title: 'a' }, |
