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(phone)!: add new style parameter #2578

Merged
merged 20 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions docs/guide/upgrading_v9/2578.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### faker.phone.number `style` replaces explicit `format`

`faker.phone.number()` generates a phone number for the current locale. However, previously there was little control over the generated number, which might or might not include country codes, extensions, white space and punctuation.

If you wanted more control over the number, it was previously necessary to pass an explicit `format` parameter. This has now been removed. Instead, you can consider one of two options:

1. The new `style` parameter has convenient options for common use cases. There are three possible values.

- - `'human'`: (default, existing behavior) A human-input phone number, e.g. `555-770-7727` or `555.770.7727 x1234`
- - `'national'`: A phone number in a standardized national format, e.g. `(555) 123-4567`.
- - `'international'`: A phone number in a E.123 standard international format with country code, e.g. `+15551234567`

The styles are locale-aware, so for example if you use pt_PT, phone numbers suitable for Portugal would be generated.

2. If none of the `style`s match your needs, you can use `faker.string.numeric()` or `faker.helpers.fromRegExp()` to create a custom pattern.
15 changes: 14 additions & 1 deletion src/definitions/phone_number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,18 @@
*
* @see faker.helpers.replaceSymbolWithNumber(format): For more information about how the patterns are used.
*/
formats: string[];
format: {
/**
* Formats for a human-input phone number, e.g. `555-770-7727` or `555.770.7727 x1234`
*/
human: string[];
/**
* Formats for a phone number in a standardized national format, e.g. `(555) 123-4567`.
*/
national: string[];
/**
* Formats for a phone number in the standardised E.123 format, e.g. `+15551234567`
*/
international: string[];
};

Check warning on line 28 in src/definitions/phone_number.ts

View check run for this annotation

Codecov / codecov/patch

src/definitions/phone_number.ts#L15-L28

Added lines #L15 - L28 were not covered by tests
}>;
16 changes: 16 additions & 0 deletions src/locales/af_ZA/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
9 changes: 9 additions & 0 deletions src/locales/af_ZA/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'+271#########',
'+272#########',
'+273#########',
'+274#########',
'+275#########',
'+27800######',
'+27860######',
];
9 changes: 9 additions & 0 deletions src/locales/af_ZA/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'1#########',
'2#########',
'3#########',
'4#########',
'5#########',
'080 0## ####',
'0860 ### ###',
];
4 changes: 2 additions & 2 deletions src/locales/af_ZA/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
2 changes: 0 additions & 2 deletions src/locales/ar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import location from './location';
import lorem from './lorem';
import metadata from './metadata';
import person from './person';
import phone_number from './phone_number';
import team from './team';
import vehicle from './vehicle';

Expand All @@ -24,7 +23,6 @@ const ar: LocaleDefinition = {
lorem,
metadata,
person,
phone_number,
team,
vehicle,
};
Expand Down
18 changes: 0 additions & 18 deletions src/locales/ar/phone_number/formats.ts
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

12 changes: 0 additions & 12 deletions src/locales/ar/phone_number/index.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/locales/az/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
1 change: 1 addition & 0 deletions src/locales/az/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+9949#########'];
1 change: 1 addition & 0 deletions src/locales/az/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['9#########'];
4 changes: 2 additions & 2 deletions src/locales/az/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/cs_CZ/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
6 changes: 6 additions & 0 deletions src/locales/cs_CZ/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default [
'+420601######',
'+420737######',
'+420736######',
'+420#########',
];
1 change: 1 addition & 0 deletions src/locales/cs_CZ/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['601 ### ###', '737 ### ###', '736 ### ###', '### ### ###'];
4 changes: 2 additions & 2 deletions src/locales/cs_CZ/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/da/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
1 change: 1 addition & 0 deletions src/locales/da/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+45!#######'];
1 change: 1 addition & 0 deletions src/locales/da/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['!# ## ## ##'];
4 changes: 2 additions & 2 deletions src/locales/da/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/de/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
1 change: 1 addition & 0 deletions src/locales/de/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+49############', '+49###########', '+49##########'];
1 change: 1 addition & 0 deletions src/locales/de/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['0#### ########', '0#### #######', '0#### ######'];
4 changes: 2 additions & 2 deletions src/locales/de/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/de_AT/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
1 change: 1 addition & 0 deletions src/locales/de_AT/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['+431#######', '+43########', '+43#########'];
1 change: 1 addition & 0 deletions src/locales/de_AT/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['01 #######', '0#### ####', '0#### #####'];
4 changes: 2 additions & 2 deletions src/locales/de_AT/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/de_CH/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
8 changes: 8 additions & 0 deletions src/locales/de_CH/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
'+41800######',
'+41#########',
'+41900######',
'+4176#######',
'+4178#######',
'+4179#######',
];
8 changes: 8 additions & 0 deletions src/locales/de_CH/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
'0800 ### ###',
'0## ### ## ##',
'0900 ### ###',
'076 ### ## ##',
'078 ### ## ##',
'079 ### ## ##',
];
4 changes: 2 additions & 2 deletions src/locales/de_CH/phone_number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../..';
import formats from './formats';
import format from './format';

const phone_number: PhoneNumberDefinition = {
formats,
format,
};

export default phone_number;
16 changes: 16 additions & 0 deletions src/locales/dv/phone_number/format/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { PhoneNumberDefinition } from '../../../..';
import human from './human';
import international from './international';
import national from './national';

const format: PhoneNumberDefinition['format'] = {
human,
international,
national,
};

export default format;
9 changes: 9 additions & 0 deletions src/locales/dv/phone_number/format/international.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'+9603######',
'+9604######',
'+9605######',
'+9606######',
'+9607######',
'+9608######',
'+9609######',
];
9 changes: 9 additions & 0 deletions src/locales/dv/phone_number/format/national.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default [
'3##-####',
'4##-####',
'5######',
'6##-####',
'7##-####',
'8######',
'9##-####',
];
Loading