Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce locale proxy #2004

Merged
merged 46 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f688434
feat: introduce locale access proxy
ST-DDT Apr 1, 2023
9db8ff9
chore: fix typo
ST-DDT Apr 2, 2023
bef53d7
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 2, 2023
b495965
test: extend proxy tests
ST-DDT Apr 2, 2023
c0be7e1
chore: fix import order
ST-DDT Apr 2, 2023
109ef31
test: use describe instead of comment sections
ST-DDT Apr 2, 2023
0f42fda
chore: apply suggestions
ST-DDT Apr 2, 2023
8530492
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 2, 2023
149ec6b
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 2, 2023
eebccd0
docs: extend migration guide
ST-DDT Apr 2, 2023
5c70e32
chore: typo
ST-DDT Apr 2, 2023
5c73725
chore: reword
ST-DDT Apr 2, 2023
df38ac7
chore: mark string type
ST-DDT Apr 2, 2023
d8fa41f
docs: add examples
ST-DDT Apr 2, 2023
05d2cab
docs: improve example
ST-DDT Apr 2, 2023
79cb31a
docs: apply suggestions
ST-DDT Apr 2, 2023
885627b
chore: fix typo
ST-DDT Apr 2, 2023
0ff62af
chore: apply suggestion
ST-DDT Apr 2, 2023
42443fa
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 2, 2023
419edfe
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 4, 2023
e0b8ac2
test: remove expected failure
ST-DDT Apr 4, 2023
fff9ccb
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 5, 2023
fe435ad
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 12, 2023
021e851
chore: apply suggestions
ST-DDT Apr 12, 2023
f69b474
chore: lost commit
ST-DDT Apr 12, 2023
d2a5312
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 13, 2023
dec1659
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 15, 2023
2a4cc3f
chore: apply suggestions
ST-DDT Apr 15, 2023
372e1f2
chore: apply suggestion
ST-DDT Apr 15, 2023
fd80d4f
test: update error message
ST-DDT Apr 15, 2023
4b92071
Update test/faker.spec.ts
ST-DDT Apr 15, 2023
385d4fa
chore: format
ST-DDT Apr 15, 2023
f107258
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 16, 2023
9b298c7
test: add tests for Object.keys
ST-DDT Apr 17, 2023
316941d
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 20, 2023
f99f72c
fix: proxy-impl
ST-DDT Apr 20, 2023
106bf70
Apply suggestions from code review
ST-DDT Apr 20, 2023
d722c6a
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 21, 2023
fbde3ac
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 21, 2023
24e14cf
refactor: use null as not applicable data
ST-DDT Apr 21, 2023
6acf6de
Merge branch 'next' into feat/locale-access-proxy
matthewmayer Apr 22, 2023
aafe702
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 22, 2023
1f29440
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 23, 2023
2ab6023
chore: own review
ST-DDT Apr 23, 2023
783b7ba
Update src/locale-proxy.ts
ST-DDT Apr 23, 2023
f915d49
Merge branch 'next' into feat/locale-access-proxy
ST-DDT Apr 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/locale-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ function createCategoryProxy<
return new Proxy(categoryData, {
has(target: CategoryData, entryName: keyof CategoryData): boolean {
const value = target[entryName];
return value != null && (!Array.isArray(value) || value.length !== 0);
return value != null;
},

get(
target: CategoryData,
entryName: keyof CategoryData
): CategoryData[keyof CategoryData] {
const value = target[entryName];
if (value == null) {
if (value === null) {
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
throw new FakerError(
`The locale data for '${categoryName}.${entryName.toString()}' aren't applicable to this locale.
If you think this is a bug, please report it at: https://github.com/faker-js/faker`
);
} else if (value == null) {
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
throw new FakerError(
`The locale data for '${categoryName}.${entryName.toString()}' are missing in this locale.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://next.fakerjs.dev/guide/localization.html`
);
} else if (Array.isArray(value) && value.length === 0) {
throw new FakerError(
`The locale data for '${categoryName}.${entryName.toString()}' aren't applicable to this locale.
If you think this is a bug, please report it at: https://github.com/faker-js/faker`
);
} else {
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
return value;
}
Expand Down
41 changes: 0 additions & 41 deletions test/all_functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,6 @@ const BROKEN_LOCALE_METHODS = {
companySuffix: ['az'],
},
location: {
streetName: [
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
'af_ZA',
'ar',
'dv',
'el',
'en',
'en_AU',
'en_BORK',
'en_CA',
'en_GB',
'en_GH',
'en_IE',
'en_IN',
'en_NG',
'en_US',
'en_ZA',
'es',
'fa',
'fi',
'fr',
'fr_BE',
'fr_CA',
'fr_CH',
'fr_LU',
'hu',
'hy',
'id_ID',
'it',
'ja',
'ne',
'nl',
'nl_BE',
'pl',
'pt_BR',
'pt_PT',
'ur',
'vi',
'zh_CN',
'zh_TW',
'zu_ZA',
],
state: ['az', 'nb_NO', 'sk'],
stateAbbr: ['sk'],
streetName: [
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion test/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('location', () => {
seededTests(faker, 'location', (t) => {
t.it('street');

// EN does not have streetName data
// TODO @xDivisionByZerox 2023-04-16: add street name locale data to `en`
t.skip('streetName');
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

t.it('buildingNumber');
Expand Down