Skip to content

Commit

Permalink
Merge branch 'next' into locale/pt-pt-addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Mar 11, 2023
2 parents fcd0193 + bb72a66 commit 1b4ea0a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ The sources are located in the [src](src) directory.
All fake data generators are divided into namespaces (each namespace being a separate module).
Most of the generators use the _definitions_, which are just plain JavaScript objects/arrays/strings that are separate for each [locale](src/locales).

## Sourcing data for definitions

If adding new data definitions to Faker, you'll often need to find source data. Note that:

- Faker must not contain copyrighted materials.
- Facts cannot be copyrighted, so if you are adding or translating a finite, known, list of things such as the names of chemical elements into another language, that's OK.
- But if you are compiling a list of, for example, popular personal names or cities, don't copy directly from a single source (Wikipedia, 'most popular' articles, government data sites etc). A compilation of facts [can be copyrighted](https://en.wikipedia.org/wiki/Copyright_in_compilation).
- It's best to refer to multiple sources and use your own judgement/knowledge to make a sample list of data.

## Building Faker

The project is being built by [esbuild](https://esbuild.github.io) (see [bundle.ts](scripts/bundle.ts))
Expand Down
5 changes: 0 additions & 5 deletions src/locales/az/company/name_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ export default [
'{{company.prefix}} {{person.female_first_name}}',
'{{company.prefix}} {{person.male_first_name}}',
'{{company.prefix}} {{person.male_last_name}}',
'{{company.prefix}} {{company.suffix}}{{company.suffix}}',
'{{company.prefix}} {{company.suffix}}{{company.suffix}}{{company.suffix}}',
'{{company.prefix}} {{location.city_name}}{{company.suffix}}',
'{{company.prefix}} {{location.city_name}}{{company.suffix}}{{company.suffix}}',
'{{company.prefix}} {{location.city_name}}{{company.suffix}}{{company.suffix}}{{company.suffix}}',
];
14 changes: 7 additions & 7 deletions src/locales/en_AU/person/last_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default [
'Johnston',
'Moore',
'Smyth',
"O'neill",
"O'Neill",
'Doherty',
'Stewart',
'Quinn',
Expand Down Expand Up @@ -121,7 +121,7 @@ export default [
'Crooks',
'Cruickshank',
'Cummings',
"D'amore",
"D'Amore",
'Daniel',
'Dare',
'Daugherty',
Expand Down Expand Up @@ -235,12 +235,12 @@ export default [
'Nader',
'Nicolas',
'Nolan',
"O'connell",
"O'conner",
"O'hara",
"O'keefe",
"O'Connell",
"O'Conner",
"O'Hara",
"O'Keefe",
'Olson',
"O'reilly",
"O'Reilly",
'Parisian',
'Parker',
'Quigley',
Expand Down
2 changes: 0 additions & 2 deletions src/locales/pt_BR/location/city.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default [
'{{location.city_prefix}} {{person.firstName}}{{location.city_suffix}}',
'{{location.city_prefix}} {{person.firstName}}',
'{{person.firstName}}{{location.city_suffix}}',
'{{person.lastName}}{{location.city_suffix}}',
];
7 changes: 7 additions & 0 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ export class InternetModule {
);
}

// local parts may not contain two or more consecutive . characters
localPart = localPart.replace(/\.{2,}/g, '.');

// local parts may not start with or end with a . character
localPart = localPart.replace(/^\./, '');
localPart = localPart.replace(/\.$/, '');

return `${localPart}@${provider}`;
}

Expand Down
24 changes: 24 additions & 0 deletions test/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ describe('internet', () => {
expect(faker.definitions.internet.free_email).toContain(suffix);
});

it('should not allow an email that starts or ends with a .', () => {
const email = faker.internet.email('...Aiden...', '...Doe...');

expect(email).toBeTruthy();
expect(email).toBeTypeOf('string');
expect(email).toSatisfy(validator.isEmail);

const [prefix] = email.split('@');
expect(prefix).not.toMatch(/^\./);
expect(prefix).not.toMatch(/\.$/);
});

it('should not allow an email with multiple dots', () => {
const email = faker.internet.email('Ai....den');

expect(email).toBeTruthy();
expect(email).toBeTypeOf('string');
expect(email).toSatisfy(validator.isEmail);

const [prefix] = email.split('@');
//expect it not to contain multiple .s
expect(prefix).not.toMatch(/\.{2,}/);
});

it('should return an email with given firstName and lastName', () => {
const email = faker.internet.email('Aiden', 'Harann');

Expand Down

0 comments on commit 1b4ea0a

Please sign in to comment.