From 2dc4a5190542ae92b2fb4b3686b483ecaab486bb Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 21 Apr 2023 22:22:01 +0200 Subject: [PATCH 1/2] refactor(locale): use null as not applicable --- src/definitions/definitions.ts | 6 ++-- src/definitions/person.ts | 40 +++++++++++------------ src/locales/az/company/suffix.ts | 2 +- src/locales/az/location/state.ts | 2 +- src/locales/az/person/female_prefix.ts | 2 +- src/locales/az/person/male_prefix.ts | 2 +- src/locales/az/person/prefix.ts | 6 +--- src/locales/az/person/suffix.ts | 2 +- src/locales/id_ID/person/female_prefix.ts | 2 +- src/locales/id_ID/person/male_prefix.ts | 2 +- src/locales/id_ID/person/prefix.ts | 6 +--- src/locales/it/person/suffix.ts | 2 +- src/locales/mk/person/suffix.ts | 2 +- src/locales/pt_BR/location/city_prefix.ts | 2 +- src/locales/pt_PT/location/city_prefix.ts | 2 +- src/locales/pt_PT/location/city_suffix.ts | 2 +- src/locales/pt_PT/person/suffix.ts | 2 +- src/locales/ru/person/female_prefix.ts | 2 +- src/locales/ru/person/male_prefix.ts | 2 +- src/locales/ru/person/prefix.ts | 6 +--- src/locales/ru/person/suffix.ts | 2 +- src/locales/sk/location/state.ts | 2 +- src/locales/sk/location/state_abbr.ts | 2 +- src/locales/th/location/city_prefix.ts | 2 +- src/locales/th/location/city_suffix.ts | 2 +- src/locales/zh_CN/person/female_prefix.ts | 2 +- src/locales/zh_CN/person/male_prefix.ts | 2 +- src/locales/zh_CN/person/prefix.ts | 6 +--- src/locales/zh_TW/person/female_prefix.ts | 2 +- src/locales/zh_TW/person/male_prefix.ts | 2 +- src/locales/zh_TW/person/prefix.ts | 6 +--- test/all_functional.spec.ts | 1 + test/person.spec.ts | 8 ++--- 33 files changed, 57 insertions(+), 76 deletions(-) diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 112c2c1aa64..8035e81d15c 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> = Partial & - // Unsupported & custom entries - Record; +export type LocaleEntry> = { + [P in keyof T]?: T[P] | null; +} & Record; // Unsupported & custom entries /** * The definitions as used by the translations/locales. diff --git a/src/definitions/person.ts b/src/definitions/person.ts index 9cc86d3a20a..b300a689273 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 cb1d846e0d6..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 cb1d846e0d6..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 cb1d846e0d6..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 cb1d846e0d6..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 d6d1738de67..7646bbd17d0 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 cb1d846e0d6..7646bbd17d0 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/all_functional.spec.ts b/test/all_functional.spec.ts index ca80014abbd..8f28f20f761 100644 --- a/test/all_functional.spec.ts +++ b/test/all_functional.spec.ts @@ -28,6 +28,7 @@ const BROKEN_LOCALE_METHODS = { companySuffix: ['az'], }, location: { + city: ['th'], state: ['az', 'nb_NO', 'sk'], stateAbbr: ['sk'], }, diff --git a/test/person.spec.ts b/test/person.spec.ts index beca664386a..dbd2169db73 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({ From ddc4b6a7a3f8fb333b43872c7df114037468b0dc Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 22 Apr 2023 10:55:42 +0200 Subject: [PATCH 2/2] test: add missing test --- test/utils/merge-locales.spec.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/utils/merge-locales.spec.ts b/test/utils/merge-locales.spec.ts index 50e519d55d2..3fb24ff3785 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' },