Skip to content

Commit

Permalink
refactor(locale)!: remove location data index-value-binding (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox authored Apr 14, 2024
1 parent 734a7f3 commit 453ea97
Show file tree
Hide file tree
Showing 26 changed files with 151 additions and 162 deletions.
12 changes: 12 additions & 0 deletions docs/guide/upgrading_v9/2476.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Direction definitions reorganized

The locale definitions used by `faker.location.direction()`, `faker.location.cardinalDirection()` and `faker.location.ordinalDirection()` have been reorganized.
Previously, they were organized under `definitions.location.direction` and `definitions.location.direction_abbr` and where values were required to be in a specific order.
Now, all values are nested under `definitions.location.direction` with descriptive property names.
If you are using the public methods, no changes are required.
You only need to change your code if you are accessing the raw definitions e.g. in `faker.helpers.fake()`.

| Before | After |
| ------------------------- | ----------------------------------------------------------------------- |
| `location.direction` | `location.direction.cardinal` or `location.direction.ordinal` |
| `location.direction_abbr` | `location.direction.cardinal_abbr` or `location.direction.ordinal_abbr` |
30 changes: 24 additions & 6 deletions src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,31 @@ export type LocationDefinition = LocaleEntry<{
* The names of the compass directions.
* First the 4 cardinal directions, then the 4 ordinal directions.
*/
direction: string[];
direction: {
/**
* The names of the cardinal compass directions.
* Cardinal directions are the four main points of a compass.
*/
cardinal: string[];

/**
* The abbreviated names of the compass directions.
* First the 4 cardinal directions, then the 4 ordinal directions.
*/
direction_abbr: string[];
/**
* The abbreviated names of the cardinal compass directions.
* Cardinal directions are the four main points of a compass.
*/
cardinal_abbr: string[];

/**
* The names of ordinal compass directions.
* Ordinal directions are combinations of cardinal directions.
*/
ordinal: string[];

/**
* The abbreviated names of ordinal compass directions.
* Ordinal directions are combinations of cardinal directions.
*/
ordinal_abbr: string[];
};

/**
* The pattern used to generate building numbers. Since building numbers rarely start with 0, any consecutive # characters will be replaced by a number without a leading zero.
Expand Down
16 changes: 6 additions & 10 deletions src/locales/da/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'Nord',
'Øst',
'Syd',
'Vest',
'Nordøst',
'Nordvest',
'Sydøst',
'Sydvest',
];
export default {
cardinal: ['Nord', 'Øst', 'Syd', 'Vest'],
cardinal_abbr: ['N', 'Ø', 'S', 'V'],
ordinal: ['Nordøst', 'Nordvest', 'Sydøst', 'Sydvest'],
ordinal_abbr: ['NØ', 'NV', 'SØ', 'SV'],
};
1 change: 0 additions & 1 deletion src/locales/da/location/direction_abbr.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/locales/da/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import city_name from './city_name';
import city_pattern from './city_pattern';
import country from './country';
import direction from './direction';
import direction_abbr from './direction_abbr';
import postcode from './postcode';
import secondary_address from './secondary_address';
import street_address from './street_address';
Expand All @@ -21,7 +20,6 @@ const location: LocationDefinition = {
city_pattern,
country,
direction,
direction_abbr,
postcode,
secondary_address,
street_address,
Expand Down
16 changes: 6 additions & 10 deletions src/locales/en/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'North',
'East',
'South',
'West',
'Northeast',
'Northwest',
'Southeast',
'Southwest',
];
export default {
cardinal: ['North', 'East', 'South', 'West'],
cardinal_abbr: ['N', 'E', 'S', 'W'],
ordinal: ['Northeast', 'Northwest', 'Southeast', 'Southwest'],
ordinal_abbr: ['NE', 'NW', 'SE', 'SW'],
};
1 change: 0 additions & 1 deletion src/locales/en/location/direction_abbr.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/locales/en/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import city_suffix from './city_suffix';
import country from './country';
import county from './county';
import direction from './direction';
import direction_abbr from './direction_abbr';
import postcode from './postcode';
import secondary_address from './secondary_address';
import state from './state';
Expand All @@ -30,7 +29,6 @@ const location: LocationDefinition = {
country,
county,
direction,
direction_abbr,
postcode,
secondary_address,
state,
Expand Down
16 changes: 6 additions & 10 deletions src/locales/eo/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'nordo',
'oriento',
'sudo',
'okcidento',
'nordoriento',
'nordokcidenta',
'sudoriento',
'sudokcidento',
];
export default {
cardinal: ['nordo', 'oriento', 'sudo', 'okcidento'],
cardinal_abbr: ['N', 'E', 'S', 'U'],
ordinal: ['nordoriento', 'nordokcidenta', 'sudoriento', 'sudokcidento'],
ordinal_abbr: ['NE', 'NU', 'SE', 'SU'],
};
1 change: 0 additions & 1 deletion src/locales/eo/location/direction_abbr.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/locales/eo/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import city_prefix from './city_prefix';
import city_suffix from './city_suffix';
import country from './country';
import direction from './direction';
import direction_abbr from './direction_abbr';
import secondary_address from './secondary_address';
import street_address from './street_address';
import street_pattern from './street_pattern';
Expand All @@ -21,7 +20,6 @@ const location: LocationDefinition = {
city_suffix,
country,
direction,
direction_abbr,
secondary_address,
street_address,
street_pattern,
Expand Down
16 changes: 6 additions & 10 deletions src/locales/fa/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'شمال',
'شرق',
'جنوب',
'غرب',
'شمال شرق',
'شمال غرب',
'جنوب شرق',
'جنوب غرب',
];
export default {
cardinal: ['شمال', 'شرق', 'جنوب', 'غرب'],
cardinal_abbr: ['شمالی', 'شرقی', 'جنوبی', 'غربی'],
ordinal: ['شمال شرق', 'شمال غرب', 'جنوب شرق', 'جنوب غرب'],
ordinal_abbr: ['شمال شرق', 'شمال غرب', 'جنوب شرق', 'جنوب غرب'],
};
16 changes: 6 additions & 10 deletions src/locales/fr/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'Nord',
'Est',
'Sud',
'Ouest',
'Nord-est',
'Nord-ouest',
'Sud-est',
'Sud-ouest',
];
export default {
cardinal: ['Nord', 'Est', 'Sud', 'Ouest'],
cardinal_abbr: ['N', 'E', 'S', 'O'],
ordinal: ['Nord-est', 'Nord-ouest', 'Sud-est', 'Sud-ouest'],
ordinal_abbr: ['NE', 'NO', 'SE', 'SO'],
};
16 changes: 6 additions & 10 deletions src/locales/fr_CH/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'Nord',
'Est',
'Sud',
'Ouest',
'Nord-est',
'Nord-ouest',
'Sud-est',
'Sud-ouest',
];
export default {
cardinal: ['Nord', 'Est', 'Sud', 'Ouest'],
cardinal_abbr: ['N', 'E', 'S', 'O'],
ordinal: ['Nord-est', 'Nord-ouest', 'Sud-est', 'Sud-ouest'],
ordinal_abbr: ['NE', 'NO', 'SE', 'SO'],
};
16 changes: 6 additions & 10 deletions src/locales/he/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'צפון',
'מזרח',
'דרום',
'מערב',
'צפון מזרח',
'צפון מערב',
'דרום מזרח',
'דרום מערב',
];
export default {
cardinal: ['צפון', 'מזרח', 'דרום', 'מערב'],
cardinal_abbr: ['צ', 'מז', 'ד', 'מע'],
ordinal: ['צפון מזרח', 'צפון מערב', 'דרום מזרח', 'דרום מערב'],
ordinal_abbr: ['צ-מז', 'צ-מע', 'ד-מז', 'ד-מע'],
};
1 change: 0 additions & 1 deletion src/locales/he/location/direction_abbr.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/locales/he/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import city_pattern from './city_pattern';
import country from './country';
import county from './county';
import direction from './direction';
import direction_abbr from './direction_abbr';
import postcode from './postcode';
import secondary_address from './secondary_address';
import state from './state';
Expand All @@ -26,7 +25,6 @@ const location: LocationDefinition = {
country,
county,
direction,
direction_abbr,
postcode,
secondary_address,
state,
Expand Down
26 changes: 16 additions & 10 deletions src/locales/hy/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default [
'Հյուսիսային',
'Արևելյան',
'Հարավային',
'Արևմտյան',
'Հյուսիսարևելյան',
'Հյուսիսարևմտյան',
'Հարավարևելյան',
'Հարավարևմտյան',
];
export default {
cardinal: ['Հյուսիսային', 'Արևելյան', 'Հարավային', 'Արևմտյան'],
cardinal_abbr: ['հս․ լ․', 'ավ․ ե․', 'հվ․ լ․', 'ամ․ ե․'],
ordinal: [
'Հյուսիսարևելյան',
'Հյուսիսարևմտյան',
'Հարավարևելյան',
'Հարավարևմտյան',
],
ordinal_abbr: [
'հս․ լ․ ավ․ ե․',
'հս․ լ․ ամ․ ե․',
'հվ․ լ․ ավ․ ե․',
'հվ․ լ․ ամ․ ե․',
],
};
7 changes: 6 additions & 1 deletion src/locales/ja/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default ['北', '東', '南', '西', '北東', '北西', '南東', '南西'];
export default {
cardinal: ['北', '東', '南', '西'],
cardinal_abbr: ['北', '東', '南', '西'],
ordinal: ['北東', '北西', '南東', '南西'],
ordinal_abbr: ['北東', '北西', '南東', '南西'],
};
21 changes: 11 additions & 10 deletions src/locales/pl/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Source: https://pl.wikipedia.org/wiki/Strony_świata
export default [
'północ',
'wschód',
'południe',
'zachód',
'północny wschód',
'południowy wschód',
'południowy zachód',
'północny zachód',
];
export default {
cardinal: ['północ', 'wschód', 'południe', 'zachód'],
cardinal_abbr: ['pn.', 'wsch.', 'pd.', 'zach.'],
ordinal: [
'północny wschód',
'południowy wschód',
'południowy zachód',
'północny zachód',
],
ordinal_abbr: ['pn. wsch.', 'pd. wsch.', 'pd. zach.', 'pn. zach.'],
};
11 changes: 0 additions & 11 deletions src/locales/pl/location/direction_abbr.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/locales/pl/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import city_name from './city_name';
import city_pattern from './city_pattern';
import country from './country';
import direction from './direction';
import direction_abbr from './direction_abbr';
import postcode from './postcode';
import secondary_address from './secondary_address';
import state from './state';
Expand All @@ -23,7 +22,6 @@ const location: LocationDefinition = {
city_pattern,
country,
direction,
direction_abbr,
postcode,
secondary_address,
state,
Expand Down
16 changes: 6 additions & 10 deletions src/locales/pt_PT/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'Norte',
'Este',
'Sul',
'Oeste',
'Nordeste',
'Noroeste',
'Sudeste',
'Sodoeste',
];
export default {
cardinal: ['Norte', 'Este', 'Sul', 'Oeste'],
cardinal_abbr: ['N', 'E', 'S', 'O'],
ordinal: ['Nordeste', 'Noroeste', 'Sudeste', 'Sodoeste'],
ordinal_abbr: ['NE', 'NO', 'SE', 'SO'],
};
16 changes: 6 additions & 10 deletions src/locales/ur/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export default [
'شمال',
'مشرق',
'جنوب',
'مغرب',
'شمال مشرق',
'سمال مغرب',
'جنوب مشرق',
'جنوب مغرب',
];
export default {
cardinal: ['شمال', 'مشرق', 'جنوب', 'مغرب'],
cardinal_abbr: ['شمال', 'مشرق', 'جنوب', 'مغرب'],
ordinal: ['شمال مشرق', 'سمال مغرب', 'جنوب مشرق', 'جنوب مغرب'],
ordinal_abbr: ['شمال مشرق', 'سمال مغرب', 'جنوب مشرق', 'جنوب مغرب'],
};
26 changes: 16 additions & 10 deletions src/locales/uz_UZ_latin/location/direction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default [
'Shimol',
'Sharq',
'Janub',
"G'arb",
'Shimoli-sharqiy',
"Shimoli g'arbiy",
'Janubi-sharqiy',
"Janubi-g'arbiy",
];
export default {
cardinal: ['Shimol', 'Sharq', 'Janub', "G'arb"],
cardinal_abbr: ['Shimol', 'Sharq', 'Janub', "G'arb"],
ordinal: [
'Shimoli-sharqiy',
"Shimoli g'arbiy",
'Janubi-sharqiy',
"Janubi-g'arbiy",
],
ordinal_abbr: [
'Shimoli-sharqiy',
"Shimoli g'arbiy",
'Janubi-sharqiy',
"Janubi-g'arbiy",
],
};
Loading

0 comments on commit 453ea97

Please sign in to comment.